Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #236 Large quotient

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

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)

New implementation...