Skip to content

horvathandris/bigdecimal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🅱️ bigdecimal

Package Version Hex Docs Erlang Target JavaScript Target

A library for arbitrary precision decimal arithmetic in Gleam.

This library builds on the great bigi library, which is used to represent the unscaled value of BigDecimals. A BigDecimal consists of an arbitrary precision integer unscaled value of type bigi.Bigint and an integer scale of built-in type Int (arbitrary precision on the Erlang target, bound between Number.MIN_SAFE_INTEGER and Number.MAX_SAFE_INTEGER on the JavaScript target). If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. The value of the number represented by the BigDecimal is therefore unscaledValue × 10-scale.

Usage

gleam add bigdecimal@1
import bigdecimal

pub fn main() {
  let assert Ok(number) = bigdecimal.from_string("12.00340")

  bigdecimal.scale(number) // 5

  bigdecimal.unscaled_value(number) // 1_200_340
}

Further documentation can be found at https://hexdocs.pm/bigdecimal.

Development

The library supports all targets and runtimes. To do a matrix run of the test suite, run:

./scripts/matrix-test.sh

TODO

Pre v1

  • absolute value
  • compare
  • add
  • subtract
  • multiply
  • product (list input)
  • sum (list input)
  • signum
  • ulp
  • divide
  • rescale/round (with rounding modes)
  • power
  • modulo

Post v1

  • clamp
  • square root
  • trim trailing zeros
  • truncate (to BigInt)

About

Arbitrary precision decimal arithmetic for Gleam

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published