Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/basvandijk/scientific
Arbitrary-precision floating-point numbers represented using scientific notation
https://github.com/basvandijk/scientific
haskell numbers scientific-notation
Last synced: 4 days ago
JSON representation
Arbitrary-precision floating-point numbers represented using scientific notation
- Host: GitHub
- URL: https://github.com/basvandijk/scientific
- Owner: basvandijk
- License: bsd-3-clause
- Created: 2013-10-22T22:52:19.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-12-20T18:32:36.000Z (about 1 month ago)
- Last Synced: 2025-01-15T05:52:55.529Z (8 days ago)
- Topics: haskell, numbers, scientific-notation
- Language: Haskell
- Size: 326 KB
- Stars: 74
- Watchers: 7
- Forks: 40
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: changelog
- License: LICENSE
Awesome Lists containing this project
README
[![Hackage](https://img.shields.io/hackage/v/scientific.svg)](https://hackage.haskell.org/package/scientific)
[![Build Status](https://travis-ci.org/basvandijk/scientific.svg)](https://travis-ci.org/basvandijk/scientific)`Data.Scientific` provides a space efficient and arbitrary precision
scientific number type.`Scientific` numbers are represented using
[scientific notation](http://en.wikipedia.org/wiki/Scientific_notation). It uses
a coefficient `c :: Integer` and a base-10 exponent `e :: Int` (do note that
since we're using an `Int` to represent the exponent these numbers aren't truly
arbitrary precision. I intend to change this to Integer in the future!). A
scientific number corresponds to the `Fractional` number:
`fromInteger c * 10 ^^ e`.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
Integral's (like: `Int`) or RealFloats (like: `Double` or `Float`) will always
be bounded by the target type.