Definition: |
sequence s = atom_to_float32(atom a1)
-- or -- sequence s = atom_to_float64(atom a1) -- or -- sequence s = atom_to_float80(atom a1) |
Description: | Convert an atom to a sequence (in fact a raw binary string) of 4/8/10 single-byte values. These bytes contain the representation of an IEEE floating-point number in 32/64/80-bit format. |
Comments: |
There are three very similar routines, atom_to_float32, atom_to_float64, and atom_to_float80, which
deal with 32-bit/4-byte, 64-bit/8-byte, and 80-bit/10-byte conversions respectively. Note that while
the result is technically a string, it is not suitable for display; instead it is intended for poking
to memory or writing to a file.
On 32-bit all atoms are stored as 64-bit IEEE floating-point numbers, so you can convert any atom to 64-bit format without losing any precision. On 64-bit all atoms are stored as 80-bit IEEE floating-point numbers, so you can convert any atom to 80-bit format without losing any precision. Converting an atom to a smaller format can lose precision or result in one of the special values inf or -inf (infinity or -infinity). It is also possible that upscaling can introduce apparent discrepancies, for instance the value 0.1 cannot be held exactly, and hence a 64-bit version of 0.1 upscaled to 80-bits will not match a 0.1 value that has been 80-bits since inception. Neither is exact but the latter will contain a futher eleven bits of the infinitely recurring bit pattern that the former does not. Integer values will also be converted to floating-point format. |
Example: |
fn = open("numbers.dat", "wb") puts(fn, atom_to_float64(157.82)) -- write 8 bytes to a file |
See Also: | floatNN_to_atom |