Next: layout bitfid immediate booleans, Up: layout bitfid immediate [Contents][Index]
These small integer values are stored in the two’s complement representation, like the CPU uses. The lowest bit is always ‘1’, due to the fixnum tag bit. The highest bit is used to determine the sign of the number.
00000000 00000000 00000000 00000001 value= 0 C_fix(0) 00000000 00000000 00000000 00000011 value= 1 C_fix(+1) 00000000 00000000 00000000 00000101 value= 2 C_fix(+2) 11111111 11111111 11111111 11111111 value=-1 C_fix(-1) 11111111 11111111 11111111 11111101 value=-2 C_fix(-2)
The C_fix()
preprocessor macro shifts its argument one bit to the left, and sets the lower bit
through a bitwise OR with 1. To convert a Scheme fixnum back to a C integer: we can use the
C_unfix()
preprocessor macro, it shifts its argument one bit to the right. C_fix()
and
C_unfix()
are defined in the header file chicken.h.
We might wonder what happens when we calculate or enter a very large integer: in CHICKEN 4, it will be coerced to a flonum; in CHICKEN 5, it will be stored as a bignum. Bignums are block objects, not immediates, because they may be arbitrarily large.
Next: layout bitfid immediate booleans, Up: layout bitfid immediate [Contents][Index]