Next: objects compnums, Previous: objects ratnums, Up: objects [Index]
Flonums are double–precision floating point numbers (8 bytes wide) implemented as specified by IEEE 754 on the hosting platform. A flonum is a fixed length memory block referenced by machine words tagged as vectors. The first machine word of a flonum block is tagged has flonum in its least significant bits and it has the most significant bits set to zero.
|------------------------|-------------| reference to flonum heap pointer vector tag |------------------------|-------------| flonum first word all set to zero flonum tag
To allow for the same binary layout: a flonum memory block is 16 bytes wide on both 32-bit and 64-bit platforms; on a 32-bit platform the actual number is stored in the last two words:
1st word 2nd word 3rd word 4th word |------------|------------|------------|------------| tagged word unused data words |.........................| flonum
on a 64-bit platform the actual number is stored in the second word:
1st word 2nd word |-------------------------|-------------------------| tagged word data word |.........................| flonum
Flonums are allocated on the heap as follows:
ikpcb_t * pcb = ik_the_pcb(); ikptr_t s_fl; s_fl = ik_safe_alloc(pcb, flonum_size) | vector_tag; IK_FLONUM_TAG(s_fl) = flonum_tag;
to extract the double number we do:
ikptr_t s_fl = the_flonum; double data = IK_FLONUM_DATA(s_fl);
to obtain a pointer to the data area we do:
ikptr_t s_fl = the_flonum; double * data = IK_FLONUM_VOIDP(s_fl);
The number of bytes to allocate to hold a flonum memory block.
The tag of ikptr_t
values used as first words in bignum memory blocks.
Displacement of secondary tag word. The number of bytes to add to an untagged pointer to flonum to get the pointer to the first byte in the word holding the flonum tag.
Displacement of data area. The number of bytes to add to an untagged
pointer to flonum to get the pointer to the first byte in the data area
holding the actual double
value.
An integer to add to add to a tagged ikptr_t
pointer to flonum to get
the pointer to the first byte in the word holding the flonum tag.
An integer to add to a tagged ikptr_t
pointer to flonum to get the
pointer to the first byte in the data area holding the actual
double
value.
Return true if obj is a flonum object; otherwise return false.
Evaluate to the location of the first word in a flonum block. fl must be a tagged pointer to flonum object. A use of this macro can appear both as operand or left–side of assignment.
Set or retrieve the floating point number; fl must be a tagged pointer to flonum object. A use of this macro can appear both as operand or left–side of assignment:
ikptr_t s_fl = the_flonum; double num; IK_FLONUM_DATA(s_fl) = 1.2; num = IK_FLONUM_DATA(s_fl);
Evaluate to a pointer to the data area of a flonum object. fl must be a tagged pointer to flonum object.
Return non–zero if obj is a flonum object; otherwise return zero.
Allocate and return a new flonum object, using ik_unsafe_alloc()
,
intialised with N.
Allocate and return a new flonum object, using ik_safe_alloc()
,
intialised with N.
Next: objects compnums, Previous: objects ratnums, Up: objects [Index]