paulyoung / purescript-precise

A huge number library for Purescript with emphasis on correctness.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

purescript-precise

Latest release Build status

This is a library for working with numbers of arbitrarily finite size.

JavaScript (and to some extension PureScript) has quite a few drawbacks when it comes to large numbers. For example, PureScript's Int primitive is a member of the Bounded typeclass, with top == 2 ^ 31 - 1 and bottom == - (2 ^ 32).

The PureScript Number primitive is not Bounded in the same way; however, there are problems with manipulating large-enough Numbers:

> import Prelude
> let x = 900000000000000000.0
> :t x
Number

> x + 1.0 == x
true
> x + 1.0
900000000000000000

In this library, correctness is prioritized above all else:

> import Data.HugeNum
> let x = fromNumber 900000000000000000.0
> let y = fromNumber 1.0
> x + y == x
false

> x + y
HugeNum 900000000000000001.0

Addition is implemented using an elementary-school method. Multiplication follows Karatsuba.

Installation

bower install purescript-precise

Documentation

Module documentation is published on Pursuit.

About

A huge number library for Purescript with emphasis on correctness.

License:MIT License


Languages

Language:PureScript 100.0%