A CLJS bigfraction is a coprime pair of JavaScript BigInts, with the sign carried in the numerator.
A CLJS bigfraction is a coprime pair of JavaScript BigInts, with the sign carried in the numerator.
(->normal-form a b)
We assume we are given two BigInts, with b > 0. The GCD is divided out, and the sign is carried in the numerator.
We assume we are given two BigInts, with b > 0. The GCD is divided out, and the sign is carried in the numerator.
(->real q)
Coerce a fraction to real by performing the division in the floating point domain
Coerce a fraction to real by performing the division in the floating point domain
(abs x)
Absolute value of the fraction x
.
Absolute value of the fraction `x`.
(bigint-gcd a b)
GCD assuming a and b are BigInts > 0
GCD assuming a and b are BigInts > 0
(cmp x y)
Compares the fractions x
and y
, returning -1, 0, or 1.
Compares the fractions `x` and `y`, returning -1, 0, or 1.
(div x y)
Returns the quotient of x
and y
.
Returns the quotient of `x` and `y`.
(division-by-zero)
Throws JS exception used to signal an attempt to construct a fraction with zero denominator.
Throws JS exception used to signal an attempt to construct a fraction with zero denominator.
(integer-> n)
Create a fraction with unit denominator.
Create a fraction with unit denominator.
(integer-power x n)
Raises the fraction x
to the integer power n
.
Raises the fraction `x` to the integer power `n`.
(invert x)
Returns the reciprocal of x
, but throws if $x=0$.
Returns the reciprocal of `x`, but throws if $x=0$.
(make a b)
Produces a fraction in canonical form. Note that the canonical form of an integer is
an integer, so if (one? b)
you just get a.
Produces a fraction in canonical form. Note that the canonical form of an integer is an integer, so if `(one? b)` you just get a.
(mul x y)
Returns the product of x
and y
.
Returns the product of `x` and `y`.
(one? x)
Returns true iff x
is a unit fraction.
Returns true iff `x` is a unit fraction.
(promote x)
If the fraction has a unit denominator, return the numerator, else the fraction.
If the fraction has a unit denominator, return the numerator, else the fraction.
(quotient x y)
Fractions form a field, so somewhat dubiously the function returns the largest integer N for which $Ny\le x$.
Fractions form a field, so somewhat dubiously the function returns the largest integer N for which $Ny\le x$.
(real-> x)
Clojure converts the real to BigDecimal and rationalizes from that. The JVM documentation explains that the BigDecimal value will correspond to what would be printed for the double value. We attempt to do the same thing here by converting to a string and converting from there.
Clojure converts the real to BigDecimal and rationalizes from that. The JVM documentation explains that the BigDecimal value will correspond to what would be printed for the double value. We attempt to do the same thing here by converting to a string and converting from there.
(remainder x y)
If $q$ is (quotient x y)
, returns $x-qy$.
If $q$ is `(quotient x y)`, returns $x-qy$.
(sub x y)
Returns the difference of x
and y
.
Returns the difference of `x` and `y`.
(zero? x)
Returns true iff x
is a zero fraction.
Returns true iff `x` is a zero fraction.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close