Want a function that determines a double or float given its 80-bit IEEE 754 SANE (big endian) representation

dan dan.hitt at gmail.com
Tue Aug 22 22:38:23 UTC 2023


Hi,

I'm parsing some files, each containing (among other things) 10 
bytes said to represent an IEEE 754 extended floating point 
number, in SANE (Standard Apple Numerical Environment) form, as 
SANE existed in the early 1990s (so, big endian).

Note that the number actually stored will probably be a positive 
even integer less than 100,000, so a better format would have 
been to store a two-byte ushort rather than a 10-byte float.  
However the spec chose to have an encoded float there.

I would like to have a function of the form

     public bool ubytes_to_double( ubytes[10] u, out double d ) { 
/* stuff */ }

which would set d to the value encoded provided that the value is 
a number and is sane, and otherwise just return false.

So my plan is just to do this: examine the first 2 bytes to check 
the sign and see how big the number is, and if it is reasonable, 
convert the remaining 8 bytes to a fractional part, perhaps 
ignoring the last 2 or 3 as not being significant.

But --- it seems like this kind of task may be something that d 
already does, maybe with some constructor of a double or 
something.

Thanks in advance for any suggestions.

dan


More information about the Digitalmars-d-learn mailing list