routine or constant name search

8.35 Scientific Notation Parsing

8.35.1 Parsing routines

The parsing functions require a sequence containing a correctly formed scientific notation representation of a number. The general pattern is an optional negative sign (-), a number, usually with a decimal point, followed by an upper case or lower case 'e', then optionally a plus (+) or a minus (-) sign, and an integer. There should be no spaces or other characters. The following are valid numbers:

1e0
3.1415e-2
-9.0E+3
This library evaluates scientific notation to the highest level of precision possible using Euphoria atoms. An atom in 32-bit euphoria can have up to 16 digits of precision (19 in 64-bit euphoria). A number represented by scientific notation could contain up to 17 (or 20) digits. The 17th (or 20th) supplied digit may have an effect upon the value of the atom due to rounding errors in the calculations.

This does not mean that if the 17th (or 20th) digit is 5 or higher, you should include it. The calculations are much more complicated, because a decimal fraction has to be converted to a binary fraction, and there is not really a one-to-one correspondence between the decimal digits and the bits in the resulting atom. The 18th or higher digit, however, will never have an effect on the resulting atom.

The biggest and smallest (magnitude) atoms possible are:

32-bit:
1.7976931348623157e+308
4.9406564584124654e-324

8.35.2 Floating Point Types

8.35.2.1 NATIVE

include std/scinot.e
public enum NATIVE

NATIVE Use whatever is the appropriate format based upon the version of euphoria being used (DOUBLE for 32-bit, EXTENDED for 64-bit)

8.35.2.2 DOUBLE

include std/scinot.e
public enum DOUBLE
DOUBLE:

Description IEEE 754 double (64-bit) floating point format. The native 32-bit euphoria floating point representation.

8.35.2.3 EXTENDED

include std/scinot.e
public enum EXTENDED

EXTENDED: 80-bit floating point format.The native 64-bit euphoria floating point reprepresentation.

8.35.2.4 bits_to_bytes

include std/scinot.e
public function bits_to_bytes(sequence bits)

Takes a sequence of bits (all elements either 0 or 1) and converts it into a sequence of bytes.

Parameters:
  1. bits : sequence of ones and zeroes

Returns a sequence of 8-bit integers

8.35.2.5 bytes_to_bits

include std/scinot.e
public function bytes_to_bits(sequence bytes)

Converts a sequence of bytes (all elements integers between 0 and 255) and converts it into a sequence of bits.

Parameters:
  1. bytes : sequence of values from 0-255
Returns:

Sequence of bits (ones and zeroes)

8.35.2.6 scientific_to_float

include std/scinot.e
public function scientific_to_float(sequence s, floating_point fp = NATIVE)

Takes a string reprepresentation of a number in scientific notation and the requested precision (DOUBLE or EXTENDED) and returns a sequence of bytes in the raw format of an IEEE 754 double or extended precision floating point number. This value can be passed to the euphoria library function, float64_to_atom or float80_to_atom, respectively.

Parameters:
  1. s : string representation of a number, e.g., "1.23E4"
  2. fp : the required precision for the ultimate representation
    1. DOUBLE Use IEEE 754, the euphoria representation used in 32-bit euphoria
    2. EXTENDED Use Extended Floating Point, the euphoria representation in 64-bit euphoria
Returns:

Sequence of bytes that represents the physical form of the converted floating point number.

Note:

Does not check if the string exceeds IEEE 754 double precision limits.

8.35.2.7 scientific_to_atom

include std/scinot.e
public function scientific_to_atom(sequence s, floating_point fp = NATIVE)

Takes a string reprepresentation of a number in scientific notation and returns an atom.

Parameters:
  1. s : string representation of a number (such as "1.23E4" ).
  2. fp : the required precision for the ultimate representation.
    1. DOUBLE Use IEEE 754, the euphoria representation used in 32-bit Euphoria.
    2. EXTENDED Use Extended Floating Point, the euphoria representation in 64-bit Euphoria.
Returns:

Euphoria atom floating point number.