# floatNN_to_atom

Definition: | atom a1 = float32_to_atom(sequence s) -- or -- atom a1 = float64_to_atom(sequence s) -- or -- atom a1 = float80_to_atom(sequence s)
Description: | Convert a sequence of 4/8/10 bytes to an atom. These bytes must contain an IEEE floating-point number in the right 32/64/80-bit format.
pwa/p2js: | Supported, apart from float80_to_atom() - while JavaScript has DataView.prototype.getFloat32 and DataView.prototype.getFloat64, there is no DataView.prototype.getFloat80, as yet, and no mention of it in the ECMAScript specs.
Comments: | There are three very similar routines, float32_to_atom, float64_to_atom, and float80_to_atom, which deal with 32-bit/4-byte, 64-bit/8-byte, and 80-bit/10-byte conversions respectively. Any 32, 64, or 80-bit IEEE floating-point number can be converted to an atom, however on 32-bit the conversion of an 80-bit float (implicitly to a 64-bit float) may unavoidably incur some loss of precision (less than one trillionth of one percent, mind you).
Example: |
    f = repeat(0, 8)
    fn = open("numbers.dat", "rb")  -- read binary
    for i=1 to 8 do
        f[i] = getc(fn)
    end for
    a = float64_to_atom(f)
Implementation: | See builtins\VM\pFloatN.e (an autoinclude), or pwa\p2js.js, for details of the actual implementation.
See Also: | atom_to_floatNN