Rational numbers in Erlang
$ rebar3 compile
$ rebar3 check
1> Third = rationals:new(1, 3).
{fraction,1,3}
2> Quarter = rationals:new(1, 4).
{fraction,1,4}
3> rationals:numerator(Quarter).
1
4> rationals:denominator(Quarter).
4
5> rationals:add(Quarter, Third).
{fraction,7,12}
6> rationals:multiply(Quarter, Third).
{fraction,1,12}
7> rationals:gcd(64, 72).
8
See more examples in test/rationals_SUITE.erl; see rationals.erl for implementation details.
Copyright © 2021, Erlang-Aided Enrichment Center
Copyright © 2014 Peter Morgan [email protected]