BSD-3-Clause licensed by Andrew Martin
Maintained by [email protected]
This version can be pinned in stack with:scientific-notation-0.1.7.0@sha256:484cdd817d1ff23f01757659325c47609ef7b5e14464ba89883d3dde91c6f8f9,3796

Module documentation for 0.1.7.0

This library provides a type used to represent a number in scientific notation. This is most frequently useful when tokenizing or parsing a language. Languages like JSON and SQL support numberic literals written in scientific notation, even though backends frequently reject numbers outside a given range. This library provides a compact representation of numbers in scientific notation. In the common case of the coefficient and then exponent each being small enough to be represented by a machine word, this library avoids the need for any indirections to retrieve the number. Consider some tokenization scheme: `data Token = ... | Number {-# UNPACK #-} !Scientific`. In this case, the unboxed coefficient and exponent are unpacked into the Number data constructor if they can each be represented by a machine word.

The internal representation does not normalize numbers. That is, parsing `300e-2` resulting in a representation that uses `300` and `-2` rather than `3` and `0`. This work is deferred with the expectation that a number in scientific notation is consumed either zero or one times. This library is not optimized for use-cases that consume a Scientific more than once since normalization is reapplied every time.

The primary library that operates in this same space is scientific. Compared to scientific, this library distinguishes itself from scientific in the following ways:

  • Correctness: scientific does not correctly handle large exponents. See issue #62.

  • Parsing: The `scientific-notation` parser outperforms the scientific parser that ships with aeson by a factor of five on small numbers.

Changes

Revision history for scientific-notation

0.1.7.0 – 2024-02-12

  • Add toInteger.

0.1.6.1 – 2024-02-06

  • Update package metadata.

0.1.6.0 – 2023-06-27

  • Support GHC 9.4 and 9.6. Drop support for GHCs older than 9.4.
  • Add fromInt and fromInt(8|16|32|64).

0.1.5.0 – 2022-07-15

  • Support GHC 9.2.

0.1.4.0 – 2022-03-16

  • Add fromWord8, fromWord16, and fromWord32.
  • Add roundShiftedToInt64.
  • Add encode.
  • Change builderUtf8 to present numbers in decimal notation without exponent in many common cases. This is not considered a breaking change.

0.1.3.0 – 2021-02-23

  • Add greaterThanInt64.
  • Add fromWord64.
  • Suppress zero exponent when encoding.

0.1.2.0 – 2020-05-01

  • Add builderUtf8.

0.1.1.0 – 2019-11-06

  • Add withExposed.
  • Start building with -O2.

0.1.0.1 – 2019-09-30

  • Make compatible with bytesmith-0.3.

0.1.0.0 – 2019-09-24

  • First version.