scientific: Numbers represented using scientific notation

[ bsd3, data, library ] [ Propose Tags ] [ Report a vulnerability ]

Data.Scientific provides the number type Scientific. Scientific numbers are arbitrary precision and space efficient. They are represented using scientific notation. The implementation uses a coefficient c :: Integer and a base-10 exponent e :: Int. A scientific number corresponds to the Fractional number: fromInteger c * 10 ^^ e.

Note that since we're using an Int to represent the exponent these numbers aren't truly arbitrary precision. I intend to change the type of the exponent to Integer in a future release.

The main application of Scientific is to be used as the target of parsing arbitrary precision numbers coming from an untrusted source. The advantages over using Rational for this are that:

  • A Scientific is more efficient to construct. Rational numbers need to be constructed using % which has to compute the gcd of the numerator and denominator.

  • Scientific is safe against numbers with huge exponents. For example: 1e1000000000 :: Rational will fill up all space and crash your program. Scientific works as expected:

>>> read "1e1000000000" :: Scientific
1.0e1000000000
  • Also, the space usage of converting scientific numbers with huge exponents to Integrals (like: Int) or RealFloats (like: Double or Float) will always be bounded by the target type.

Flags

Automatic Flags
NameDescriptionDefault
integer-simple

Use the integer-simple package instead of integer-gmp

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.0.0, 0.0.0.1, 0.0.0.2, 0.1.0.0, 0.1.0.1, 0.2.0.0, 0.2.0.1, 0.2.0.2, 0.3.0.0, 0.3.0.1, 0.3.0.2, 0.3.1.0, 0.3.2.0, 0.3.2.1, 0.3.2.2, 0.3.3.0, 0.3.3.1, 0.3.3.2, 0.3.3.3, 0.3.3.4, 0.3.3.5, 0.3.3.6, 0.3.3.7, 0.3.3.8, 0.3.4.0, 0.3.4.1, 0.3.4.2, 0.3.4.3, 0.3.4.4, 0.3.4.5, 0.3.4.6, 0.3.4.7, 0.3.4.8, 0.3.4.9, 0.3.4.10, 0.3.4.11, 0.3.4.12, 0.3.4.13, 0.3.4.14, 0.3.4.15, 0.3.5.0, 0.3.5.1, 0.3.5.2, 0.3.5.3, 0.3.6.0, 0.3.6.1, 0.3.6.2, 0.3.7.0, 0.3.8.0
Change log changelog
Dependencies base (>=4.5 && <4.21), binary (>=0.8.6.0 && <0.9), bytestring (>=0.10.8.2 && <0.13), containers (>=0.6.0.1 && <0.8), deepseq (>=1.4.4.0 && <1.6), hashable (>=1.4.4.0 && <1.6), integer-gmp, integer-logarithms (>=1.0.3.1 && <1.1), integer-simple, invalid-cabal-flag-settings (<0), primitive (>=0.9.0.0 && <0.10), template-haskell (>=2.14.0.0 && <2.23), text (>=1.2.3.0 && <1.3 || >=2.0 && <2.2) [details]
Tested with ghc ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.5 || ==9.8.2 || ==9.10.1
License BSD-3-Clause
Author Bas van Dijk
Maintainer Bas van Dijk <v.dijk.bas@gmail.com>
Revised Revision 1 made by phadej at 2024-07-04T20:39:28Z
Category Data
Home page https://github.com/basvandijk/scientific
Bug tracker https://github.com/basvandijk/scientific/issues
Source repo head: git clone git://github.com/basvandijk/scientific.git
Uploaded by phadej at 2024-05-14T10:23:19Z
Distributions Arch:0.3.7.0, Debian:0.3.6.2, Fedora:0.3.7.0, FreeBSD:0.3.3.8, LTSHaskell:0.3.7.0, NixOS:0.3.7.0, Stackage:0.3.8.0, openSUSE:0.3.8.0
Reverse Dependencies 484 direct, 7416 indirect [details]
Downloads 407707 total (727 in the last 30 days)
Rating 2.25 (votes: 4) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-05-14 [all 1 reports]