|<< 7 Included Tools||< 8.34 Stack||Up: 8 API Reference||8.36 Core Sockets >||9 Release Notes >>|
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+3This 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
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)
include std/scinot.e public enum DOUBLE
Description IEEE 754 double (64-bit) floating point format. The native 32-bit euphoria floating point representation.
include std/scinot.e public enum EXTENDED
EXTENDED: 80-bit floating point format.The native 64-bit euphoria floating point reprepresentation.
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.
- bits : sequence of ones and zeroes
Returns a sequence of 8-bit integers
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.
- bytes : sequence of values from 0-255
Sequence of bits (ones and zeroes)
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.
- s : string representation of a number, e.g., "1.23E4"
- fp : the required precision for the ultimate representation
- DOUBLE Use IEEE 754, the euphoria representation used in 32-bit euphoria
- EXTENDED Use Extended Floating Point, the euphoria representation in 64-bit euphoria
Sequence of bytes that represents the physical form of the converted floating point number.
Does not check if the string exceeds IEEE 754 double precision limits.
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.
- s : string representation of a number (such as "1.23E4" ).
- fp : the required precision for the ultimate representation.
- DOUBLE Use IEEE 754, the euphoria representation used in 32-bit Euphoria.
- EXTENDED Use Extended Floating Point, the euphoria representation in 64-bit Euphoria.
Euphoria atom floating point number.