Project

decimal

0.0
No commit activity in last 3 years
No release in over 3 years
Decimal is (yet another) multi-precision decimal arithmetic library. It provides simple, compact, fast, precise, stable and easy-to-use solution.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

 Project Readme

Decimal - multi-precision decimal arithmetic library¶ ↑

Decimal is (yet another) multi-precision decimal arithmetic library, which aims to surpass BigDecimal. It provides simple, compact, fast, precise, stable and easy-to-use solution.

Webpages¶ ↑

Requirements¶ ↑

Ruby 1.9.3 / 2.0.0 / 2.1.x / 2.2.x / 2.3.x

Install¶ ↑

With rubygems,

sudo gem install decimal

or to build by yourself,

ruby extconf.rb
make
sudo make install

Read INSTALL for less details.

Examples¶ ↑

Use like Float with few exceptions including Decimal#divide.

require 'decimal'

N = 3 # larger N may take huge time and more inaccurate result
pi = 0
i = 0

loop do
  term = (-1) ** i * Decimal(4).divide(2 * i + 1, N + 2, :down)
  break if term.zero?
  pi += term
  i += 1
end

puts pi.round(N)

License¶ ↑

Ruby’s. See COPYING and BSDL for more details.

Author¶ ↑

Tadashi Saito