On Jan 28, 2013, at 2:53 PM, Hugo Arregui wrote:

> 3) To read/write float/double numbers (in ieee754) i'm using
> endian-blob egg (here[4]), it's there any alternative without
> implementing the full float/double->binary logic (which seems quite
> complicated)?

Maybe I'm overlooking something, but my understanding is that all modern
machines use IEEE 754 format internally, and although endianness is
unspecified, it can be assumed it's the same as for integers except for
all but the weirdest of platforms.  Virtually all the complex logic
in endian-blob / GDB for floating point conversion is for 
extended floating point values or platforms like VAX and old
ARM processors, and could probably just be discarded.

So if you want IEEE 754 format output, can you not just cast
the floating point memory to uint8_t* (e.g. (uint8_t*)&f )
and then write out the bytes in big-endian order?

And if you don't know your system's endianness and so can't easily
use something like bswap, you should just be able to cast to a
sufficiently wide integer value and write out a byte at a time
in sequence; e.g.

 /* untested */
 double d=35.4;
 write_byte( ((*(uint64_t *)&d) >> 56) & 0xff );
 write_byte( ((*(uint64_t *)&d) >> 48) & 0xff );
 write_byte( ((*(uint64_t *)&d) >> 40) & 0xff );
 ...

The bit-twiddling of the latter example can't easily be accomplished
directly in Chicken due to lossage on integers larger than 53 bits,
but you could do byte swapping in C and byte writing from Chicken.

Jim

_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to