iyi

Standard library, 0.18.0

std/math

import std/math to use it. Source: src/std/math.iyi at v0.18.0.

Mathstruct

std/mathiyi doc src/std/math.iyi
pub struct Math
  def self.acos(value : Float64) : Float64
  def self.acos(value : Float32) : Float32
  def self.acos(value : T) : Float64 forall T
  # Correctly rounded (CORE-MATH, e_acosh.c): NaN below 1 (and for NaN),
  # acosh(1) = 0, acosh(inf) = inf.
  def self.acosh(value : Float64) : Float64
  def self.acosh(value : Float32) : Float32
  def self.acosh(value : T) : Float64 forall T
  def self.asin(value : Float64) : Float64
  def self.asin(value : Float32) : Float32
  def self.asin(value : T) : Float64 forall T
  # Correctly rounded (CORE-MATH, s_asinh.c): odd, asinh(+-0) = +-0,
  # +-inf and NaN come back as x + x.
  def self.asinh(value : Float64) : Float64
  def self.asinh(value : Float32) : Float32
  def self.asinh(value : T) : Float64 forall T
  def self.atan(value : Float64) : Float64
  def self.atan(value : Float32) : Float32
  def self.atan(value : T) : Float64 forall T
  # The angle of (x, y), with the zeros' and infinities' signs read the
  # way C's atan2 reads them: atan2(0.0, -0.0) is pi, atan2(-0.0, -1.0) is
  # -pi, atan2(inf, inf) is pi/4.
  def self.atan2(y : Float64, x : Float64) : Float64
  def self.atan2(y : Float32, x : Float32) : Float32
  def self.atan2(y : T, x : U) : Float64 forall T, U
  # Correctly rounded (CORE-MATH, e_atanh.c): odd, atanh(+-1) = +-inf, NaN
  # beyond 1 in magnitude (and for NaN).
  def self.atanh(value : Float64) : Float64
  def self.atanh(value : Float32) : Float32
  def self.atanh(value : T) : Float64 forall T
  # The Bessel function of the first kind of the given *order*,
  # Jn(*value*), as glibc computes it.
  def self.besselj(order : Int32, value : Float64) : Float64
  # The Bessel function of the first kind of the given *order*,
  # Jn(*value*), as glibc computes it.
  def self.besselj(order : Int32, value : Float32) : Float32
  # The Bessel function of the first kind of the given *order*,
  # Jn(*value*), as glibc computes it.
  def self.besselj(order : Int32, value : T) : Float64 forall T
  # The Bessel function of the first kind of order 0, J0(*value*), as glibc
  # computes it.
  def self.besselj0(value : Float64) : Float64
  # The Bessel function of the first kind of order 0, J0(*value*), as glibc
  # computes it.
  def self.besselj0(value : Float32) : Float32
  # The Bessel function of the first kind of order 0, J0(*value*), as glibc
  # computes it.
  def self.besselj0(value : T) : Float64 forall T
  # The Bessel function of the first kind of order 1, J1(*value*), as glibc
  # computes it.
  def self.besselj1(value : Float64) : Float64
  # The Bessel function of the first kind of order 1, J1(*value*), as glibc
  # computes it.
  def self.besselj1(value : Float32) : Float32
  # The Bessel function of the first kind of order 1, J1(*value*), as glibc
  # computes it.
  def self.besselj1(value : T) : Float64 forall T
  # The Bessel function of the second kind of the given *order*,
  # Yn(*value*), as glibc computes it: NaN for negative *value*, -infinity
  # at zero (+infinity for odd negative *order*).
  def self.bessely(order : Int32, value : Float64) : Float64
  # The Bessel function of the second kind of the given *order*,
  # Yn(*value*), as glibc computes it: NaN for negative *value*, -infinity
  # at zero (+infinity for odd negative *order*).
  def self.bessely(order : Int32, value : Float32) : Float32
  # The Bessel function of the second kind of the given *order*,
  # Yn(*value*), as glibc computes it: NaN for negative *value*, -infinity
  # at zero (+infinity for odd negative *order*).
  def self.bessely(order : Int32, value : T) : Float64 forall T
  # The Bessel function of the second kind of order 0, Y0(*value*), as glibc
  # computes it: NaN for negative *value*, -infinity at zero.
  def self.bessely0(value : Float64) : Float64
  # The Bessel function of the second kind of order 0, Y0(*value*), as glibc
  # computes it: NaN for negative *value*, -infinity at zero.
  def self.bessely0(value : Float32) : Float32
  # The Bessel function of the second kind of order 0, Y0(*value*), as glibc
  # computes it: NaN for negative *value*, -infinity at zero.
  def self.bessely0(value : T) : Float64 forall T
  # The Bessel function of the second kind of order 1, Y1(*value*), as glibc
  # computes it: NaN for negative *value*, -infinity at zero.
  def self.bessely1(value : Float64) : Float64
  # The Bessel function of the second kind of order 1, Y1(*value*), as glibc
  # computes it: NaN for negative *value*, -infinity at zero.
  def self.bessely1(value : Float32) : Float32
  # The Bessel function of the second kind of order 1, Y1(*value*), as glibc
  # computes it: NaN for negative *value*, -infinity at zero.
  def self.bessely1(value : T) : Float64 forall T
  def self.cbrt(value : Float64) : Float64
  def self.cbrt(value : Float32) : Float32
  def self.cbrt(value : T) : Float64 forall T
  def self.copysign(mag : Float64, sgn : Float64) : Float64
  def self.copysign(mag : Float32, sgn : Float32) : Float32
  def self.cos(value : Float64) : Float64
  def self.cos(value : Float32) : Float32
  def self.cos(value : T) : Float64 forall T
  def self.cosh(value : Float64) : Float64
  def self.cosh(value : Float32) : Float32
  def self.cosh(value : T) : Float64 forall T
  # The error function, correctly rounded: glibc 2.43's CORE-MATH erf
  # (s_erf.c). NaN answers NaN, ±inf answer ±1, and ±0 keep their sign.
  def self.erf(value : Float64) : Float64
  # The single's: the double's answer rounded, which is the correctly
  # rounded single but where rounding twice meets a halfway point.
  def self.erf(value : Float32) : Float32
  def self.erf(value : T) : Float64 forall T
  # 1 - erf(value), correctly rounded: glibc 2.43's CORE-MATH erfc
  # (s_erfc.c). NaN answers NaN, -inf 2 and +inf 0; the answer underflows
  # to 0 from 0x1.b39dc41e48bfdp+4 (about 27.23) up.
  def self.erfc(value : Float64) : Float64
  # The single's: the double's answer rounded, which is the correctly
  # rounded single but where rounding twice meets a halfway point.
  def self.erfc(value : Float32) : Float32
  def self.erfc(value : T) : Float64 forall T
  def self.exp(value : Float64) : Float64
  def self.exp(value : Float32) : Float32
  def self.exp(value : T) : Float64 forall T
  def self.exp2(value : Float64) : Float64
  def self.exp2(value : Float32) : Float32
  def self.exp2(value : T) : Float64 forall T
  def self.expm1(value : Float64) : Float64
  def self.expm1(value : Float32) : Float32
  def self.expm1(value : T) : Float64 forall T
  # a * b + c rounded once, as IEEE 754 defines it and as the other
  # library's `Math.fma` answers through libm. The instruction where the
  # processor has one: every aarch64 processor (`fmadd`, LLVM's intrinsic),
  # and an x86_64 one with FMA3 and an operating system that saves its
  # registers, asked once by `cpuid` and `xgetbv` as `Float64#floor` asks
  # for `roundsd`. Elsewhere musl's `fma` (MIT; Copyright 2005-2020 Rich
  # Felker, et al.), in iyi: the significands as integers, their product's
  # 128 bits exact, the sum aligned with a sticky bit, one rounding at the
  # conversion back. This was Dekker's product and two more additions,
  # which round each, and answered the neighbour of the fused result for
  # arguments that cancel.
  def self.fma(a : Float64, b : Float64, c : Float64) : Float64
  # The single's: the instruction where there is one, and otherwise
  # musl's `fmaf` - the product of two singles is exact in a double and
  # the sum rounds once there, which is right unless that double sits on
  # a single's halfway point or among the subnormals; then the sum's
  # rounding error, which is exact, sends it to the odd neighbour, which
  # the conversion to a single cannot then misround.
  def self.fma(a : Float32, b : Float32, c : Float32) : Float32
  def self.fma(a : T, b : U, c : V) : Float64 forall T, U, V
  # value as m * 2^e with m in [0.5, 1) (or 0, NaN or an infinity as it
  # came, with 0), read from the bits: a subnormal is first scaled up by
  # 2^54 so that it has an exponent field of its own.
  def self.frexp(value : Float64) : ::Tuple(Float64, Int32)
  def self.gamma(value : Float64) : Float64
  # The single's: the double's answer rounded, which is the correctly
  # rounded single but where rounding twice meets a halfway point.
  def self.gamma(value : Float32) : Float32
  def self.gamma(value : T) : Float64 forall T
  # Euclid on the side of zero where every magnitude fits: the non-positive
  # side for a signed type, its minimum included - gcd(-2147483648, 6) is 2
  # - and the non-negative side, the only one there is, for an unsigned
  # type. Only gcd(minimum, 0), whose answer does not fit, overflows. The
  # two arguments are one type, as `%` takes one: the signature took any
  # two integers, and an unsigned pair (it has no unary minus) or a pair of
  # widths (no `%` between them) failed to compile inside this method. A
  # pair of widths is refused at the call now, and a literal takes the
  # other argument's type.
  def self.gcd(a : T, b : T) : T forall T
  def self.hypot(x : Float64, y : Float64) : Float64
  def self.hypot(x : Float32, y : Float32) : Float32
  def self.hypot(x : T, y : U) : Float64 forall T, U
  # The exponent of value as an integer, as C's ilogb and glibc answer it:
  # a subnormal's true exponent, -2147483648 for zero and NaN, 2147483647
  # for an infinity.
  def self.ilogb(value : Float64) : Int32
  def self.ilogb(value : Float32) : Int32
  def self.ilogb(value : T) : Int32 forall T
  def initialize
  # The largest r with r * r <= value, in the value's own type, by the
  # other library's bit-at-a-time method. A negative value panics, where
  # that library raises.
  def self.isqrt(value : ::Int) : ::Int
  def self.lcm(a : T, b : T) : T forall T
  # value * 2^exponent, with one rounding: the exponent field is rewritten
  # outright, and a result that lands among the subnormals is scaled down
  # from a normal one in a single step.
  def self.ldexp(value : Float64, exponent : Int32) : Float64
  # log|gamma(value)|, correctly rounded (CORE-MATH, as glibc 2.43): the
  # poles at the non-positive whole numbers and both infinities answer
  # +infinity, NaN answers NaN.
  def self.lgamma(value : Float64) : Float64
  # The single's: the double's answer rounded, which is the correctly
  # rounded single but where rounding twice meets a halfway point.
  def self.lgamma(value : Float32) : Float32
  def self.lgamma(value : T) : Float64 forall T
  def self.log(value : Float64, base : Float64) : Float64
  def self.log(value : T, base : U) : Float64 forall T, U
  def self.log(value : Float64) : Float64
  def self.log(value : Float32) : Float32
  def self.log(value : T) : Float64 forall T
  def self.log10(value : Float64) : Float64
  def self.log10(value : Float32) : Float32
  def self.log10(value : T) : Float64 forall T
  def self.log1p(value : Float64) : Float64
  def self.log1p(value : Float32) : Float32
  def self.log1p(value : T) : Float64 forall T
  def self.log2(value : Float64) : Float64
  def self.log2(value : Float32) : Float32
  def self.log2(value : T) : Float64 forall T
  # The exponent of value as a double: -inf for zero, +inf for an
  # infinity, NaN for NaN, as C's logb.
  def self.logb(value : Float64) : Float64
  def self.logb(value : Float32) : Float32
  def self.logb(value : T) : Float64 forall T
  # The larger, with the number when one side is NaN, and 0.0 over -0.0.
  def self.max(a : Float64, b : Float64) : Float64
  def self.max(a : Float32, b : Float32) : Float32
  # The smaller, with the number when one side is NaN, and -0.0 over 0.0.
  def self.min(a : Float64, b : Float64) : Float64
  def self.min(a : Float32, b : Float32) : Float32
  def self.pow(base : Float64, exp : Float64) : Float64
  def self.pow(base : Float32, exp : Float32) : Float32
  def self.pow(base : T, exp : U) : Float64 forall T, U
  # The least power of two not below v, 1 for v <= 1, in v's type; one
  # the type cannot hold panics "arithmetic overflow".
  def self.pw2ceil(v : ::Int) : ::Int
  # scalbn with an Int64 exponent: past the range an Int32 holds every
  # answer is zero or an infinity already, so the exponent is clamped.
  def self.scalbln(value : Float64, exp : Int64) : Float64
  def self.scalbln(value : Float32, exp : Int64) : Float32
  def self.scalbln(value : T, exp : U) : Float64 forall T, U
  # value * 2^exp, rounded once: `ldexp` under C's other name.
  def self.scalbn(value : Float64, exp : Int32) : Float64
  def self.scalbn(value : Float32, exp : Int32) : Float32
  def self.scalbn(value : T, exp : U) : Float64 forall T, U
  def self.sin(value : Float64) : Float64
  def self.sin(value : Float32) : Float32
  def self.sin(value : T) : Float64 forall T
  # sinh, cosh and tanh as glibc 2.43 computes them - fdlibm's
  # `e_sinh.c`, `e_cosh.c` and `s_tanh.c` (Sun's notice is at `expm1`), on
  # the `exp` and `expm1` above, which are glibc's to the last bit, so
  # these are too. Their branches are fdlibm's, at its thresholds, read off
  # the high word: a series near zero and `half_exp` past 709 answered
  # differently in the last bit for 952 arguments of sinh in 100,000, 217
  # of cosh and 4,863 of tanh.
  def self.sinh(value : Float64) : Float64
  def self.sinh(value : Float32) : Float32
  def self.sinh(value : T) : Float64 forall T
  def self.sqrt(value : Float64) : Float64
  def self.sqrt(value : Float32) : Float32
  def self.sqrt(value : T) : Float64 forall T
  def self.tan(value : Float64) : Float64
  def self.tan(value : Float32) : Float32
  def self.tan(value : T) : Float64 forall T
  def self.tanh(value : Float64) : Float64
  def self.tanh(value : Float32) : Float32
  def self.tanh(value : T) : Float64 forall T
  # gamma(value), correctly rounded (CORE-MATH, as glibc 2.43): +-0 answer
  # +-infinity, the negative whole numbers and -infinity NaN; past
  # 171.62 the answer overflows to infinity, and below -184 it is a zero
  # carrying gamma's sign.
  def self.tgamma(value : Float64) : Float64
  # The single's: the double's answer rounded, which is the correctly
  # rounded single but where rounding twice meets a halfway point.
  def self.tgamma(value : Float32) : Float32
  def self.tgamma(value : T) : Float64 forall T
end