Table of Contents

scientific.e was written by Matt Lewis (matthewwalkerlewis@gmail.com)

It's purpose is to parse numbers in scientific notation to the maximum precision allowed by the IEEE 754 floating point standard.

LICENSE AND DISCLAIMER

The MIT License

Copyright (c) 2007 Matt Lewis

 Permission is hereby granted, free of charge, to any person obtaining a copy of this
 software and associated documentation files (the "Software"), to deal in the Software
 without restriction, including without limitation the rights to use, copy, modify, merge,
 publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 
 to whom the Software is furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all copies or
 substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.


Table of Contents

Topic

Description

IndexAlphabetical list of all items.
Low levelHelper routines
Scientific NotationParsing routines

Table of Contents

Helper routines


  • func bits_to_bytes( sequence bits )   
  • func bytes_to_bits( sequence bytes )   

    Table of Contents

    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 can have up to 16 digits of precision. A number represented by scientific notation could contain up to 17 digits. The 17th supplied digit may have an effect upon the value of the atom due to rounding errors in the calculations.

    This doesn't mean that if the 17th 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's 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:

        1.7976931348623157e+308
        4.9406564584124654e-324
    

  • func scientific_to_atom( sequence s )   
  • func scientific_to_float64( sequence s )   
  • Table of Contents

    [func]
    bits_to_bytes
    ( sequence bits )

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

    See Also: bytes_to_bits


    Table of Contents

    [func]
    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.

    See Also: bits_to_bytes


    Table of Contents

    []
    Miscellaneous Notes


    Table of Contents

    [func]
    scientific_to_atom
    ( sequence s )

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

    See Also: scientific_to_float64


    Table of Contents

    [func]
    scientific_to_float64
    ( sequence s )

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

    See Also: scientific_to_atom


    Index

    bits_to_bytes [func]
    bytes_to_bits [func]
    Low level
    Miscellaneous Notes []
    Scientific Notation
    scientific_to_atom [func]
    scientific_to_float64 [func]