Logo

Programming-Idioms

Initialize a quotient q = a/b of arbitrary precision. a and b are large integers.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "math/big"
q := new(big.Rat)
q.SetString(str)
import "math/big"
q := new(big.Rat)
q.SetFrac(a, b)
import "math/big"
q := big.NewRat(a, b)
use v5.10;
use Math::BigRat;
my $a = Math::BigRat->new(  '1_000_000_000_000_000_000' );
my $b = Math::BigRat->new( '10_000_000_000_000_000_000' );
my $q = $a / $b;

say $q;  # prints 1/10
import fractions
q = fractions.Fraction(a, b)
q = Rational(a, b)