## range-check.pkg
#
# Check that a given int/unt value will # XXX SUCKO FIXME This module belongs in xclient, not stdlib.
# fit in a 8 or 16 bits.
# Compiled by:
#
src/lib/std/standard.libpackage range_check: (weak)
api {
valid8: Int -> Bool;
valid_word8: Unt -> Bool;
valid_signed8: Int -> Bool;
valid16: Int -> Bool;
valid_word16: Unt -> Bool;
valid_signed16: Int -> Bool;
}
{
not8 = unt::bitwise_not 0uxFF;
not16 = unt::bitwise_not 0uxFFFF;
fun bitwise_and (i, mask)
=
unt::bitwise_and (unt::from_int i, mask);
fun valid_word8 w
=
unt::bitwise_and (w, not8) == 0u0;
fun valid8 i
=
valid_word8 (unt::from_int i);
fun valid_signed8 i
=
(i < 128) and (i >= -128);
fun valid_word16 w
=
unt::bitwise_and (w, not16) == 0u0;
fun valid16 i
=
valid_word16 (unt::from_int i);
fun valid_signed16 i
=
(i < 32768) and (i >= -32768);
}; # Range_Check
## COPYRIGHT (c) 1992 by AT&T Bell Laboratories. See SMLNJ-COPYRIGHT file for details.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.