RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Raya docs · Exact and higher mathematics

Arbitrary precision

Exact rationals, binary floating point of any precision with correctly rounded operations, interval and ball arithmetic, and elementary and special functions to any precision.

import 'package:riptide_precision/riptide_precision.ray';
15 classes387 functions and methods160 of 425 documented335 runnable examplesWhat MPFR and mpmath do

Overview

Exact and arbitrary-precision arithmetic. The analysis, CAS and algebra packages (riptide_analysis, riptide_cas, riptide_algebra) build on it.

TypeWhat
RationalExact rationals over BigInt, lowest terms; parse "-3/4", "6.02e23"; floor/ceil/round; correctly rounded toDouble (subnormals, overflow); LaTeX
BigFloatman · 2^exp with a per-value precision in bits (an MPFR variable); add, sub, mul, div, sqrt and fma rounded once in any RoundingMode (nearest-even, toward zero, up, down, away); signed zeros, \pm\infty, NaN; unbounded exponent; exact toRational, correctly rounded toDouble, decimal output and parsing
Interval[lo, hi] over BigFloat with outward rounding (IEEE 1788 set semantics, simplified): + - \times \div \mathrm{sqrt}, integer powers, abs, hull/intersect/bisect, certainly/possibly comparisons, empty and entire sets; functions restricted to their domain
DoubleIntervalFast [lo, hi] on doubles: each IEEE operation widened one ulp with nextUp/nextDown; a Raya value class (@pragma('raya:value'))
BallArb-style midpoint-radius ball: BigFloat midpoint, 30-bit upper-bound radius; rounding errors go into the radius, exact balls stay exact; containment/overlap tests, relative accuracy in bits
Elementary functionsCorrectly rounded in every mode at any precision (MPFR semantics, Ziv's strategy over rigorous ball kernels): exponential (e^{x}; BigFloat.exp is the exponent field), expm1, log, log1p, pow, sin, cos, tan, atan, atan2, asin, acos, sinh, cosh, tanh, asinh, acosh, atanh; IEEE special values; exact results detected (pow decides exactness completely); tiny arguments rounded without huge working precision (MPFR's round-near-x)
Constants\pi (Chudnovsky, binary splitting), e, \ln 2 (Machin-like atanh), Euler \gamma (Brent–McMillan), Catalan G (Ramanujan), correctly rounded; also as balls
Ball / Interval / DoubleInterval functionsThe same functions over Ball (Arb semantics: indeterminate outside the domain), Interval (tight: endpoints through the directed correctly rounded functions; sin/cos extrema and tan poles detected rigorously; domain clipping) and DoubleInterval; power and atan2 too
BigComplexArbitrary-precision complex numbers: + − × correctly rounded per part, ÷, abs/arg (correctly rounded), exp, log (no cancellation near \|z\| = 1), principal sqrt, pow/powInt, sin/cos/tan/sinh/cosh/tanh/atan
SpecialSpecial functions, real and complex arguments: gamma, rgamma, loggamma (principal branch), digamma, polygamma, beta, bernoulli (exact); zeta, hurwitzZeta, polylog; erf, erfc, gammaincLower/Upper; hyp0f1, hyp1f1, hyp2f1 (all of \mathbb{C} except a neighbourhood of e^{\pm i\pi/3} on \|z\| ≈ 1), hyper (pFq); besselJ/Y/I/K (any real or complex order), airyAi/Bi; ellipK/ellipE/ellipPi and incomplete ellipF/ellipEIncomplete/ellipPiIncomplete, Carlson RF/RC/RD/RJ, agm; jtheta (\theta1–\theta4), ellipNome, ellipfun (sn, cn, dn); lambertW (any branch); legendreP, legendrePAssoc (Ferrers), sphericalHarmonic. Real shortcuts on BigFloat (gamma, lgamma, digamma, erf, erfc, zeta, lambertW)
Fast BigInt arithmeticfastMultiply/fastSquare (Karatsuba from 7000 bits, Toom-3 from 24 000, a two-prime NTT kept for \ge 2^{25} bits), fastDivide/fastDivMod (Newton reciprocal from 300 000 bits), fastIsqrt (Newton from a recursive half-size root, from 12 000 bits); used by BigFloat mul/div/sqrt/fma, Ball, and the elementary kernels
roundBitsThe single rounding routine (precision and fixed-exponent limits, sticky tail) every operation uses

Operators (a + b) round to nearest at the larger operand precision; the named methods take prec and rnd.

Correctness

raya test. 1500 random add/sub/mul/div/sqrt cases (precisions 2–1000 bits, all five rounding modes, catastrophic cancellation, exponents \pm300) agree bit for bit with mpmath 1.3.0; decimal output agrees with Python's exact decimal module and decimal parsing with mpmath's from_str; a property test checks every product in every mode against the exact rational value and its neighbours.

Validated numerics: property tests draw random exact rational points in random operand intervals and balls (precisions 2–300 bits, magnitudes 2\wedge \pm 40, degenerate and zero-containing operands) and check that the exact rational result of

  • {-}\ \times\ \div, integer powers, abs and sqrt lies in the computed result (1500 interval cases, 1500 ball cases, 5000 DoubleInterval cases).

Elementary functions: 876 cases over all 18 functions and 175 constant cases agree bit for bit with mpmath 1.3.0 evaluated with 500 extra bits and rounded once (cases whose rounding mpmath can't settle with a 2^{-450} margin are dropped), in all five rounding modes, at 2, 24, 53, 113, 300 and 1000 bits (constants to 3000 bits). Inputs include tiny arguments, arguments near multiples of \frac{\pi}{2}, near \pm1 and near 1, and integer and dyadic pow exponents. The Interval and Ball versions are property-tested: random points in random intervals/balls map into the result (bracketed by the 300-bit correctly rounded values), for every function plus power and atan2.

Timing on the dev Mac (VM, JIT): a 53-bit exponential ≈ 45 µs, a 1000-bit \exp + \sin + \log + \operatorname{atan} \approx 4 ms, \pi to 100 000 bits ≈ 90 ms. Ball kernels track errors explicitly in fixed point; each kernel documents its bound.

Special functions: 2257 cases over all families (35 function kinds; real and complex arguments; precisions 53, 113, 300 and 1000 bits; hard regions included: degenerate and near-degenerate 2F1 parameters, the 1F1, Bessel, erfc and Airy asymptotic regimes, zeta on the critical line to t = 200, K(m) near 1, Lambert W at the branch point, upper incomplete gamma at s = 0, -1, -2, negative real gamma and digamma) agree with mpmath (evaluated with 80 extra bits) to within 1 ulp of the larger part — the observed maximum is 0.50 ulp for every family, i.e. the results are faithfully rounded on this sample (they are not guaranteed correctly rounded). Identities (\Gamma recurrence and reflection, \psi recurrence, \zeta(2), erf + erfc, W e^{W}, the Bessel Wronskian) hold to the last bits at 200 bits.

Fast multiplication (raya run benchmark/multiply_benchmark.ray, best of 5, Raya VM JIT, shared and loaded dev Mac), equal-size operands:

bitsbuilt-in *fastMultiplyspeedup
4 0002.9 µs3.1 µs0.96× (built-in used)
8 00014.8 µs11.6 µs1.3×
32 000188 µs108 µs1.75×
100 0002.2 ms0.87 ms2.55×
300 00015.8 ms4.1 ms3.9×
1 000 000160 ms22.9 ms7.0×
4 000 0002.38 s0.19 s12.7×

Raya's built-in multiply is an intrinsified schoolbook loop, so the Karatsuba crossover is high (~8000 bits) and Toom-3 pays from ~24 000. Our NTT (two 30-bit primes, 16-bit limbs) never beat Toom-3 up to 4 M bits (0.66 s vs 0.19 s at 4 M), so it is only enabled from 2^{25} bits. Built-in division is much faster than built-in multiply at equal sizes; Newton division pays from ~300 000 bits (1.9× at 300 k, 2.7× at 1 M). fastIsqrt (Newton from a recursive estimate) beats Newton-from-a-power-of-two by 3.7× at 20 000 bits and 6.4× at 100 000. Correctness: random sizes (to 400 000 bits, signs, carry/borrow runs, unbalanced operands) agree with the built-ins exactly.

Riptide: not used here. Arbitrary-precision kernels are sequential carry chains on variable-length integers; the GPU would only pay for huge batched multiplications (NTT), which the fast-multiplication work may revisit.

Functions and constants

Functions

nextUpfunction
double nextUp(double x)

The least double greater than x (nextUp(maxFinite) = ∞, nextUp(−∞) = −maxFinite, NaN stays NaN).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('nextUp(1.0) = ${nextUp(1.0)}, gap ${nextUp(1.0) - 1.0}');
  print('nextUp(0.0) = ${nextUp(0.0)} (the smallest subnormal)');
}
Output
nextUp(1.0) = 1.0000000000000002, gap 2.220446049250313e-16
nextUp(0.0) = 5e-324 (the smallest subnormal)
nextDownfunction
double nextDown(double x)

The greatest double less than x.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('nextDown(1.0) = ${nextDown(1.0)}');
}
Output
nextDown(1.0) = 0.9999999999999999
fastMultiplyfunction
BigInt fastMultiply(BigInt a, BigInt b)

a · b, subquadratic for large operands (same result as a * b).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final a = BigInt.from(3).pow(5000), b = BigInt.from(7).pow(4000);
  print('same as a*b: ${fastMultiply(a, b) == a * b}, ${fastMultiply(a, b).bitLength} bits');
}
Output
same as a*b: true, 19155 bits
fastSquarefunction
BigInt fastSquare(BigInt a)

a².

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final a = BigInt.from(10).pow(3000) + BigInt.one;
  print('${fastSquare(a) == a * a}');
}
Output
true
fastDividefunction
BigInt fastDivide(BigInt a, BigInt b)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final a = BigInt.from(3).pow(9000), b = BigInt.from(7).pow(2000);
  print('${fastDivide(a, b) == a ~/ b}');
}
Output
true
fastDivModfunction
(BigInt, BigInt) fastDivMod(BigInt a, BigInt b)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final (q, r) = fastDivMod(BigInt.from(10).pow(500), BigInt.from(997));
  print('remainder $r, q·997 + r == 10^500: ${q * BigInt.from(997) + r == BigInt.from(10).pow(500)}');
}
Output
remainder 100, q·997 + r == 10^500: true
fastIsqrtfunction
BigInt fastIsqrt(BigInt n)

Floor of the square root of a nonnegative BigInt (Newton from a recursive approximation for huge n).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final n = BigInt.from(2) * BigInt.from(10).pow(100);
  print('⌊√(2·10^100)⌋ = ${fastIsqrt(n)}');
}
Output
⌊√(2·10^100)⌋ = 141421356237309504880168872420969807856967187537694
quotientBitsfunction
(BigInt, int, bool) quotientBits(BigInt n, BigInt d, int bits)

n / d (d > 0, n \ne 0) as q · 2^e with q holding at least bits significant bits, and whether the division left a remainder (the sticky flag for roundBits).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // 1/3 to 10 bits: the quotient bits, the exponent and whether the division was inexact.
  print('${quotientBits(BigInt.one, BigInt.from(3), 10)}');
}
Output
(1365, -12, true)
(BigInt, int) decomposeDouble(double x)

Splits a finite double into (m, e) with x == m · 2^e exactly (m odd or zero).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // A double is m·2^e exactly.
  final (m, e) = decomposeDouble(0.1);
  print('0.1 = $m · 2^$e');
}
Output
0.1 = 3602879701896397 · 2^-55
double doubleFromBits(BigInt m, int e, RoundingMode rnd, {bool sticky = false})

The double for m · 2^e (plus a sticky tail), rounded once with IEEE binary64 rules.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${doubleFromBits(BigInt.from(3), -1, RoundingMode.nearestEven)}, ${doubleFromBits(BigInt.one, -1074, RoundingMode.nearestEven)}');
}
Output
1.5, 5e-324
int trailingZeros(BigInt m)

Number of trailing zero bits of a nonzero BigInt.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('trailingZeros(96) = ${trailingZeros(BigInt.from(96))}');
}
Output
trailingZeros(96) = 5
roundBitsfunction
(BigInt, int, bool) roundBits(BigInt m, int e, int prec, RoundingMode rnd, {int? minExp, bool sticky = false})

Rounds the exact value m · 2^e (plus a tail of the same sign as m when sticky is set: the true value lies strictly between m · 2^e and (m + sign m) · 2^e) to at most prec significant bits and, when minExp is given, to a multiple of 2^minExp (fixed-point floor, as for subnormals). Returns the rounded (m, e) with m odd or zero, and whether the result is exact.

Callers that pass sticky must supply m with at least prec + 2 bits (or two bits below minExp), so the tail can't cross a rounding boundary; roundBits appends the sticky bit below them.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // 0b1011 (11) rounded to 3 bits: up to 12 = 0b110·2.
  print('${roundBits(BigInt.from(11), 0, 3, RoundingMode.nearestEven)}');
}
Output
(3, 2, false)
isqrtfunction
BigInt isqrt(BigInt n)

Floor of the square root of a nonnegative BigInt (Newton's method from a power-of-two start above the root).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('⌊√10^40⌋ = ${isqrt(BigInt.from(10).pow(40))}, ⌊√99⌋ = ${isqrt(BigInt.from(99))}');
}
Output
⌊√10^40⌋ = 100000000000000000000, ⌊√99⌋ = 9

Classes

class

Ball

final class Ball

The set [mid − rad, mid + rad] of real numbers. Every operation returns a ball that contains the exact result for every choice of points in the operands (the inclusion property): the midpoint is rounded to the working precision and the rounding error is added to the radius, which is kept as a 30-bit upper bound.

The midpoint is always finite; a ball with an infinite radius is the whole real line (an indeterminate result, Arb's [0 +/- inf]). Operators use the larger midpoint precision; the named methods take prec.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Ball arithmetic: a midpoint and a radius that bounds the error.
  final b = Ball.fromInt(2).sqrt();
  print('√2 as a ball: $b');
  print('contains 1.41421356 (an 8-digit approximation, outside the ball): ${b.contains(Rational.fromInt(141421356, 100000000))}');
}
Output
√2 as a ball: [1.414213562373095 +/- 2.3e-16]
contains 1.41421356 (an 8-digit approximation, outside the ball): false

Constructors

Ballfactory
factory Ball(BigFloat mid, [BigFloat? rad])

[mid ± rad] (rad defaults to 0: an exact ball). A non-finite midpoint gives the whole line.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // A midpoint and a radius.
  final b = Ball(BigFloat.parse('3.14159'), BigFloat.parse('0.00001'));
  print('$b contains π: ${b.overlaps(Constants.piBallAt(60))}');
}
Output
[3.14159 +/- 0.000011] contains π: true
factory Ball.fromInt(Object n, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromInt(7)}, ${Ball.fromInt(BigInt.from(10).pow(30), prec: 20)}');
}
Output
7.0000000000000000, [1.00000e+30 +/- 1.3e+24]
factory Ball.fromDouble(double x, {int prec = 53})

The exact value of a finite double (an exact ball when prec ≥ 53).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromDouble(0.1)} (exact: the double nearest 0.1)');
}
Output
0.10000000000000001 (exact: the double nearest 0.1)
factory Ball.fromRational(Rational q, {int prec = 53})

A ball containing q (exact when q is a dyadic rational with at most prec bits).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('1/3 at 60 bits: ${Ball.fromRational(Rational.fromInt(1, 3), prec: 60)}');
}
Output
1/3 at 60 bits: [0.333333333333333333 +/- 4.4e-19]
Ball.parsefactory
factory Ball.parse(String s, {int prec = 53})

A ball containing the decimal s ("0.1", "1/3", "-2.5e-10").

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.parse('0.1', prec: 80)} (encloses the decimal 1/10, not the double)');
}
Output
[0.100000000000000000000000 +/- 1.1e-25] (encloses the decimal 1/10, not the double)
factory Ball.indeterminate({int prec = 53})

The whole real line.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.indeterminate()} (every value)');
}
Output
[+/- inf] (every value)
factory Ball.fromEndpoints(BigFloat lo, BigFloat hi, {int? prec})

The smallest ball (at prec) containing [lo, hi].

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromEndpoints(BigFloat.parse('1.4'), BigFloat.parse('1.5'))}');
}
Output
[1.4 +/- 0.051]

Properties

midfield
final BigFloat mid

The midpoint (finite).

radfield
final BigFloat rad

The radius: a nonnegative 30-bit upper bound, or +\infty.

precisiongetter
int get precision
isExactgetter
bool get isExact
isFinitegetter
bool get isFinite
isZerogetter
bool get isZero
bool get isPositive

True when every point of the ball is > 0 / < 0 / \ne 0.

bool get isNegative
isNonZerogetter
bool get isNonZero
bool get containsZero
BigFloat get magnitudeUpper

An upper bound of |x| over the ball.

BigFloat get magnitudeLower

A lower bound of |x| over the ball (0 when it contains zero).

int get relativeAccuracyBits

Relative accuracy in bits, like Arb's arb_rel_accuracy_bits (a large number for exact balls).

Methods

lowermethod
BigFloat lower({int? prec})

A lower bound of every point (rounded down at prec, default the midpoint precision).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final b = Ball.fromInt(2, prec: 60).sqrt();
  print('√2 ≥ ${b.lower().toStringAsPrecision(18)}');
}
Output
√2 ≥ 1.41421356237309505
uppermethod
BigFloat upper({int? prec})

An upper bound of every point (rounded up at prec).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final b = Ball.fromInt(2, prec: 60).sqrt();
  print('√2 ≤ ${b.upper().toStringAsPrecision(18)}');
}
Output
√2 ≤ 1.41421356237309505
containsmethod
bool contains(Rational q)

Whether the exact rational q lies in the ball.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final b = Ball.fromRational(Rational.fromInt(1, 3), prec: 40);
  print('${b.contains(Rational.fromInt(1, 3))}, ${b.contains(Rational.fromInt(333, 1000))}');
}
Output
true, false
bool containsBall(Ball o)

Whether every point of o lies in this ball.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromEndpoints(BigFloat.fromInt(0), BigFloat.fromInt(2)).containsBall(Ball.fromInt(1))}');
}
Output
true
overlapsmethod
bool overlaps(Ball o)

Whether the two balls share a point.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromInt(2).sqrt().overlaps(Ball.parse('1.41421356237309504880', prec: 80))}');
}
Output
true
addmethod
Ball add(Ball o, {int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.parse('0.1', prec: 80).add(Ball.parse('0.2', prec: 80))} contains 3/10: ${Ball.parse('0.1', prec: 80).add(Ball.parse('0.2', prec: 80)).contains(Rational.fromInt(3, 10))}');
}
Output
[0.300000000000000000000000 +/- 7.3e-25] contains 3/10: true
submethod
Ball sub(Ball o, {int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.parse('0.3', prec: 80).sub(Ball.parse('0.1', prec: 80))}');
}
Output
[0.200000000000000000000000 +/- 7.3e-25]
mulmethod
Ball mul(Ball o, {int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromInt(3).sqrt().mul(Ball.fromInt(3).sqrt())} ∋ 3: ${Ball.fromInt(3).sqrt().mul(Ball.fromInt(3).sqrt()).contains(Rational.fromInt(3))}');
}
Output
[3.000000000000000 +/- 1.3e-15] ∋ 3: true
divmethod
Ball div(Ball o, {int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromInt(1, prec: 100).div(Ball.fromInt(7, prec: 100))}');
}
Output
[0.142857142857142857142857142857 +/- 2.0e-31]
sqrtmethod
Ball sqrt({int? prec})

Square root of the nonnegative part (the whole line when the ball is entirely negative or indeterminate).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('√2 at 200 bits: ${Ball.fromInt(2, prec: 200).sqrt()}');
}
Output
√2 at 200 bits: [1.41421356237309504880168872420969807856967187537694807317668 +/- 1.3e-60]
squaremethod
Ball square({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final x = Ball.fromEndpoints(BigFloat.fromInt(-1), BigFloat.fromInt(2));
  print('$x² = ${x.square()} (never negative)');
}
Output
[0.500 +/- 1.5]² = [0.250 +/- 3.8] (never negative)
powmethod
Ball pow(int n, {int? prec})

this^n for an integer n (n < 0 inverts) by binary powering.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('(1 + 10⁻²⁰)^1000 ∈ ${Ball.parse('1.00000000000000000001', prec: 120).pow(1000)}');
}
Output
(1 + 10⁻²⁰)^1000 ∈ [1.000000000000000010000000000000000 +/- 1.6e-33]
inversemethod
Ball inverse({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromInt(3, prec: 80).inverse()}');
}
Output
[0.333333333333333333333333 +/- 4.2e-25]
roundTomethod
Ball roundTo(int prec)

The same set with the midpoint rounded to prec bits (the radius grows by the rounding error).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Constants.piBallAt(200).roundTo(30)}');
}
Output
[3.14159266 +/- 3.8e-9]
ldexpmethod
Ball ldexp(int k)

this · 2^k, exact.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromInt(3).ldexp(-4)} = 3/16');
}
Output
0.18750000000000000 = 3/16
addErrormethod
Ball addError(BigFloat err)

The ball with its radius grown by err (an upper bound, ≥ 0).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Widen a ball by a known error (e.g. a truncated series tail).
  print('${Ball.fromInt(1).addError(BigFloat.parse('0.001'))}');
}
Output
[1.000 +/- 0.0011]
absmethod
Ball abs()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromEndpoints(BigFloat.fromInt(-3), BigFloat.fromInt(1)).abs()}');
}
Output
[1.50 +/- 1.5]
unionmethod
Ball union(Ball o, {int? prec})

The union hull of two balls.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromInt(1).union(Ball.fromInt(2))}');
}
Output
[1.50 +/- 0.50]
toStringmethod
String toString()

"[3.14159265358979 +/- 3.2e-16]".

Operators

operator +operator
Ball operator +(Ball o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromInt(2).sqrt() + Ball.fromInt(3).sqrt()}');
}
Output
[3.146264369941973 +/- 8.9e-16]
operator -operator
Ball operator -(Ball o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final x = Ball.fromInt(2).sqrt();
  print('x − x = ${x - x} (contains 0, with the radius doubled)');
}
Output
x − x = [0 +/- 4.5e-16] (contains 0, with the radius doubled)
operator *operator
Ball operator *(Ball o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromInt(2).sqrt() * Ball.fromInt(2).sqrt()}');
}
Output
[2.000000000000000 +/- 1.1e-15]
operator /operator
Ball operator /(Ball o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Ball.fromInt(22) / Ball.fromInt(7)}');
}
Output
[3.142857142857143 +/- 4.5e-16]
operator -operator
Ball operator -()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${-Ball.parse('2.5')}');
}
Output
-2.5000000000000000
final class BigFloat implements Comparable<BigFloat>

A binary floating-point number man · 2^exp with a precision in bits, like an MPFR variable.

Every operation returns the exactly computed result rounded once to the target precision (by default the larger operand precision) in the requested RoundingMode, so results are reproducible bit for bit and match MPFR. The exponent is unbounded (a Raya int), there are signed zeros, \pm\infty and NaN. The mantissa is kept odd, so equal values have equal representations whatever their precision.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final two = BigFloat.fromInt(2);
  print('√2 to 50 digits: ${two.sqrt(prec: 180).toStringAsPrecision(50)}');
  final third = BigFloat.fromInt(1).div(BigFloat.fromInt(3), prec: 100);
  print('1/3 at 100 bits: ${third.toStringAsPrecision(30)}');
}
Output
√2 to 50 digits: 1.4142135623730950488016887242096980785696718753769
1/3 at 100 bits: 0.333333333333333333333333333333

Constructors

factory BigFloat.fromBits(BigInt m, int e, {int prec = 53, RoundingMode rnd = RoundingMode.nearestEven, bool sticky = false})

Rounds the exact value m · 2^e (plus a sticky tail, see roundBits) to prec bits.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // m·2^e rounded to 10 bits.
  print('${BigFloat.fromBits(BigInt.from(12345), -3, prec: 10)}');
}
Output
1544.0
factory BigFloat.fromInt(Object n, {int prec = 53, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.fromInt(BigInt.parse('123456789012345678901234567890'), prec: 40)}');
}
Output
1.2345678901239e+29
factory BigFloat.fromDouble(double x, {int prec = 53, RoundingMode rnd = RoundingMode.nearestEven})

The exact value of x (rounded only when prec < 53 bits of x are needed).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('0.1 exactly: ${BigFloat.fromDouble(0.1).toRational()}');
}
Output
0.1 exactly: 3602879701896397/36028797018963968
factory BigFloat.fromRational(Rational q, {int prec = 53, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.fromRational(Rational.fromInt(1, 3), prec: 100).toStringAsPrecision(30)}');
}
Output
0.333333333333333333333333333333
factory BigFloat.parse(String s, {int prec = 53, RoundingMode rnd = RoundingMode.nearestEven})

Parses a decimal ("3.14159", "-1e-400", "2/3", "inf", "nan"), correctly rounded to prec bits.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.parse('3.14159265358979323846264338327950288', prec: 120).toStringAsPrecision(35)}');
}
Output
3.1415926535897932384626433832795029
factory BigFloat.zero({int prec = 53, bool negative = false})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.zero()}, ${BigFloat.zero(negative: true)}');
}
Output
0.0, -0.0
factory BigFloat.infinity({int prec = 53, bool negative = false})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.infinity()}, ${BigFloat.infinity(negative: true)}');
}
Output
inf, -inf
factory BigFloat.nan({int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.nan()}');
}
Output
nan

Static

fmastaticmethod
static BigFloat fma(BigFloat a, BigFloat b, BigFloat c, {int? prec, RoundingMode rnd = RoundingMode.nearestEven})

a · b + c with a single rounding.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // a·b + c with one rounding: recovers the rounding error of a product.
  final a = BigFloat.parse('0.1'), b = BigFloat.parse('0.1');
  final p = a.mul(b);
  print('error of 0.1·0.1 in doubles: ${BigFloat.fma(a, b, -p, prec: 106)}');
}
Output
error of 0.1·0.1 in doubles: -8.32667268468867374502844640872342e-19

Properties

manfield
final BigInt man

Signed odd mantissa (zero for non-finite values and zeros).

expfield
final int exp

Binary exponent: the value is man · 2^exp.

final int precision

Precision in bits; the result precision of operators is the larger operand precision.

isNaNgetter
bool get isNaN
bool get isInfinite
isFinitegetter
bool get isFinite
isZerogetter
bool get isZero
bool get isNegative

True for negative values, -0 and -\infty (false for NaN).

signgetter
int get sign
bitCountgetter
int get bitCount

Bits in the mantissa.

magnitudegetter
int get magnitude

Exponent of the leading bit plus one (MPFR's mpfr_get_exp): 2^(magnitude-1) <= |x| < 2^magnitude.

ulpgetter
BigFloat get ulp

One unit in the last place at this precision.

hashCodegetter
int get hashCode

Methods

roundmethod
BigFloat round(int prec, [RoundingMode rnd = RoundingMode.nearestEven])

Rounds to prec bits (precision change, MPFR mpfr_prec_round).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final x = BigFloat.fromRational(Rational.fromInt(2, 3), prec: 100);
  print('${x.round(8)}, down ${x.round(8, RoundingMode.down)}, up ${x.round(8, RoundingMode.up)}');
}
Output
0.6680, down 0.6641, up 0.6680
addmethod
BigFloat add(BigFloat o, {int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.parse('1e30', prec: 120).add(BigFloat.fromInt(1), prec: 120)} (1 survives at 120 bits)');
}
Output
1.0000000000000000000000000000010000000e+30 (1 survives at 120 bits)
submethod
BigFloat sub(BigFloat o, {int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.parse('1e30', prec: 120).add(BigFloat.fromInt(1), prec: 120).sub(BigFloat.parse('1e30', prec: 120), prec: 120)}');
}
Output
1.0000000000000000000000000000000000000
mulmethod
BigFloat mul(BigFloat o, {int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.parse('1.1', prec: 100).mul(BigFloat.parse('1.1', prec: 100), prec: 100).toStringAsPrecision(25)}');
}
Output
1.210000000000000000000000
divmethod
BigFloat div(BigFloat o, {int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.fromInt(1).div(BigFloat.fromInt(7), prec: 200).toStringAsPrecision(50)}');
}
Output
0.14285714285714285714285714285714285714285714285714
sqrtmethod
BigFloat sqrt({int? prec, RoundingMode rnd = RoundingMode.nearestEven})

Correctly rounded square root; NaN for negative input, \sqrt{-0} = -0.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('√3 = ${BigFloat.fromInt(3).sqrt(prec: 300).toStringAsPrecision(80)}');
}
Output
√3 = 1.7320508075688772935274463415058723669428052538103806280558069794519330169088000
ldexpmethod
BigFloat ldexp(int k)

this · 2^k, exact.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.fromInt(5).ldexp(10)}, ${BigFloat.fromInt(5).ldexp(-3)}');
}
Output
5120.0000000000000, 0.62500000000000000
absmethod
BigFloat abs()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.parse('-2.5').abs()}');
}
Output
2.5000000000000000
nextUpmethod
BigFloat nextUp()

The next representable value toward +\infty at this precision.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.fromInt(1, prec: 10).nextUp()}');
}
Output
1.0020
nextDownmethod
BigFloat nextDown()

The next representable value toward -\infty at this precision.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.fromInt(1, prec: 10).nextDown()}');
}
Output
0.99902
Rational toRational()

The exact value (throws for \pm\infty and NaN).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.parse('0.1', prec: 10).toRational()}');
}
Output
819/8192
toDoublemethod
double toDouble([RoundingMode rnd = RoundingMode.nearestEven])

Nearest double (correctly rounded in rnd, subnormals included).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Constants.pi(prec: 200).toDouble()}');
}
Output
3.141592653589793
toBigIntmethod
BigInt toBigInt([RoundingMode rnd = RoundingMode.towardZero])

Integer part rounded in rnd (floor = down, ceil = up, truncate = towardZero).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.parse('-7.9').toBigInt()}, down ${BigFloat.parse('-7.9').toBigInt(RoundingMode.down)}');
}
Output
-7, down -8
compareTomethod
int compareTo(BigFloat o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.parse('0.1', prec: 100).compareTo(BigFloat.fromDouble(0.1))} (the double 0.1 is slightly larger)');
}
Output
-13108 (the double 0.1 is slightly larger)
String toStringAsPrecision(int digits, [RoundingMode rnd = RoundingMode.nearestEven])

digits significant decimal digits, correctly rounded in rnd: "3.1415926535897932385", "1.2345e-30".

(BigInt, int) decimalDigits(int digits, [RoundingMode rnd = RoundingMode.nearestEven])

The decimal N · 10^(d − digits + 1) nearest this value with |N| having exactly digits digits; returns (N, d) where d is the decimal exponent of the leading digit.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Constants.pi(prec: 100).decimalDigits(20)}');
}
Output
(31415926535897932385, 0)
toStringmethod
String toString()

Enough digits to round-trip at this precision.

Operators

operator +operator
BigFloat operator +(BigFloat o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.parse('0.1') + BigFloat.parse('0.2')}');
}
Output
0.30000000000000004
operator -operator
BigFloat operator -(BigFloat o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.fromInt(1) - BigFloat.parse('0.9')}');
}
Output
0.099999999999999978
operator *operator
BigFloat operator *(BigFloat o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.parse('1.5') * BigFloat.parse('2.25')}');
}
Output
3.3750000000000000
operator /operator
BigFloat operator /(BigFloat o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.fromInt(2) / BigFloat.fromInt(3)}');
}
Output
0.66666666666666663
operator -operator
BigFloat operator -()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${-BigFloat.parse('1.25')}');
}
Output
-1.2500000000000000
operator <operator
bool operator <(BigFloat o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.parse('0.1', prec: 100) < BigFloat.fromDouble(0.1)}');
}
Output
true
operator <=operator
bool operator <=(BigFloat o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigFloat.fromInt(2) <= BigFloat.fromInt(2)}');
}
Output
true
operator >operator
bool operator >(BigFloat o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Constants.pi(prec: 100) > BigFloat.parse('3.14159265358979')}');
}
Output
true
operator >=operator
bool operator >=(BigFloat o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Constants.e() >= BigFloat.parse('2.718281828459045')}');
}
Output
true
operator ==operator
bool operator ==(Object other)

Value equality (precision is ignored; -0 = +0; NaN != NaN).

final class BigComplex

A complex number re + i·im with BigFloat parts. Arithmetic rounds each part to nearest at prec (default the larger part precision); + − × are correctly rounded per part, ÷ and the elementary functions are accurate to a few units in the last place of the larger part (computed with guard bits), not correctly rounded; abs and arg are correctly rounded.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final z = BigComplex.fromInt(3, 4, 100);
  print('|3 + 4i| = ${z.abs()}, exp(iπ) = ${BigComplex(BigFloat.zero(prec: 100), Constants.pi(prec: 100)).exp()}');
}
Output
|3 + 4i| = 5.0000000000000000000000000000000, exp(iπ) = (-1.0000000000000000000000000000000 + 1.6956855320737799287917402938778e-31i)

Constructors

BigComplexconstructor
const BigComplex(this.re, this.im)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex(BigFloat.parse('1.5'), BigFloat.parse('-2'))}');
}
Output
(1.5000000000000000 - 2.0000000000000000i)
factory BigComplex.real(BigFloat re)

A real number as a complex one.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.real(BigFloat.fromInt(7))}');
}
Output
7.0000000000000000
factory BigComplex.fromInt(int re, [int im = 0, int prec = 53])
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(1, -1)}');
}
Output
(1.0000000000000000 - 1.0000000000000000i)
factory BigComplex.fromDoubles(double re, [double im = 0, int prec = 53])
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromDoubles(0.5, 0.25)}');
}
Output
(0.50000000000000000 + 0.25000000000000000i)
factory BigComplex.parse(String s, {int prec = 53})

Parses "1.5", "-2/3", or two parts "1.5, -2" (re, im), correctly rounded to prec bits.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
    // "re,im" (the imaginary part after a comma).
  print('${BigComplex.parse('1.5,2')}');
}
Output
(1.5000000000000000 + 2.0000000000000000i)
factory BigComplex.i({int prec = 53})

The imaginary unit at prec bits.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('i² = ${BigComplex.i().square()}');
}
Output
i² = -1.0000000000000000

Properties

refield
final BigFloat re
imfield
final BigFloat im
precisiongetter
int get precision
isRealgetter
bool get isReal
isZerogetter
bool get isZero
isFinitegetter
bool get isFinite
isNaNgetter
bool get isNaN
int get log2Magnitude

About log2 |z| (an int; 0 for zero).

int get magnitudeBits
hashCodegetter
int get hashCode

Methods

addmethod
BigComplex add(BigComplex o, {int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(1, 2).add(BigComplex.fromInt(3, -1))}');
}
Output
(4.0000000000000000 + 1.0000000000000000i)
submethod
BigComplex sub(BigComplex o, {int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(1, 2).sub(BigComplex.fromInt(3, -1))}');
}
Output
(-2.0000000000000000 + 3.0000000000000000i)
mulmethod
BigComplex mul(BigComplex o, {int? prec})

Each part is correctly rounded (exact products, one rounding): re·o.re − im·o.im and re·o.im + im·o.re.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(1, 2).mul(BigComplex.fromInt(3, -1))}');
}
Output
(5.0000000000000000 + 5.0000000000000000i)
divmethod
BigComplex div(BigComplex o, {int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(1, 2).div(BigComplex.fromInt(3, -1), prec: 60)}');
}
Output
(0.10000000000000000002 + 0.69999999999999999983i)
scalemethod
BigComplex scale(BigFloat s, {int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(1, 2).scale(BigFloat.parse('0.5'))}');
}
Output
(0.50000000000000000 + 1.0000000000000000i)
ldexpmethod
BigComplex ldexp(int k)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(3, 5).ldexp(2)}');
}
Output
(12.000000000000000 + 20.000000000000000i)
conjmethod
BigComplex conj()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(3, 5).conj()}');
}
Output
(3.0000000000000000 - 5.0000000000000000i)
squaremethod
BigComplex square({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('(1 + i)² = ${BigComplex.fromInt(1, 1).square()}');
}
Output
(1 + i)² = (0.0 + 2.0000000000000000i)
inversemethod
BigComplex inverse({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('1/(1 + i) = ${BigComplex.fromInt(1, 1).inverse()}');
}
Output
1/(1 + i) = (0.50000000000000000 - 0.50000000000000000i)
roundTomethod
BigComplex roundTo(int prec)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex(Constants.pi(prec: 200), Constants.e(prec: 200)).roundTo(20)}');
}
Output
(3.1415939 + 2.7182808i)
absmethod
BigFloat abs({int? prec})
z, correctly rounded (exact sum of squares, one square root).
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('|1 + i| = ${BigComplex.fromInt(1, 1, 120).abs().toStringAsPrecision(30)}');
}
Output
|1 + i| = 1.41421356237309504880168872421
normmethod
BigFloat norm({int? prec})
z² rounded to prec.
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('|3 + 4i|² = ${BigComplex.fromInt(3, 4).norm()}');
}
Output
|3 + 4i|² = 25.000000000000000
argmethod
BigFloat arg({int? prec})

The principal argument in (-\pi, \pi], correctly rounded.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('arg(−1) = ${BigComplex.fromInt(-1, 0, 120).arg().toStringAsPrecision(30)} (π)');
}
Output
arg(−1) = 3.14159265358979323846264338328 (π)
expmethod
BigComplex exp({int? prec})

e^{z}.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('e^{iπ} = ${BigComplex(BigFloat.zero(prec: 120), Constants.pi(prec: 120)).exp()}');
}
Output
e^{iπ} = (-1.0000000000000000000000000000000000000 - 5.5059930380881434362856026294599943387e-37i)
logmethod
BigComplex log({int? prec})

Principal logarithm: log|z| + i·arg z (\log|z| without cancellation near |z| = 1).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('log(−1) = ${BigComplex.fromInt(-1, 0, 100).log()}');
}
Output
log(−1) = (0.0 + 3.1415926535897932384626433832793i)
sqrtmethod
BigComplex sqrt({int? prec})

Principal square root (branch cut on the negative real axis, sqrt(−x) = i·sqrt(x)).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('√(−4) = ${BigComplex.fromInt(-4).sqrt()}, √i = ${BigComplex.i(prec: 80).sqrt()}');
}
Output
√(−4) = (0.0 + 2.0000000000000000i), √i = (0.70710678118654752440084474 + 0.70710678118654752440084474i)
powmethod
BigComplex pow(BigComplex w, {int? prec})

z^w = exp(w·log z) (principal), with exact binary powering for integer w.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('i^i = e^{−π/2} = ${BigComplex.i(prec: 100).pow(BigComplex.i(prec: 100))}');
}
Output
i^i = e^{−π/2} = 0.20787957635076190854695561983490
powIntmethod
BigComplex powInt(int n, {int? prec})

z^n by binary powering.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('(1 + i)^8 = ${BigComplex.fromInt(1, 1).powInt(8)}');
}
Output
(1 + i)^8 = 16.000000000000000
sinmethod
BigComplex sin({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('sin(i) = i·sinh 1 = ${BigComplex.i(prec: 80).sin()}');
}
Output
sin(i) = i·sinh 1 = (0.0 + 1.1752011936438014568823824i)
cosmethod
BigComplex cos({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('cos(i) = cosh 1 = ${BigComplex.i(prec: 80).cos()}');
}
Output
cos(i) = cosh 1 = 1.5430806348152437784779056
tanmethod
BigComplex tan({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromDoubles(0.5, 0.5, 80).tan()}');
}
Output
(0.40389645531602573986977336 + 0.56408314126749849830136361i)
sinhmethod
BigComplex sinh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromDoubles(1, 1, 80).sinh()}');
}
Output
(0.63496391478473610825508226 + 1.2984575814159772948260430i)
coshmethod
BigComplex cosh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromDoubles(1, 1, 80).cosh()}');
}
Output
(0.83373002513114904888388564 + 0.98889770576286509638212993i)
tanhmethod
BigComplex tanh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromDoubles(1, 1, 80).tanh()}');
}
Output
(1.0839233273386945434757514 + 0.27175258531951171652884380i)
atanmethod
BigComplex atan({int? prec})

Principal atan: (i/2)·(log(1 − iz) − log(1 + iz)).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('atan(1) = ${BigComplex.fromInt(1, 0, 100).atan()} (π/4)');
}
Output
atan(1) = 0.78539816339744830961566084581983 (π/4)
toDoublesmethod
(double, double) toDoubles()

(re, im) as doubles (nearest).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex(Constants.pi(prec: 100), Constants.e(prec: 100)).toDoubles()}');
}
Output
(3.141592653589793, 2.718281828459045)
toStringmethod
String toString()

Operators

operator +operator
BigComplex operator +(BigComplex o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(1, 1) + BigComplex.fromInt(1, -1)}');
}
Output
2.0000000000000000
operator -operator
BigComplex operator -(BigComplex o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(1, 1) - BigComplex.fromInt(1, -1)}');
}
Output
(0.0 + 2.0000000000000000i)
operator *operator
BigComplex operator *(BigComplex o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(1, 1) * BigComplex.fromInt(1, -1)}');
}
Output
2.0000000000000000
operator /operator
BigComplex operator /(BigComplex o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${BigComplex.fromInt(1, 1) / BigComplex.fromInt(1, -1)}');
}
Output
(0.0 + 1.0000000000000000i)
operator -operator
BigComplex operator -()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${-BigComplex.fromInt(1, -1)}');
}
Output
(-1.0000000000000000 + 1.0000000000000000i)
operator ==operator
bool operator ==(Object other)

Same parts (precision ignored).

final class DoubleInterval

The closed interval [lo, hi] of doubles. Each IEEE 754 operation (+ - \times \div \mathrm{sqrt}, correctly rounded to nearest) is widened by one step with nextDown / nextUp, so the result contains the exact real result for all points of the operands. Much faster than Interval (no BigInt work), at the cost of one ulp per operation. A value class on Raya (no allocation when it doesn't escape).

The empty set is [NaN, NaN]; lo may be -\infty and hi +\infty.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Fast interval arithmetic on doubles with outward rounding.
  const x = DoubleInterval(0.1, 0.1);
  final s = x + x + x;
  print('0.1 + 0.1 + 0.1 ⊆ $s, contains 0.3: ${s.contains(0.3)}; plain doubles give ${0.1 + 0.1 + 0.1}');
}
Output
0.1 + 0.1 + 0.1 ⊆ [0.29999999999999993, 0.3000000000000001], contains 0.3: true; plain doubles give 0.30000000000000004

Constructors

DoubleIntervalconstructor
const DoubleInterval(this.lo, this.hi)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  const x = DoubleInterval(1, 2);
  print('$x, width ${x.hi - x.lo}');
}
Output
[1.0, 2.0], width 1.0
const DoubleInterval.point(double x)

The degenerate interval [x, x].

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${DoubleInterval.point(0.5)}');
}
Output
[0.5, 0.5]

Static

entireconstant
static const DoubleInterval entire = DoubleInterval(double.negativeInfinity, double.infinity)
emptyconstant
static const DoubleInterval empty = DoubleInterval(double.nan, double.nan)

Properties

lofield
final double lo
hifield
final double hi
isEmptygetter
bool get isEmpty
bool get containsZero
bool get isPositive
bool get isNegative
widthgetter
double get width

Width rounded up.

midgetter
double get mid

Midpoint (finite intervals).

hashCodegetter
int get hashCode

Methods

containsmethod
bool contains(double x)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(1, 2).contains(1.5)}, ${const DoubleInterval(1, 2).contains(2.5)}');
}
Output
true, false
bool containsInterval(DoubleInterval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(0, 10).containsInterval(const DoubleInterval(2, 3))}');
}
Output
true
overlapsmethod
bool overlaps(DoubleInterval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(0, 1).overlaps(const DoubleInterval(1, 2))}');
}
Output
true
sqrtmethod
DoubleInterval sqrt()

Square root of the nonnegative part.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('√[2, 2] ⊆ ${const DoubleInterval(2, 2).sqrt()}');
}
Output
√[2, 2] ⊆ [1.414213562373095, 1.4142135623730954]
squaremethod
DoubleInterval square()

x², never negative.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('[−1, 2]² ⊆ ${const DoubleInterval(-1, 2).square()}');
}
Output
[−1, 2]² ⊆ [0.0, 4.000000000000001]
absmethod
DoubleInterval abs()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(-3, 1).abs()}');
}
Output
[0.0, 3.0]
intersectmethod
DoubleInterval intersect(DoubleInterval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(0, 2).intersect(const DoubleInterval(1, 3))}');
}
Output
[1.0, 2.0]
hullmethod
DoubleInterval hull(DoubleInterval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(0, 1).hull(const DoubleInterval(3, 4))}');
}
Output
[0.0, 4.0]
bisectmethod
(DoubleInterval, DoubleInterval) bisect()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(0, 1).bisect()}');
}
Output
([0.0, 0.5], [0.5, 1.0])
toStringmethod
String toString()

Operators

operator +operator
DoubleInterval operator +(DoubleInterval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(1, 2) + const DoubleInterval(0.1, 0.1)}');
}
Output
[1.0999999999999999, 2.1000000000000005]
operator -operator
DoubleInterval operator -(DoubleInterval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  const x = DoubleInterval(1, 2);
  print('x − x = ${x - x} (the dependency problem)');
}
Output
x − x = [-1.0000000000000002, 1.0000000000000002] (the dependency problem)
operator -operator
DoubleInterval operator -()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${-const DoubleInterval(1, 2)}');
}
Output
[-2.0, -1.0]
operator *operator
DoubleInterval operator *(DoubleInterval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(-1, 2) * const DoubleInterval(3, 4)}');
}
Output
[-4.000000000000001, 8.000000000000002]
operator /operator
DoubleInterval operator /(DoubleInterval o)

A divisor containing 0 gives the entire line (empty for [0, 0]).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(1, 1) / const DoubleInterval(3, 3)}, by an interval containing 0: ${const DoubleInterval(1, 1) / const DoubleInterval(-1, 1)}');
}
Output
[0.33333333333333326, 0.33333333333333337], by an interval containing 0: [-Infinity, Infinity]
operator ==operator
bool operator ==(Object other)
abstract final class Constants

Mathematical constants to any precision, correctly rounded.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('π to 60 digits:  ${Constants.pi(prec: 210).toStringAsPrecision(60)}');
  print('e to 40 digits:  ${Constants.e(prec: 140).toStringAsPrecision(40)}');
  print('ln 2 to 30:      ${Constants.ln2(prec: 110).toStringAsPrecision(30)}');
}
Output
π to 60 digits:  3.14159265358979323846264338327950288419716939937510582097494
e to 40 digits:  2.718281828459045235360287471352662497757
ln 2 to 30:      0.693147180559945309417232121458

Static

pistaticmethod
static BigFloat pi({int prec = 53, RoundingMode rnd = RoundingMode.nearestEven})

\pi.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('π to 60 digits: ${Constants.pi(prec: 210).toStringAsPrecision(60)}');
  print('rounded down vs up at 20 bits: ${Constants.pi(prec: 20, rnd: RoundingMode.down)} / ${Constants.pi(prec: 20, rnd: RoundingMode.up)}');
}
Output
π to 60 digits: 3.14159265358979323846264338327950288419716939937510582097494
rounded down vs up at 20 bits: 3.1415901 / 3.1415939
estaticmethod
static BigFloat e({int prec = 53, RoundingMode rnd = RoundingMode.nearestEven})

e = \exp(1).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('e to 40 digits: ${Constants.e(prec: 140).toStringAsPrecision(40)}');
  print('rounded down vs up at 20 bits: ${Constants.e(prec: 20, rnd: RoundingMode.down)} / ${Constants.e(prec: 20, rnd: RoundingMode.up)}');
}
Output
e to 40 digits: 2.718281828459045235360287471352662497757
rounded down vs up at 20 bits: 2.7182808 / 2.7182846
ln2staticmethod
static BigFloat ln2({int prec = 53, RoundingMode rnd = RoundingMode.nearestEven})

\ln 2.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('ln 2 to 30 digits: ${Constants.ln2(prec: 110).toStringAsPrecision(30)}');
  print('rounded down vs up at 20 bits: ${Constants.ln2(prec: 20, rnd: RoundingMode.down)} / ${Constants.ln2(prec: 20, rnd: RoundingMode.up)}');
}
Output
ln 2 to 30 digits: 0.693147180559945309417232121458
rounded down vs up at 20 bits: 0.69314671 / 0.69314766
eulerstaticmethod
static BigFloat euler({int prec = 53, RoundingMode rnd = RoundingMode.nearestEven})

Euler–Mascheroni constant \gamma.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('γ (Euler–Mascheroni) to 40 digits: ${Constants.euler(prec: 140).toStringAsPrecision(40)}');
  print('rounded down vs up at 20 bits: ${Constants.euler(prec: 20, rnd: RoundingMode.down)} / ${Constants.euler(prec: 20, rnd: RoundingMode.up)}');
}
Output
γ (Euler–Mascheroni) to 40 digits: 0.5772156649015328606065120900824024310422
rounded down vs up at 20 bits: 0.57721519 / 0.57721615
catalanstaticmethod
static BigFloat catalan({int prec = 53, RoundingMode rnd = RoundingMode.nearestEven})

Catalan's constant G.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Catalan G to 40 digits: ${Constants.catalan(prec: 140).toStringAsPrecision(40)}');
  print('rounded down vs up at 20 bits: ${Constants.catalan(prec: 20, rnd: RoundingMode.down)} / ${Constants.catalan(prec: 20, rnd: RoundingMode.up)}');
}
Output
Catalan G to 40 digits: 0.9159655941772190150546035149323841107741
rounded down vs up at 20 bits: 0.91596508 / 0.91596603
piBallAtstaticmethod
static Ball piBallAt(int prec)

Balls containing the constants at about prec bits.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('π enclosed at 100 bits: ${Constants.piBallAt(100)}');
}
Output
π enclosed at 100 bits: [3.14159265358979323846264338328 +/- 3.2e-30]
eBallAtstaticmethod
static Ball eBallAt(int prec)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('e enclosed at 100 bits: ${Constants.eBallAt(100)}');
}
Output
e enclosed at 100 bits: [2.71828182845904523536028747135 +/- 3.2e-30]
ln2BallAtstaticmethod
static Ball ln2BallAt(int prec)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('ln 2 enclosed at 100 bits: ${Constants.ln2BallAt(100)}');
}
Output
ln 2 enclosed at 100 bits: [0.693147180559945309417232121458 +/- 8.0e-31]
eulerBallAtstaticmethod
static Ball eulerBallAt(int prec)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('γ (Euler–Mascheroni) enclosed at 100 bits: ${Constants.eulerBallAt(100)}');
}
Output
γ (Euler–Mascheroni) enclosed at 100 bits: [0.577215664901532860606512090082 +/- 8.0e-31]
catalanBallAtstaticmethod
static Ball catalanBallAt(int prec)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Catalan G enclosed at 100 bits: ${Constants.catalanBallAt(100)}');
}
Output
Catalan G enclosed at 100 bits: [0.915965594177219015054603514933 +/- 8.0e-31]
extension BigFloatElementary on BigFloat

Correctly rounded elementary functions (MPFR semantics): the exact result rounded once to prec bits (default the operand precision) in rnd. Special values follow IEEE 754 / MPFR; beyond |x| \ge 2^{60} the exponential family saturates (the result exponent must fit an int).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Correctly rounded elementary functions at any precision.
  final x = BigFloat.fromInt(1, prec: 300);
  print('e = ${x.exponential().toStringAsPrecision(80)}');
}
Output
e = 2.7182818284590452353602874713526624977572470936999595749669676277240766303535476

Methods

BigFloat exponential({int? prec, RoundingMode rnd = RoundingMode.nearestEven})

e^{x} (named exponential because BigFloat.exp is the binary exponent).

Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('1', prec: 200);
  print('exp(1) = e: ${x.exponential().toStringAsPrecision(45)}');
  print('double:  ${math.exp(1.0)}');
}
Output
exp(1) = e: 2.71828182845904523536028747135266249775724709
double:  2.718281828459045
expm1method
BigFloat expm1({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('1e-20', prec: 200);
  print('expm1(10⁻²⁰): no cancellation: ${x.expm1().toStringAsPrecision(45)}');
  print('double:  ${math.exp(1e-20) - 1}');
}
Output
expm1(10⁻²⁰): no cancellation: 1.00000000000000000000500000000000000000001667e-20
double:  0.0
logmethod
BigFloat log({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('2', prec: 200);
  print('log 2: ${x.log().toStringAsPrecision(45)}');
  print('double:  ${math.log(2.0)}');
}
Output
log 2: 0.693147180559945309417232121458176568075500134
double:  0.6931471805599453
log1pmethod
BigFloat log1p({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('1e-20', prec: 200);
  print('log1p(10⁻²⁰): ${x.log1p().toStringAsPrecision(45)}');
  print('double:  ${math.log(1 + 1e-20)}');
}
Output
log1p(10⁻²⁰): 9.99999999999999999995000000000000000000033333e-21
double:  0.0
powmethod
BigFloat pow(BigFloat y, {int? prec, RoundingMode rnd = RoundingMode.nearestEven})

this^y (IEEE 754 pow special values; exact when the result is representable).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // 2^(1/2) and 10^0.1 to 45 digits.
  final two = BigFloat.fromInt(2, prec: 200);
  print('2^(1/2) = ${two.pow(BigFloat.parse('0.5', prec: 200)).toStringAsPrecision(45)}');
  print('10^0.1  = ${BigFloat.fromInt(10, prec: 200).pow(BigFloat.parse('0.1', prec: 200)).toStringAsPrecision(45)}');
}
Output
2^(1/2) = 1.41421356237309504880168872420969807856967188
10^0.1  = 1.25892541179416721042395410639580060609361741
sinmethod
BigFloat sin({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('1e22', prec: 200);
  print('sin(10²²), a hard argument reduction: ${x.sin().toStringAsPrecision(45)}');
  print('double:  ${math.sin(1e22)}');
}
Output
sin(10²²), a hard argument reduction: -0.852200849767188801772705893753029368261762150
double:  -0.8522008497671888
cosmethod
BigFloat cos({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('0.5', prec: 200);
  print('cos(1/2): ${x.cos().toStringAsPrecision(45)}');
  print('double:  ${math.cos(0.5)}');
}
Output
cos(1/2): 0.877582561890372716116281582603829651991645197
double:  0.8775825618903728
tanmethod
BigFloat tan({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('1.5', prec: 200);
  print('tan(1.5): ${x.tan().toStringAsPrecision(45)}');
  print('double:  ${(math.tan(1.5)).toStringAsPrecision(15)}');
}
Output
tan(1.5): 14.1014199471717193876460836519877564456595436
double:  14.1014199471717
atanmethod
BigFloat atan({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('1', prec: 200);
  print('atan 1 = π/4: ${x.atan().toStringAsPrecision(45)}');
  print('double:  ${math.atan(1.0)}');
}
Output
atan 1 = π/4: 0.785398163397448309615660845819875721049292350
double:  0.7853981633974483
atan2method
BigFloat atan2(BigFloat x, {int? prec, RoundingMode rnd = RoundingMode.nearestEven})

atan2(this, x): the angle of the point (x, this), in (-\pi, \pi] (IEEE 754 special values).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final y = BigFloat.fromInt(1, prec: 200), x = BigFloat.fromInt(-1, prec: 200);
  print('atan2(1, −1) = 3π/4 = ${y.atan2(x).toStringAsPrecision(45)}');
}
Output
atan2(1, −1) = 3π/4 = 2.35619449019234492884698253745962716314787705
asinmethod
BigFloat asin({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('0.5', prec: 200);
  print('asin(1/2) = π/6: ${x.asin().toStringAsPrecision(45)}');
  print('double:  ${(math.asin(0.5)).toStringAsPrecision(15)}');
}
Output
asin(1/2) = π/6: 0.523598775598298873077107230546583814032861567
double:  0.523598775598299
acosmethod
BigFloat acos({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('0.5', prec: 200);
  print('acos(1/2) = π/3: ${x.acos().toStringAsPrecision(45)}');
  print('double:  ${(math.acos(0.5)).toStringAsPrecision(15)}');
}
Output
acos(1/2) = π/3: 1.04719755119659774615421446109316762806572313
double:  1.04719755119660
sinhmethod
BigFloat sinh({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('1', prec: 200);
  print('sinh 1: ${x.sinh().toStringAsPrecision(45)}');
  print('double:  ${(math.exp(1.0) - math.exp(-1.0)) / 2}');
}
Output
sinh 1: 1.17520119364380145688238185059560081515571798
double:  1.1752011936438014
coshmethod
BigFloat cosh({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('1', prec: 200);
  print('cosh 1: ${x.cosh().toStringAsPrecision(45)}');
  print('double:  ${(math.exp(1.0) + math.exp(-1.0)) / 2}');
}
Output
cosh 1: 1.54308063481524377847790562075706168260152911
double:  1.5430806348152437
tanhmethod
BigFloat tanh({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('0.5', prec: 200);
  print('tanh(1/2): ${x.tanh().toStringAsPrecision(45)}');
  print('double:  ${(math.exp(1.0) - 1) / (math.exp(1.0) + 1)}');
}
Output
tanh(1/2): 0.462117157260009758502318483643672548730289280
double:  0.46211715726000974
asinhmethod
BigFloat asinh({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('1', prec: 200);
  print('asinh 1: ${x.asinh().toStringAsPrecision(45)}');
  print('double:  ${math.log(1 + math.sqrt(2.0))}');
}
Output
asinh 1: 0.881373587019543025232609324979792309028160328
double:  0.8813735870195429
acoshmethod
BigFloat acosh({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('2', prec: 200);
  print('acosh 2: ${x.acosh().toStringAsPrecision(45)}');
  print('double:  ${math.log(2 + math.sqrt(3.0))}');
}
Output
acosh 2: 1.31695789692481670862504634730796844402698197
double:  1.3169578969248166
atanhmethod
BigFloat atanh({int? prec, RoundingMode rnd = RoundingMode.nearestEven})
Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:math' as math;

void main() {
  final x = BigFloat.parse('0.5', prec: 200);
  print('atanh(1/2): ${x.atanh().toStringAsPrecision(45)}');
  print('double:  ${(0.5 * math.log(3.0)).toStringAsPrecision(15)}');
}
Output
atanh(1/2): 0.549306144334054845697622618461262852323745279
double:  0.549306144334055
extension BallElementary on Ball

Elementary functions over balls (Arb semantics: a ball not inside the domain gives an indeterminate result).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final x = Ball.parse('0.1', prec: 100);
  print('exp(0.1) ∈ ${x.exp()}, sin(0.1) ∈ ${x.sin()}');
}
Output
exp(0.1) ∈ [1.105170918075647624811707826491 +/- 5.6e-31], sin(0.1) ∈ [0.0998334166468281523068141984106 +/- 2.0e-31]

Methods

expmethod
Ball exp({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('1', prec: 120);
  print('exp(1) ∈ ${x.exp()}');
}
Output
exp(1) ∈ [2.71828182845904523536028747135266250 +/- 3.1e-36]
expm1method
Ball expm1({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('1e-10', prec: 120);
  print('expm1(1e-10) ∈ ${x.expm1()}');
}
Output
expm1(1e-10) ∈ [1.00000000005000000000166666666670833e-10 +/- 1.1e-46]
logmethod
Ball log({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('2', prec: 120);
  print('log(2) ∈ ${x.log()}');
}
Output
log(2) ∈ [0.693147180559945309417232121458176568 +/- 7.6e-37]
log1pmethod
Ball log1p({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('0.001', prec: 120);
  print('log1p(0.001) ∈ ${x.log1p()}');
}
Output
log1p(0.001) ∈ [0.000999500333083533166809398920535011461 +/- 1.8e-39]
atanmethod
Ball atan({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('1', prec: 120);
  print('atan(1) ∈ ${x.atan()}');
}
Output
atan(1) ∈ [0.785398163397448309615660845819875721 +/- 7.6e-37]
asinmethod
Ball asin({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('0.5', prec: 120);
  print('asin(0.5) ∈ ${x.asin()}');
}
Output
asin(0.5) ∈ [0.523598775598298873077107230546583814 +/- 7.6e-37]
acosmethod
Ball acos({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('0.5', prec: 120);
  print('acos(0.5) ∈ ${x.acos()}');
}
Output
acos(0.5) ∈ [1.04719755119659774615421446109316763 +/- 1.6e-36]
sinhmethod
Ball sinh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('1', prec: 120);
  print('sinh(1) ∈ ${x.sinh()}');
}
Output
sinh(1) ∈ [1.17520119364380145688238185059560082 +/- 1.6e-36]
tanhmethod
Ball tanh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('0.5', prec: 120);
  print('tanh(0.5) ∈ ${x.tanh()}');
}
Output
tanh(0.5) ∈ [0.462117157260009758502318483643672549 +/- 3.8e-37]
asinhmethod
Ball asinh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('1', prec: 120);
  print('asinh(1) ∈ ${x.asinh()}');
}
Output
asinh(1) ∈ [0.881373587019543025232609324979792309 +/- 7.6e-37]
acoshmethod
Ball acosh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('2', prec: 120);
  print('acosh(2) ∈ ${x.acosh()}');
}
Output
acosh(2) ∈ [1.31695789692481670862504634730796844 +/- 1.6e-36]
atanhmethod
Ball atanh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('0.5', prec: 120);
  print('atanh(0.5) ∈ ${x.atanh()}');
}
Output
atanh(0.5) ∈ [0.549306144334054845697622618461262852 +/- 7.6e-37]
sinmethod
Ball sin({int? prec})
sin'≤ 1: the midpoint value plus the radius.
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('1', prec: 120);
  print('sin(1) ∈ ${x.sin()}');
}
Output
sin(1) ∈ [0.841470984807896506652502321630298999 +/- 7.6e-37]
cosmethod
Ball cos({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('1', prec: 120);
  print('cos(1) ∈ ${x.cos()}');
}
Output
cos(1) ∈ [0.540302305868139717400936607442976604 +/- 7.6e-37]
tanmethod
Ball tan({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('1', prec: 120);
  print('tan(1) ∈ ${x.tan()}');
}
Output
tan(1) ∈ [1.55740772465490223050697480745836017 +/- 1.6e-36]
coshmethod
Ball cosh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // The result ball is guaranteed to contain the true value.
  final x = Ball.parse('1', prec: 120);
  print('cosh(1) ∈ ${x.cosh()}');
}
Output
cosh(1) ∈ [1.54308063481524377847790562075706168 +/- 1.6e-36]
powermethod
Ball power(Ball y, {int? prec})

this^y for a positive base: exp(y \cdot \log this).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('2^0.5 ∈ ${Ball.fromInt(2, prec: 120).power(Ball.parse('0.5', prec: 120))}');
}
Output
2^0.5 ∈ [1.414213562373095048801688724209698079 +/- 5.8e-37]
atan2method
Ball atan2(Ball x, {int? prec})

Atan2(this, x) (through the interval version: corners, or (-\pi, \pi] across the branch cut).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('atan2(1, 1) ∈ ${Ball.fromInt(1, prec: 120).atan2(Ball.fromInt(1, prec: 120))} (π/4)');
}
Output
atan2(1, 1) ∈ [0.7853981633974483096156608458198757212 +/- 1.4e-37] (π/4)
extension IntervalElementary on Interval

Elementary functions over intervals, restricted to the domain (log([−1, 4]) = [−∞, log 4]).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final x = Interval.parse('[0, 3.2]');
  print('sin([0, 3.2]) ⊆ ${x.sin()} (includes the maximum 1 at π/2)');
}
Output
sin([0, 3.2]) ⊆ [-0.058374143427580093, 1.0000000000000000] (includes the maximum 1 at π/2)

Methods

expmethod
Interval exp({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of exp over the whole interval.
  final x = Interval.parse('[1, 1.1]');
  print('exp([1, 1.1]) ⊆ ${x.exp()}');
}
Output
exp([1, 1.1]) ⊆ [2.7182818284590450, 3.0041660239464334]
expm1method
Interval expm1({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of expm1 over the whole interval.
  final x = Interval.parse('[1e-10, 2e-10]');
  print('expm1([1e-10, 2e-10]) ⊆ ${x.expm1()}');
}
Output
expm1([1e-10, 2e-10]) ⊆ [1.0000000000499998e-10, 2.0000000002000002e-10]
logmethod
Interval log({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of log over the whole interval.
  final x = Interval.parse('[2, 21]');
  print('log([2, 21]) ⊆ ${x.log()}');
}
Output
log([2, 21]) ⊆ [0.69314718055994528, 3.0445224377234231]
log1pmethod
Interval log1p({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of log1p over the whole interval.
  final x = Interval.parse('[0.001, 0.0011]');
  print('log1p([0.001, 0.0011]) ⊆ ${x.log1p()}');
}
Output
log1p([0.001, 0.0011]) ⊆ [0.00099950033308353293, 0.0010993954433009637]
atanmethod
Interval atan({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of atan over the whole interval.
  final x = Interval.parse('[1, 1.1]');
  print('atan([1, 1.1]) ⊆ ${x.atan()}');
}
Output
atan([1, 1.1]) ⊆ [0.78539816339744827, 0.83298126667443185]
asinmethod
Interval asin({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of asin over the whole interval.
  final x = Interval.parse('[0.5, 0.51]');
  print('asin([0.5, 0.51]) ⊆ ${x.asin()}');
}
Output
asin([0.5, 0.51]) ⊆ [0.52359877559829881, 0.53518479027559996]
acosmethod
Interval acos({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of acos over the whole interval.
  final x = Interval.parse('[0.5, 0.51]');
  print('acos([0.5, 0.51]) ⊆ ${x.acos()}');
}
Output
acos([0.5, 0.51]) ⊆ [1.0356115365192966, 1.0471975511965979]
sinhmethod
Interval sinh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of sinh over the whole interval.
  final x = Interval.parse('[1, 1.1]');
  print('sinh([1, 1.1]) ⊆ ${x.sinh()}');
}
Output
sinh([1, 1.1]) ⊆ [1.1752011936438013, 1.3356474701241770]
tanhmethod
Interval tanh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of tanh over the whole interval.
  final x = Interval.parse('[0.5, 0.51]');
  print('tanh([0.5, 0.51]) ⊆ ${x.tanh()}');
}
Output
tanh([0.5, 0.51]) ⊆ [0.46211715726000973, 0.46994519893303766]
asinhmethod
Interval asinh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of asinh over the whole interval.
  final x = Interval.parse('[1, 1.1]');
  print('asinh([1, 1.1]) ⊆ ${x.asinh()}');
}
Output
asinh([1, 1.1]) ⊆ [0.88137358701954293, 0.95034692982113434]
acoshmethod
Interval acosh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of acosh over the whole interval.
  final x = Interval.parse('[2, 21]');
  print('acosh([2, 21]) ⊆ ${x.acosh()}');
}
Output
acosh([2, 21]) ⊆ [1.3169578969248165, 3.7371022421989242]
atanhmethod
Interval atanh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of atanh over the whole interval.
  final x = Interval.parse('[0.5, 0.51]');
  print('atanh([0.5, 0.51]) ⊆ ${x.atanh()}');
}
Output
atanh([0.5, 0.51]) ⊆ [0.54930614433405478, 0.56272976935214892]
coshmethod
Interval cosh({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of cosh over the whole interval.
  final x = Interval.parse('[1, 1.1]');
  print('cosh([1, 1.1]) ⊆ ${x.cosh()}');
}
Output
cosh([1, 1.1]) ⊆ [1.5430806348152437, 1.6685185538222567]
sinmethod
Interval sin({int? prec})

Sin over the interval: the endpoint values, plus \pm1 wherever the interval may contain \frac{\pi}{2} + 2k\pi or -\frac{\pi}{2} + 2k\pi.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of sin over the whole interval.
  final x = Interval.parse('[1, 1.1]');
  print('sin([1, 1.1]) ⊆ ${x.sin()}');
}
Output
sin([1, 1.1]) ⊆ [0.84147098480789650, 0.89120736006143542]
cosmethod
Interval cos({int? prec})

Cos = the same with extrema at 2k\pi (max) and \pi + 2k\pi (min).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of cos over the whole interval.
  final x = Interval.parse('[1, 1.1]');
  print('cos([1, 1.1]) ⊆ ${x.cos()}');
}
Output
cos([1, 1.1]) ⊆ [0.45359612142557725, 0.54030230586813977]
tanmethod
Interval tan({int? prec})

Tan: monotone between poles; the entire line when the interval may contain a pole \frac{\pi}{2} + k\pi.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // An enclosure of tan over the whole interval.
  final x = Interval.parse('[1, 1.1]');
  print('tan([1, 1.1]) ⊆ ${x.tan()}');
}
Output
tan([1, 1.1]) ⊆ [1.5574077246549020, 1.9647596572486526]
powermethod
Interval power(Interval y, {int? prec})

this^y for the positive part of the base: \exp(y \cdot \log x).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('[2, 3]^[0.5, 1] ⊆ ${Interval.parse('[2, 3]').power(Interval.parse('[0.5, 1]'))}');
}
Output
[2, 3]^[0.5, 1] ⊆ [1.4142135623730949, 3.0000000000000005]
atan2method
Interval atan2(Interval x, {int? prec})

Atan2(this, x): corners of the box when it avoids the origin and the branch cut, else [-\pi, \pi].

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('atan2([1, 2], [1, 2]) ⊆ ${Interval.parse('[1, 2]').atan2(Interval.parse('[1, 2]'))}');
}
Output
atan2([1, 2], [1, 2]) ⊆ [0.46364760900080609, 1.1071487177940907]
extension DoubleIntervalElementary on DoubleInterval
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  const x = DoubleInterval(0.1, 0.2);
  print('exp ⊆ ${x.exp()}, sin ⊆ ${x.sin()}');
}
Output
exp ⊆ [1.1051709180756475, 1.2214027581601699], sin ⊆ [0.09983341664682815, 0.19866933079506124]

Methods

expmethod
DoubleInterval exp()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(1, 1);
  final r = x.exp();
  print('exp(1) ∈ $r, width ${r.hi - r.lo}');
}
Output
exp(1) ∈ [2.718281828459045, 2.7182818284590455], width 4.440892098500626e-16
expm1method
DoubleInterval expm1()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(0.001, 0.001);
  final r = x.expm1();
  print('expm1(0.001) ∈ $r, width ${r.hi - r.lo}');
}
Output
expm1(0.001) ∈ [0.0010005001667083417, 0.0010005001667083419], width 2.168404344971009e-19
logmethod
DoubleInterval log()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(2, 2);
  final r = x.log();
  print('log(2) ∈ $r, width ${r.hi - r.lo}');
}
Output
log(2) ∈ [0.6931471805599453, 0.6931471805599454], width 1.1102230246251565e-16
log1pmethod
DoubleInterval log1p()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(0.001, 0.001);
  final r = x.log1p();
  print('log1p(0.001) ∈ $r, width ${r.hi - r.lo}');
}
Output
log1p(0.001) ∈ [0.0009995003330835331, 0.0009995003330835334], width 2.168404344971009e-19
sinmethod
DoubleInterval sin()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(1, 1);
  final r = x.sin();
  print('sin(1) ∈ $r, width ${r.hi - r.lo}');
}
Output
sin(1) ∈ [0.8414709848078965, 0.8414709848078966], width 1.1102230246251565e-16
cosmethod
DoubleInterval cos()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(1, 1);
  final r = x.cos();
  print('cos(1) ∈ $r, width ${r.hi - r.lo}');
}
Output
cos(1) ∈ [0.5403023058681397, 0.5403023058681398], width 1.1102230246251565e-16
tanmethod
DoubleInterval tan()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(1, 1);
  final r = x.tan();
  print('tan(1) ∈ $r, width ${r.hi - r.lo}');
}
Output
tan(1) ∈ [1.557407724654902, 1.5574077246549023], width 2.220446049250313e-16
atanmethod
DoubleInterval atan()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(1, 1);
  final r = x.atan();
  print('atan(1) ∈ $r, width ${r.hi - r.lo}');
}
Output
atan(1) ∈ [0.7853981633974483, 0.7853981633974484], width 1.1102230246251565e-16
asinmethod
DoubleInterval asin()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(0.5, 0.5);
  final r = x.asin();
  print('asin(0.5) ∈ $r, width ${r.hi - r.lo}');
}
Output
asin(0.5) ∈ [0.5235987755982988, 0.5235987755982989], width 1.1102230246251565e-16
acosmethod
DoubleInterval acos()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(0.5, 0.5);
  final r = x.acos();
  print('acos(0.5) ∈ $r, width ${r.hi - r.lo}');
}
Output
acos(0.5) ∈ [1.0471975511965976, 1.0471975511965979], width 2.220446049250313e-16
sinhmethod
DoubleInterval sinh()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(1, 1);
  final r = x.sinh();
  print('sinh(1) ∈ $r, width ${r.hi - r.lo}');
}
Output
sinh(1) ∈ [1.1752011936438014, 1.1752011936438016], width 2.220446049250313e-16
coshmethod
DoubleInterval cosh()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(1, 1);
  final r = x.cosh();
  print('cosh(1) ∈ $r, width ${r.hi - r.lo}');
}
Output
cosh(1) ∈ [1.5430806348152437, 1.543080634815244], width 2.220446049250313e-16
tanhmethod
DoubleInterval tanh()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(0.5, 0.5);
  final r = x.tanh();
  print('tanh(0.5) ∈ $r, width ${r.hi - r.lo}');
}
Output
tanh(0.5) ∈ [0.46211715726000974, 0.4621171572600098], width 5.551115123125783e-17
asinhmethod
DoubleInterval asinh()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(1, 1);
  final r = x.asinh();
  print('asinh(1) ∈ $r, width ${r.hi - r.lo}');
}
Output
asinh(1) ∈ [0.8813735870195429, 0.881373587019543], width 1.1102230246251565e-16
acoshmethod
DoubleInterval acosh()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(2, 2);
  final r = x.acosh();
  print('acosh(2) ∈ $r, width ${r.hi - r.lo}');
}
Output
acosh(2) ∈ [1.3169578969248166, 1.3169578969248168], width 2.220446049250313e-16
atanhmethod
DoubleInterval atanh()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Double endpoints, rounded outward so the true value stays inside.
  const x = DoubleInterval(0.5, 0.5);
  final r = x.atanh();
  print('atanh(0.5) ∈ $r, width ${r.hi - r.lo}');
}
Output
atanh(0.5) ∈ [0.5493061443340548, 0.5493061443340549], width 1.1102230246251565e-16
powermethod
DoubleInterval power(DoubleInterval y)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(2, 3).power(const DoubleInterval(2, 2))}');
}
Output
[4.0, 9.0]
atan2method
DoubleInterval atan2(DoubleInterval x)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${const DoubleInterval(1, 1).atan2(const DoubleInterval(1, 1))}');
}
Output
[0.7853981633974483, 0.7853981633974484]
final class Interval

The closed set [lo, hi] of real numbers, lo ≤ hi, with lo ∈ [−∞, ∞) and hi ∈ (−∞, ∞]; or the empty set.

Lower endpoints are rounded toward -\infty and upper endpoints toward +\infty, so every operation returns an interval containing f(x, y) for every x and y in the operands (the inclusion property). Operators use the largest endpoint precision; the named methods take prec. Functions are restricted to their domain: sqrt([−1, 4]) is [0, 2], sqrt([−2, −1]) is empty.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Interval arithmetic: the true result is guaranteed to lie inside.
  final x = Interval.parse('[1.0, 2.0]');
  print('x = $x');
  print('x² = ${x.square()}');
  // x − x is not 0: the two operands are treated as independent intervals.
  print('x − x = ${x - x}');
  print('√2 enclosed: ${Interval.fromInt(2).sqrt()}');
}
Output
x = [1.0000000000000000, 2.0000000000000000]
x² = [1.0000000000000000, 4.0000000000000000]
x − x = [-1.0000000000000000, 1.0000000000000000]
√2 enclosed: [1.4142135623730949, 1.4142135623730952]

Constructors

Intervalfactory
factory Interval(BigFloat lo, BigFloat hi)

[lo, hi]; throws when lo > hi, an endpoint is NaN, or lo = +∞ / hi = −∞.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval(BigFloat.parse('1.5'), BigFloat.parse('2.5'))}');
}
Output
[1.5000000000000000, 2.5000000000000000]
factory Interval.point(BigFloat x)

The single point x.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.point(BigFloat.parse('0.75'))}');
}
Output
[0.75000000000000000, 0.75000000000000000]
factory Interval.fromInt(Object n, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.fromInt(BigInt.from(10).pow(20) + BigInt.one)} (rounded outward at 53 bits)');
}
Output
[1.0000000000000000e+20, 1.0000000000000002e+20] (rounded outward at 53 bits)
factory Interval.fromRational(Rational q, {int prec = 53})

The tightest interval at prec bits containing q.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('1/3 ∈ ${Interval.fromRational(Rational.fromInt(1, 3), prec: 80)}');
}
Output
1/3 ∈ [0.33333333333333333333333305, 0.33333333333333333333333348]
factory Interval.fromRationals(Rational a, Rational b, {int prec = 53})

The tightest interval containing [a, b] (rationals, a \le b).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.fromRationals(Rational.fromInt(1, 3), Rational.fromInt(2, 3))}');
}
Output
[0.33333333333333331, 0.66666666666666675]
factory Interval.parse(String s, {int prec = 53})

The tightest interval containing the decimal s ("0.1", "1/3"), or "[a, b]".

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0.1, 0.2]')}, ${Interval.parse('0.1')}');
}
Output
[0.099999999999999991, 0.20000000000000002], [0.099999999999999991, 0.10000000000000001]
factory Interval.fromDouble(double x, {int prec = 53})

The interval [x − 2^-k, x + 2^-k]-style enclosure of a double: exact.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.fromDouble(0.1)}');
}
Output
[0.10000000000000000, 0.10000000000000001]
factory Interval.fromBall(Ball b, {int? prec})

[mid − rad, mid + rad] rounded outward.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.fromBall(Ball.fromInt(2).sqrt())}');
}
Output
[1.4142135623730949, 1.4142135623730954]
factory Interval.entire({int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.entire()}');
}
Output
[-inf, inf]
factory Interval.empty({int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.empty()}');
}
Output
[empty]

Properties

lofield
final BigFloat lo

Lower endpoint (NaN for the empty set).

hifield
final BigFloat hi

Upper endpoint (NaN for the empty set).

isEmptygetter
bool get isEmpty
isEntiregetter
bool get isEntire
isBoundedgetter
bool get isBounded
isPointgetter
bool get isPoint
bool get containsZero
bool get isPositive

Every point > 0 / < 0.

bool get isNegative
precisiongetter
int get precision
magnitudegetter
BigFloat get magnitude

Upper bound of |x| over the interval.

mignitudegetter
BigFloat get mignitude

Lower bound of |x| over the interval (0 when it contains zero).

hashCodegetter
int get hashCode

Methods

midmethod
BigFloat mid({int? prec})

The midpoint, rounded to nearest (0 for the entire line, \pm\max-ish for half-unbounded intervals).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[1, 2]').mid()}');
}
Output
1.5000000000000000
widthmethod
BigFloat width({int prec = magPrec})

hi − lo rounded up.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.fromInt(2).sqrt().width()}');
}
Output
2.2204460493e-16
containsmethod
bool contains(Rational q)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0.33, 0.34]').contains(Rational.fromInt(1, 3))}');
}
Output
true
bool containsBigFloat(BigFloat x)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[3.14, 3.15]').containsBigFloat(Constants.pi())}');
}
Output
true
bool containsInterval(Interval o)

Whether o is a subset of this interval.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0, 10]').containsInterval(Interval.parse('[2, 3]'))}');
}
Output
true
bool interiorContains(Interval o)

Whether o lies in the interior of this interval.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0, 10]').interiorContains(Interval.parse('[0, 3]'))}, ${Interval.parse('[0, 10]').interiorContains(Interval.parse('[1, 3]'))}');
}
Output
false, true
overlapsmethod
bool overlaps(Interval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0, 1]').overlaps(Interval.parse('[1, 2]'))}');
}
Output
true
bool certainlyLess(Interval o)

Certainly less: every point of this interval is below every point of o.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0, 1]').certainlyLess(Interval.parse('[2, 3]'))}, ${Interval.parse('[0, 2]').certainlyLess(Interval.parse('[1, 3]'))}');
}
Output
true, false
bool certainlyLessOrEqual(Interval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0, 1]').certainlyLessOrEqual(Interval.parse('[1, 3]'))}');
}
Output
true
bool possiblyLess(Interval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0, 2]').possiblyLess(Interval.parse('[1, 3]'))}');
}
Output
true
intersectmethod
Interval intersect(Interval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0, 2]').intersect(Interval.parse('[1, 3]'))}');
}
Output
[1.0000000000000000, 2.0000000000000000]
hullmethod
Interval hull(Interval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0, 1]').hull(Interval.parse('[5, 6]'))}');
}
Output
[0, 6.0000000000000000]
bisectmethod
(Interval, Interval) bisect({int? prec})

Splits at the midpoint (for bisection-based root isolation and branch and bound).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0, 1]').bisect()}');
}
Output
([0, 0.500000000000000000], [0.500000000000000000, 1.00000000000000000])
toBallmethod
Ball toBall({int? prec})

A ball containing this interval.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[1, 2]').toBall()}');
}
Output
[1.50 +/- 0.50]
addmethod
Interval add(Interval o, {int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[1, 2]').add(Interval.parse('[10, 20]'))}');
}
Output
[11.000000000000000, 22.000000000000000]
submethod
Interval sub(Interval o, {int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[1, 2]').sub(Interval.parse('[10, 20]'))}');
}
Output
[-19.000000000000000, -8.0000000000000000]
mulmethod
Interval mul(Interval o, {int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[-1, 2]').mul(Interval.parse('[3, 4]'))}');
}
Output
[-4.0000000000000000, 8.0000000000000000]
divmethod
Interval div(Interval o, {int? prec})

Division; a divisor containing zero gives the entire line (or the empty set for [0, 0]).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[1, 2]').div(Interval.parse('[4, 8]'))}');
}
Output
[0.12500000000000000, 0.50000000000000000]
inversemethod
Interval inverse({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[2, 4]').inverse()}');
}
Output
[0.25000000000000000, 0.50000000000000000]
sqrtmethod
Interval sqrt({int? prec})

Square root of the nonnegative part.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[2, 3]').sqrt()}');
}
Output
[1.4142135623730949, 1.7320508075688775]
squaremethod
Interval square({int? prec})

x² (tighter than x * x: the result is never negative).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('[−2, 1]² = ${Interval.parse('[-2, 1]').square()} vs [−2, 1]·[−2, 1] = ${Interval.parse('[-2, 1]') * Interval.parse('[-2, 1]')}');
}
Output
[−2, 1]² = [0, 4.0000000000000000] vs [−2, 1]·[−2, 1] = [-2.0000000000000000, 4.0000000000000000]
powmethod
Interval pow(int n, {int? prec})

x^n for an integer n, respecting monotonicity (even powers of an interval containing 0 start at 0).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[-2, 1]').pow(3)}');
}
Output
[-8.0000000000000000, 1.0000000000000000]
absmethod
Interval abs()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[-3, 1]').abs()}');
}
Output
[0, 3.0000000000000000]
ldexpmethod
Interval ldexp(int k)

this · 2^k, exact.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[1, 3]').ldexp(-1)}');
}
Output
[0.50000000000000000, 1.5000000000000000]
toStringmethod
String toString()

"[1.4142135623730949, 1.4142135623730952]": the decimal endpoints are rounded outward too.

Operators

operator +operator
Interval operator +(Interval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[0.1, 0.1]') + Interval.parse('[0.2, 0.2]')}');
}
Output
[0.29999999999999993, 0.30000000000000005]
operator -operator
Interval operator -(Interval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[1, 2]') - Interval.parse('[1, 2]')}');
}
Output
[-1.0000000000000000, 1.0000000000000000]
operator *operator
Interval operator *(Interval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[1, 2]') * Interval.parse('[-1, 1]')}');
}
Output
[-2.0000000000000000, 2.0000000000000000]
operator /operator
Interval operator /(Interval o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Interval.parse('[1, 2]') / Interval.parse('[3, 4]')}');
}
Output
[0.25000000000000000, 0.66666666666666675]
operator -operator
Interval operator -()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${-Interval.parse('[1, 2]')}');
}
Output
[-2.0000000000000000, -1.0000000000000000]
operator ==operator
bool operator ==(Object other)

Same endpoints (precision ignored).

final class Rational implements Comparable<Rational>

An exact rational numerator / denominator, always in lowest terms with a positive denominator.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final a = Rational.fromInt(1, 3), b = Rational.fromInt(1, 6);
  print('1/3 + 1/6 = ${a + b}');
  print('1/3 × 3/4 = ${a * Rational.fromInt(3, 4)}');
  print('(2/3)^10 = ${Rational.fromInt(2, 3).pow(10)}');
  print('0.1 as a double is exactly ${Rational.fromDouble(0.1)}');
}
Output
1/3 + 1/6 = 1/2
1/3 × 3/4 = 1/4
(2/3)^10 = 1024/59049
0.1 as a double is exactly 3602879701896397/36028797018963968

Constructors

Rationalfactory
factory Rational(BigInt n, [BigInt? d])

n / d, reduced. Throws on a zero denominator.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational(BigInt.from(6), BigInt.from(-8))} (normalised)');
}
Output
-3/4 (normalised)
factory Rational.fromInt(int n, [int d = 1])
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(10, 4)}');
}
Output
5/2
factory Rational.fromDouble(double x)

The exact value of a finite double.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('0.1 as a double is exactly ${Rational.fromDouble(0.1)}');
}
Output
0.1 as a double is exactly 3602879701896397/36028797018963968
factory Rational.parse(String s)

Parses "-3/4", "17", "1.25", "6.02e23" exactly.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final r = Rational.parse('22/7');
  print('$r = ${r.toDouble()}');
  print('floor ${r.floor()}, ceil ${r.ceil()}, round ${r.round()}');
  print('LaTeX: ${Rational.fromInt(-3, 8).toLatex()}');
}
Output
22/7 = 3.142857142857143
floor 3, ceil 4, round 3
LaTeX: -\frac{3}{8}

Static

zerostaticfield
static final Rational zero
onestaticfield
static final Rational one

Properties

final BigInt numerator
final BigInt denominator
isZerogetter
bool get isZero
isIntegergetter
bool get isInteger
bool get isNegative
signgetter
int get sign
Rational get reciprocal
hashCodegetter
int get hashCode

Methods

absmethod
Rational abs()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(-3, 7).abs()}');
}
Output
3/7
powmethod
Rational pow(int k)

this^k for any integer k (k < 0 inverts).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('(2/3)^5 = ${Rational.fromInt(2, 3).pow(5)}, (2/3)^-2 = ${Rational.fromInt(2, 3).pow(-2)}');
}
Output
(2/3)^5 = 32/243, (2/3)^-2 = 9/4
floormethod
BigInt floor()

Largest integer ≤ this.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(-7, 2).floor()}');
}
Output
-4
ceilmethod
BigInt ceil()

Smallest integer ≥ this.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(-7, 2).ceil()}');
}
Output
-3
roundmethod
BigInt round()

Nearest integer, ties to even.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(5, 2).round()}, ${Rational.fromInt(-5, 2).round()} (ties away from zero)');
}
Output
2, -2 (ties away from zero)
toDoublemethod
double toDouble([RoundingMode rnd = RoundingMode.nearestEven])

The double nearest to this value (correctly rounded, subnormals included, \pm\infty on overflow).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(1, 3).toDouble()}, rounded down ${Rational.fromInt(1, 3).toDouble(RoundingMode.down)}');
}
Output
0.3333333333333333, rounded down 0.3333333333333333
compareTomethod
int compareTo(Rational o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(1, 3).compareTo(Rational.fromInt(333, 1000))}');
}
Output
1
toStringmethod
String toString()
toLatexmethod
String toLatex()

LaTeX: \frac{3}{4}, -\frac{1}{2}, 5.

Example
import 'package:riptide_precision/riptide_precision.ray';
import 'raya:convert';

void main() {
  for (final r in [Rational.fromInt(-22, 7), Rational.fromInt(5), Rational.fromInt(1, 1000)]) {
    print(r.toLatex());
  }
}
Output
-\frac{22}{7}
5
\frac{1}{1000}

Operators

operator +operator
Rational operator +(Rational o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('1/10 + 2/10 = ${Rational.fromInt(1, 10) + Rational.fromInt(2, 10)}; doubles: ${0.1 + 0.2}');
}
Output
1/10 + 2/10 = 3/10; doubles: 0.30000000000000004
operator -operator
Rational operator -(Rational o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(1, 2) - Rational.fromInt(1, 3)}');
}
Output
1/6
operator -operator
Rational operator -()
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${-Rational.fromInt(1, 2)}');
}
Output
-1/2
operator *operator
Rational operator *(Rational o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(2, 3) * Rational.fromInt(9, 4)}');
}
Output
3/2
operator /operator
Rational operator /(Rational o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(2, 3) / Rational.fromInt(4, 9)}');
}
Output
3/2
operator <operator
bool operator <(Rational o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(1, 3) < Rational.fromInt(1, 2)}');
}
Output
true
operator <=operator
bool operator <=(Rational o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(2, 4) <= Rational.fromInt(1, 2)}');
}
Output
true
operator >operator
bool operator >(Rational o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(355, 113) > Rational.fromInt(22, 7)}');
}
Output
false
operator >=operator
bool operator >=(Rational o)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('${Rational.fromInt(1, 3) >= Rational.fromInt(1, 3)}');
}
Output
true
operator ==operator
bool operator ==(Object other)
enum RoundingMode

IEEE 754 / MPFR rounding modes.

Values

nearestEven

Round to nearest, ties to even (MPFR RNDN, IEEE default).

towardZero

Toward zero (truncate; MPFR RNDZ).

upvalue
up

Toward +\infty (MPFR RNDU).

downvalue
down

Toward -\infty (MPFR RNDD).

awayFromZero

Away from zero (MPFR RNDA).

class

Special

abstract final class Special

Special functions to arbitrary precision for real and complex arguments, after mpmath (BSD; algorithms ported, marked in the sources). Each takes BigComplex arguments (use BigComplex.real(x) for real ones; real arguments give results with an exactly zero imaginary part wherever the function is real) and a target precision in bits. Results are not correctly rounded: they are computed with guard bits and tested against mpmath to the bounds in the README.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // Special functions over the complex numbers at any precision.
  print('Γ(1/2)² = π: ${Special.gamma(BigComplex.fromDoubles(0.5, 0, 120), prec: 120).square()}');
}
Output
Γ(1/2)² = π: 3.1415926535897932384626433832795028847

Static

gammastaticmethod
static BigComplex gamma(BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Γ(1/2) = ${Special.gamma(BigComplex.fromDoubles(0.5, 0, 120), prec: 120)}');
  print('Γ(1 + i) = ${Special.gamma(BigComplex.fromInt(1, 1, 80), prec: 80)}');
}
Output
Γ(1/2) = 1.7724538509055160272981674833411451826
Γ(1 + i) = (0.49801566811835604271369109 - 0.15494982830181068512495507i)
rgammastaticmethod
static BigComplex rgamma(BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // 1/Γ is entire: zero at the poles of Γ.
  print('1/Γ(−2) = ${Special.rgamma(BigComplex.fromInt(-2), prec: 60)}, 1/Γ(3) = ${Special.rgamma(BigComplex.fromInt(3), prec: 60)}');
}
Output
1/Γ(−2) = 0.0, 1/Γ(3) = 0.50000000000000000000
loggammastaticmethod
static BigComplex loggamma(BigComplex z, {int prec = 53})

Principal-branch \log \Gamma (mpmath's loggamma).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('log Γ(100) = ${Special.loggamma(BigComplex.fromInt(100, 0, 100), prec: 100)}');
}
Output
log Γ(100) = 359.13420536957539877604401046023
digammastaticmethod
static BigComplex digamma(BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('ψ(1) = −γ = ${Special.digamma(BigComplex.fromInt(1, 0, 100), prec: 100)}');
}
Output
ψ(1) = −γ = -0.57721566490153286060651209008234
polygammastaticmethod
static BigComplex polygamma(int m, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('ψ′(1) = π²/6 = ${Special.polygamma(1, BigComplex.fromInt(1, 0, 100), prec: 100)}');
}
Output
ψ′(1) = π²/6 = 1.6449340668482264364724151666460
betastaticmethod
static BigComplex beta(BigComplex a, BigComplex b, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('B(2, 3) = 1/12 = ${Special.beta(BigComplex.fromInt(2), BigComplex.fromInt(3), prec: 80)}');
}
Output
B(2, 3) = 1/12 = 0.083333333333333333333333368
bernoullistaticmethod
static Rational bernoulli(int n)

Bernoulli number B_{n} (exact).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print([for (var n = 0; n <= 12; n += 2) Special.bernoulli(n)]);
  print('B_30 = ${Special.bernoulli(30)}');
}
Output
[1, 1/6, -1/30, 1/42, -1/30, 5/66, -691/2730]
B_30 = 8615841276005/14322
zetastaticmethod
static BigComplex zeta(BigComplex s, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('ζ(3) = ${Special.zeta(BigComplex.fromInt(3, 0, 120), prec: 120)}');
  print('ζ(1/2 + 14.134725141734693i) ≈ 0: ${Special.zeta(BigComplex.fromDoubles(0.5, 14.134725141734693, 60), prec: 60)}');
}
Output
ζ(3) = 1.2020569031595942853997381615114499914
ζ(1/2 + 14.134725141734693i) ≈ 0: (1.1667488744689433850e-16 - 7.3288818838113143958e-16i)
hurwitzZetastaticmethod
static BigComplex hurwitzZeta(BigComplex s, BigComplex a, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('ζ(2, 1/2) = π²/2 = ${Special.hurwitzZeta(BigComplex.fromInt(2, 0, 100), BigComplex.fromDoubles(0.5, 0, 100), prec: 100)}');
}
Output
ζ(2, 1/2) = π²/2 = 4.9348022005446793094172454999379
polylogstaticmethod
static BigComplex polylog(BigComplex s, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Li₂(1/2) = ${Special.polylog(BigComplex.fromInt(2, 0, 100), BigComplex.fromDoubles(0.5, 0, 100), prec: 100)}');
}
Output
Li₂(1/2) = 0.58224052646501250590265632015979
erfstaticmethod
static BigComplex erf(BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('erf(1) = ${Special.erf(BigComplex.fromInt(1, 0, 120), prec: 120)}');
}
Output
erf(1) = 0.84270079294971486934122063508260925943
erfcstaticmethod
static BigComplex erfc(BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // erfc(10) ≈ 2·10⁻⁴⁵: computed directly, not as 1 − erf(10).
  print('erfc(10) = ${Special.erfc(BigComplex.fromInt(10, 0, 80), prec: 80)}');
}
Output
erfc(10) = 2.0884875837625447570007854e-45
gammaincLowerstaticmethod
static BigComplex gammaincLower(BigComplex s, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('γ(1, 2) = 1 − e⁻² = ${Special.gammaincLower(BigComplex.fromInt(1, 0, 80), BigComplex.fromInt(2, 0, 80), prec: 80)}');
}
Output
γ(1, 2) = 1 − e⁻² = 0.86466471676338730810600037
gammaincUpperstaticmethod
static BigComplex gammaincUpper(BigComplex s, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Γ(1, 2) = e⁻² = ${Special.gammaincUpper(BigComplex.fromInt(1, 0, 80), BigComplex.fromInt(2, 0, 80), prec: 80)}');
}
Output
Γ(1, 2) = e⁻² = 0.13533528323661269189399942
hyp0f1staticmethod
static BigComplex hyp0f1(BigComplex b, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('₀F₁(; 1; 1) = ${Special.hyp0f1(BigComplex.fromInt(1, 0, 80), BigComplex.fromInt(1, 0, 80), prec: 80)}');
}
Output
₀F₁(; 1; 1) = 2.2795853023360672674372043
hyp1f1staticmethod
static BigComplex hyp1f1(BigComplex a, BigComplex b, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('₁F₁(1; 2; 1) = e − 1 = ${Special.hyp1f1(BigComplex.fromInt(1, 0, 80), BigComplex.fromInt(2, 0, 80), BigComplex.fromInt(1, 0, 80), prec: 80)}');
}
Output
₁F₁(1; 2; 1) = e − 1 = 1.7182818284590452353602880
hyp2f1staticmethod
static BigComplex hyp2f1(BigComplex a, BigComplex b, BigComplex c, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // ₂F₁(1, 1; 2; z) = −log(1 − z)/z.
  print('₂F₁(1, 1; 2; 1/2) = 2 ln 2 = ${Special.hyp2f1(BigComplex.fromInt(1, 0, 80), BigComplex.fromInt(1, 0, 80), BigComplex.fromInt(2, 0, 80), BigComplex.fromDoubles(0.5, 0, 80), prec: 80)}');
}
Output
₂F₁(1, 1; 2; 1/2) = 2 ln 2 = 1.3862943611198906188344647
hyperstaticmethod
static BigComplex hyper(List<BigComplex> a, List<BigComplex> b, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final o = BigComplex.fromInt(1, 0, 80);
  print('₃F₂(1,1,1; 2,2; 1/2) = ${Special.hyper([o, o, o], [BigComplex.fromInt(2, 0, 80), BigComplex.fromInt(2, 0, 80)], BigComplex.fromDoubles(0.5, 0, 80), prec: 80)}');
}
Output
₃F₂(1,1,1; 2,2; 1/2) = 1.1644810529300250118053123
besselJstaticmethod
static BigComplex besselJ(BigComplex nu, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('J₀(2.404825557695773) ≈ 0: ${Special.besselJ(BigComplex.fromInt(0), BigComplex.fromDoubles(2.404825557695773, 0, 80), prec: 80)}');
  print('J₁(1) = ${Special.besselJ(BigComplex.fromInt(1), BigComplex.fromInt(1, 0, 80), prec: 80)}');
}
Output
J₀(2.404825557695773) ≈ 0: -6.1087652597367303970819796e-17
J₁(1) = 0.44005058574493351595968204
besselYstaticmethod
static BigComplex besselY(BigComplex nu, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Y₀(1) = ${Special.besselY(BigComplex.fromInt(0), BigComplex.fromInt(1, 0, 80), prec: 80)}');
}
Output
Y₀(1) = 0.088256964215676957982926774
besselIstaticmethod
static BigComplex besselI(BigComplex nu, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('I₀(1) = ${Special.besselI(BigComplex.fromInt(0), BigComplex.fromInt(1, 0, 80), prec: 80)}');
}
Output
I₀(1) = 1.2660658777520083355982447
besselKstaticmethod
static BigComplex besselK(BigComplex nu, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('K₀(1) = ${Special.besselK(BigComplex.fromInt(0), BigComplex.fromInt(1, 0, 80), prec: 80)}');
}
Output
K₀(1) = 0.42102443824070833333562758
airyAistaticmethod
static BigComplex airyAi(BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Ai(0) = ${Special.airyAi(BigComplex.fromInt(0, 0, 80), prec: 80)}');
}
Output
Ai(0) = 0.35502805388781723926006300
airyBistaticmethod
static BigComplex airyBi(BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Bi(0) = ${Special.airyBi(BigComplex.fromInt(0, 0, 80), prec: 80)}');
}
Output
Bi(0) = 0.61492662744600073515092278
legendrePstaticmethod
static BigComplex legendreP(BigComplex nu, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('P₂(1/2) = −1/8 = ${Special.legendreP(BigComplex.fromInt(2), BigComplex.fromDoubles(0.5), prec: 60)}');
}
Output
P₂(1/2) = −1/8 = -0.12500000000000000000
legendrePAssocstaticmethod
static BigComplex legendrePAssoc(BigComplex nu, BigComplex mu, BigComplex z, {int prec = 53})

Ferrers associated Legendre function (mpmath legenp(ν, μ, x, type=2)).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('P₂¹(1/2) = ${Special.legendrePAssoc(BigComplex.fromInt(2), BigComplex.fromInt(1), BigComplex.fromDoubles(0.5), prec: 60)}');
}
Output
P₂¹(1/2) = -1.2990381056766579695
sphericalHarmonicstaticmethod
static BigComplex sphericalHarmonic(int l, int m, BigFloat theta, BigFloat phi, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Y₁⁰(θ = 0) = √(3/4π) = ${Special.sphericalHarmonic(1, 0, BigFloat.zero(), BigFloat.zero(), prec: 60)}');
}
Output
Y₁⁰(θ = 0) = √(3/4π) = 0.48860251190291992176
agmstaticmethod
static BigComplex agm(BigComplex a, BigComplex b, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // agm(1, √2) gives Gauss's constant 1/agm = 0.8346…
  print('agm(1, 2) = ${Special.agm(BigComplex.fromInt(1, 0, 100), BigComplex.fromInt(2, 0, 100), prec: 100)}');
}
Output
agm(1, 2) = 1.4567910310469068691864323832646
ellipKstaticmethod
static BigComplex ellipK(BigComplex m, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('K(1/2) = ${Special.ellipK(BigComplex.fromDoubles(0.5, 0, 100), prec: 100)}');
}
Output
K(1/2) = 1.8540746773013719184338503471947
ellipEstaticmethod
static BigComplex ellipE(BigComplex m, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('E(1/2) = ${Special.ellipE(BigComplex.fromDoubles(0.5, 0, 100), prec: 100)}');
}
Output
E(1/2) = 1.3506438810476755025201747353392
ellipPistaticmethod
static BigComplex ellipPi(BigComplex n, BigComplex m, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Π(1/4, 1/2) = ${Special.ellipPi(BigComplex.fromDoubles(0.25), BigComplex.fromDoubles(0.5), prec: 80)}');
}
Output
Π(1/4, 1/2) = 2.1676193607665559599061578
ellipFstaticmethod
static BigComplex ellipF(BigComplex phi, BigComplex m, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('F(π/4, 1/2) = ${Special.ellipF(BigComplex.fromDoubles(0.7853981633974483), BigComplex.fromDoubles(0.5), prec: 60)}');
}
Output
F(π/4, 1/2) = 0.82601787624924515041
ellipEIncompletestaticmethod
static BigComplex ellipEIncomplete(BigComplex phi, BigComplex m, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('E(π/4, 1/2) = ${Special.ellipEIncomplete(BigComplex.fromDoubles(0.7853981633974483), BigComplex.fromDoubles(0.5), prec: 60)}');
}
Output
E(π/4, 1/2) = 0.74818650417766135053
ellipPiIncompletestaticmethod
static BigComplex ellipPiIncomplete(BigComplex n, BigComplex phi, BigComplex m, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Π(1/4; π/4, 1/2) = ${Special.ellipPiIncomplete(BigComplex.fromDoubles(0.25), BigComplex.fromDoubles(0.7853981633974483), BigComplex.fromDoubles(0.5), prec: 60)}');
}
Output
Π(1/4; π/4, 1/2) = 0.86833172918987304532
carlsonRFstaticmethod
static BigComplex carlsonRF(BigComplex x, BigComplex y, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('R_F(1, 2, 0) = ${Special.carlsonRF(BigComplex.fromInt(1), BigComplex.fromInt(2), BigComplex.fromInt(0), prec: 80)}');
}
Output
R_F(1, 2, 0) = 1.3110287771460599052324203
carlsonRCstaticmethod
static BigComplex carlsonRC(BigComplex x, BigComplex y, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // R_C(0, 1/4) = π.
  print('R_C(0, 1/4) = ${Special.carlsonRC(BigComplex.fromInt(0, 0, 100), BigComplex.fromDoubles(0.25, 0, 100), prec: 100)}');
}
Output
R_C(0, 1/4) = 3.1415926535897932384626433832793
carlsonRDstaticmethod
static BigComplex carlsonRD(BigComplex x, BigComplex y, BigComplex z, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('R_D(0, 2, 1) = ${Special.carlsonRD(BigComplex.fromInt(0), BigComplex.fromInt(2), BigComplex.fromInt(1), prec: 80)}');
}
Output
R_D(0, 2, 1) = 1.7972103521033883111598831
carlsonRJstaticmethod
static BigComplex carlsonRJ(BigComplex x, BigComplex y, BigComplex z, BigComplex p, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('R_J(0, 1, 2, 3) = ${Special.carlsonRJ(BigComplex.fromInt(0), BigComplex.fromInt(1), BigComplex.fromInt(2), BigComplex.fromInt(3), prec: 80)}');
}
Output
R_J(0, 1, 2, 3) = 0.77688623778582332014190311
jthetastaticmethod
static BigComplex jtheta(int n, BigComplex z, BigComplex q, {int prec = 53})

Jacobi theta \theta_{n}(z, q), nome q (|q| < 1).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('θ₃(0, 1/2) = ${Special.jtheta(3, BigComplex.fromInt(0), BigComplex.fromDoubles(0.5), prec: 80)}');
}
Output
θ₃(0, 1/2) = 2.1289368272118771586694577
ellipNomestaticmethod
static BigComplex ellipNome(BigComplex m, {int prec = 53})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('q(1/2) = e^{−π} = ${Special.ellipNome(BigComplex.fromDoubles(0.5, 0, 80), prec: 80)}');
}
Output
q(1/2) = e^{−π} = 0.043213918263772249774417727
ellipfunstaticmethod
static (BigComplex, BigComplex, BigComplex) ellipfun(BigComplex u, BigComplex m, {int prec = 53})

Jacobi elliptic functions (sn, cn, dn)(u \mid m).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final (sn, cn, dn) = Special.ellipfun(BigComplex.fromDoubles(0.5), BigComplex.fromDoubles(0.3), prec: 60);
  print('sn = $sn, cn = $cn, dn = $dn');
}
Output
sn = 0.47421562271182062572, cn = 0.88040873642646243040, dn = 0.96567896474595120004
lambertWstaticmethod
static BigComplex lambertW(BigComplex z, {int k = 0, int prec = 53})

Lambert W on branch k.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  // W(1) = Ω, the omega constant: Ω e^Ω = 1.
  print('W(1) = ${Special.lambertW(BigComplex.fromInt(1, 0, 120), prec: 120)}');
  print('W₋₁(−0.1) = ${Special.lambertW(BigComplex.fromDoubles(-0.1), k: -1, prec: 60)}');
}
Output
W(1) = 0.56714329040978387299996866221035554984
W₋₁(−0.1) = -3.5771520639572971408
extension BigFloatSpecial on BigFloat

Real special functions on BigFloat (NaN where the value isn't real).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Γ(1/3) = ${BigFloat.parse('1', prec: 150).div(BigFloat.fromInt(3, prec: 150), prec: 150).gamma().toStringAsPrecision(40)}');
}
Output
Γ(1/3) = 2.678938534707747633655692940974677644129

Methods

gammamethod
BigFloat gamma({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('Γ(0.5) = ${BigFloat.parse('0.5', prec: 200).gamma().toStringAsPrecision(50)}');
}
Output
Γ(0.5) = 1.7724538509055160272981674833411451827975494561224
lgammamethod
BigFloat lgamma({int? prec})

Log |\Gamma(x)|.

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('ln Γ(1000) = ${BigFloat.fromInt(1000, prec: 120).lgamma().toStringAsPrecision(30)}');
}
Output
ln Γ(1000) = 5905.22042320918121182607691236
digammamethod
BigFloat digamma({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('ψ(1) = ${BigFloat.fromInt(1, prec: 120).digamma().toStringAsPrecision(30)}');
}
Output
ψ(1) = -0.577215664901532860606512090082
erfmethod
BigFloat erf({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('erf(0.5) = ${BigFloat.parse('0.5', prec: 120).erf().toStringAsPrecision(30)}');
}
Output
erf(0.5) = 0.520499877813046537682746653892
erfcmethod
BigFloat erfc({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('erfc(6) = ${BigFloat.fromInt(6, prec: 120).erfc().toStringAsPrecision(30)}');
}
Output
erfc(6) = 2.15197367124989131165933503992e-17
zetamethod
BigFloat zeta({int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('ζ(5) = ${BigFloat.fromInt(5, prec: 150).zeta().toStringAsPrecision(40)}');
}
Output
ζ(5) = 1.036927755143369926331365486457034168057
lambertWmethod
BigFloat lambertW({int k = 0, int? prec})
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  print('W(10) = ${BigFloat.fromInt(10, prec: 150).lambertW().toStringAsPrecision(40)}');
}
Output
W(10) = 1.745528002740699383074301264875389911535
class NoConvergence implements Exception

Thrown where an expansion doesn't converge (outside the implemented region).

Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  final e = NoConvergence('series did not converge after 10000 terms');
  print(e);
}
Output
NoConvergence: series did not converge after 10000 terms

Constructors

NoConvergenceconstructor
NoConvergence(this.message)
Example
import 'package:riptide_precision/riptide_precision.ray';

void main() {
  try {
    throw NoConvergence('demo');
  } on NoConvergence catch (e) {
    print('caught: ${e.message}');
  }
}
Output
caught: demo

Properties

messagefield
final String message

Methods

toStringmethod
String toString()