updating oE atom_to_float32


include convert.e 
namespace convert 
public function atom_to_float32(atom a) 

converts an atom to a sequence of 4 bytes in IEEE 32-bit format.

  1. a : the atom to convert:

A sequence, of 4 bytes, which can be poked in memory to represent a.


Euphoria atoms can have values which are 64-bit IEEE floating-point numbers, so you may lose precision when you convert to 32-bits (16 significant digits versus 7). The range of exponents is much larger in 64-bit format (10 to the 308, versus 10 to the 38), so some atoms may be too large or too small to represent in 32-bit format. In this case you will get one of the special 32-bit values: inf or -inf (infinity or -infinity). To avoid this, you can use atom_to_float64.

Integer values will also be converted to 32-bit floating-point format.

On modern computers, computations on 64 bit floats are no slower than on 32 bit floats. Internally, the PC stores them in 80 bit registers anyway. Euphoria does not support these so called long doubles. Not all C compilers do.

Example 1:
fn = open("numbers.dat", "wb") 
puts(fn, atom_to_float32(157.82)) -- write 4 bytes to a file 
See Also:

float32_to_atom, int_to_bytes, atom_to_float64

Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu