High-precision Math library Implemented By Pure Moonbit
moon updatemoon add Kaida-Amethyst/math{
"import" :[
"Kaida-Amethyst/math"
]
}fn main {
let angle = 1.0 // in radians
let result = @math.sin(angle)
println("The sine of \{angle} is \{result}")
}{
"import" :[
{
"path": "Kaida-Amethyst/math",
"alias" : "kmath"
}
]
}fn main {
let angle = 1.0
let result1 = @kmath.sin(angle) // use Moonbit-Math's sin function
let result2 = @math.sin(angle) // use Core-Math's sin function
println("Moonbit-Math: The sine of \{angle} is \{result1}")
println("Core: The sine of \{angle} is \{result2}")
}| Function Name | Description |
|---|---|
| acos | Inverse cosine function. |
| asin | Inverse sine function. |
| atan | Inverse tangent function. |
| atan2 | Computes the arctangent of y/x, with the result in radians. |
| cos | Cosine function. |
| cospi | Computes the cosine of x * pi. |
| sin | Sine function. |
| sinc | Normalized sinc function, defined as sin(πx)/(πx). |
| sincos | Simultaneously computes the sine and cosine values. |
| sincospi | Simultaneously computes the sine and cosine of x * pi. |
| sinpi | Computes the sine of x * pi. |
| tan | Tangent function. |
| Function Name | Description |
|---|---|
| acosh | Inverse hyperbolic cosine. |
| asinh | Inverse hyperbolic sine. |
| atanh | Inverse hyperbolic tangent. |
| cosh | Hyperbolic cosine. |
| sinh | Hyperbolic sine. |
| tanh | Hyperbolic tangent. |
| Function Name | Description |
|---|---|
| exp | Exponential function, computes e raised to the power of x. |
| exp10 | Base-10 exponential function. |
| exp2 | Base-2 exponential function. |
| expm1 | Computes exp(x) - 1, offering better precision for small values. |
| expx2 | Computes x * 2n. |
| ilogb | Returns the integer base-2 exponent of x. |
| inv_digamma | Inverse of the digamma function. |
| lgamma | Natural logarithm of the absolute value of the Gamma function. |
| ln | Natural logarithm function (base e). |
| ln_1p | Equivalent to log1p. |
| ln_gamma | Equivalent to lgamma. |
| log | Natural logarithm function (base e). |
| log10 | Base-10 logarithm function. |
| log1p | Computes the natural logarithm of 1 + x, for better precision with small values. |
| log1pf | Computes log1p for Float type. |
| log2 | Base-2 logarithm function. |
| log_ndtr | Logarithm of the standard normal cumulative distribution function. |
| logaddexp | Computes log(exp(x) + exp(y)) avoiding overflow. |
| logf | Computes the natural logarithm for Float type. |
| logsumexp | Computes the logarithm of the sum of exponentials of an array. |
| ndtr | Standard normal cumulative distribution function. |
| ndtri | Inverse of the standard normal cumulative distribution function. |
| pow | Computes x raised to the power of y. |
| powi | Computes the base as Double raised to the power of an Int exponent. |
| pown | Computes the base as Double raised to the power of an Int exponent. |
| rsqrt | Computes 1 / sqrt(x). |
| sqrt | Square root function. |
| sqrt1pm1 | Computes sqrt(1 + x) - 1, for better precision with small values. |
| zeta | Zeta function. |
| Function Name | Description | ||
|---|---|---|---|
| airy_ai | Airy function Ai. | ||
| bessel_i0 | Modified Bessel function of the first kind of order zero, I₀(x). | ||
| bessel_i0e | Scaled modified Bessel function of the first kind of order zero, exp(- | x | ) * I₀(x). |
| bessel_i1 | Modified Bessel function of the first kind of order one, I₁(x). | ||
| bessel_i1e | Scaled modified Bessel function of the first kind of order one, exp(- | x | ) * I₁(x). |
| bessel_k0 | Modified Bessel function of the second kind of order zero, K₀(x). | ||
| bessel_k0e | Scaled modified Bessel function of the second kind of order zero, exp(-x) * K₀(x). | ||
| bessel_k1 | Modified Bessel function of the second kind of order one, K₁(x). | ||
| bessel_k1e | Scaled modified Bessel function of the second kind of order one, exp(-x) * K₁(x). | ||
| bessel_j0 | Bessel function of the first kind of order zero, J₀(x). | ||
| bessel_j1 | Bessel function of the first kind of order one, J₁(x). | ||
| bessel_jn | Bessel function of the first kind of order n, Jn(x). | ||
| bessel_y0 | Bessel function of the second kind of order zero, Y₀(x), also known as Neumann function N₀(x) or Weber function. | ||
| bessel_y1 | Bessel function of the second kind of order one, Y₁(x), also known as Neumann function N₁(x) or Weber function. | ||
| bessel_yn | Bessel function of the second kind of order n, Yn(x), also known as Neumann function Nn(x). | ||
| i0 | Equivalent to bessel_i0. | ||
| i0e | Equivalent to bessel_i0e. | ||
| i1 | Equivalent to bessel_i1. | ||
| i1e | Equivalent to bessel_i1e. | ||
| j0 | Equivalent to bessel_j0. | ||
| j1 | Equivalent to bessel_j1. | ||
| jn | Equivalent to bessel_jn. | ||
| k0 | Equivalent to bessel_k0. | ||
| k0e | Equivalent to bessel_k0e. | ||
| k1 | Equivalent to bessel_k1. | ||
| k1e | Equivalent to bessel_k1e. | ||
| y0 | Equivalent to bessel_y0. | ||
| y1 | Equivalent to bessel_y1. | ||
| yn | Equivalent to bessel_yn. | ||
| erf | Error function. | ||
| erfc | Complementary error function. | ||
| erfce | Scaled complementary error function, exp(x²) * erfc(x). | ||
| erfcinv | Inverse of the complementary error function. | ||
| erfcx | Scaled complementary error function, exp(x²) * erfc(x). | ||
| erfinv | Inverse error function. | ||
| gamma | Gamma function. | ||
| gdtr | Gamma distribution function. | ||
| gdtrc | Complement of the gamma distribution function. | ||
| polygamma | Polygamma function ψ(n)(x). | ||
| trigamma | Trigamma function, the second polygamma function. | ||
| digamma | Digamma function, the first polygamma function. | ||
| gegenbauer | Gegenbauer polynomial C(α)<sub>n(x). | ||
| gegenbauer_derivative | Derivative of the Gegenbauer polynomial. | ||
| gegenbauer_prime | Derivative of the Gegenbauer polynomial. | ||
| hermite | Hermite polynomial Hn(x). |
| Function Name | Description |
|---|---|
| cbrt | Cube root function. |
| ceil | Ceiling function, rounds up to the nearest integer. |
| clamp | Clamps a value within a specified range. |
| div_euclid | Computes the result of Euclidean division. |
| entr | Computes the binary entropy -p * log2(p). |
| fdim | Computes max(x - y, 0). |
| floor | Floor function, rounds down to the nearest integer. |
| gelu | Gaussian Error Linear Unit activation function. |
| hypot | Computes sqrt(x² + y²). |
| isinf | Checks if a floating-point number is infinite. |
| isnan | Checks if a floating-point number is NaN (Not a Number). |
| isninf | Checks if a floating-point number is negative infinity. |
| isnormal | Checks if a floating-point number is normal (neither zero, subnormal, infinite, nor NaN). |
| ispinf | Checks if a floating-point number is positive infinity. |
| issubnormal | Checks if a floating-point number is subnormal. |
| ldexp | Computes x * 2exp. |
| lerp | Performs linear interpolation between two values. |
| norm | Computes the Euclidean norm (L2 norm) of an array. |
| norm3d | Computes the Euclidean norm of a 3D vector. |
| norm4d | Computes the Euclidean norm of a 4D vector. |
| normcdf | Standard normal cumulative distribution function. |
| normcdfinv | Inverse of the standard normal cumulative distribution function. |
| rcbrt | Computes 1 / cbrt(x). |
| rem_euclid | Computes the remainder of Euclidean division. |
| rhypot | Computes 1 / sqrt(x² + y²). |
| rint | Rounds to the nearest integer. |
| rnorm | Computes the reciprocal of the Euclidean norm of an array. |
| round | Rounds to the nearest integer, away from zero. |
| roundeven | Rounds to the nearest even integer. |
| scalbn | Computes x * 2n. |
| signum | Returns the sign of a number: -1, 0, or 1. |
| to_degrees | Converts radians to degrees. |
| to_radians | Converts degrees to radians. |
| trunc | Truncates towards zero. |
| Function Name | Max ULP |
|---|---|
| log | 0 |
| log2 | 1 |
| log10 | 0 |
| log1p | 0 |
| pow | 2 |
| exp | 1 |
| exp2 | 1 |
| exp10 | 1 |
| expm1 | 0 |
| cbrt | 0 |
| atan | 1 |
| atan2 | 1 |
| asin | 1 |
| acos | 1 |
| acosh | 0 |
| asinh | 0 |
| atanh | 0 |
| cosh | 0 |
| sinh | 0 |
| tanh | 0 |
| cos | 0 |
| sin | 0 |
| tan | 0 |
| cospi | 49 |
| sinpi | 3 |
| sqrt | 0 |
| hypot | 1 |
| erf | 1 |
| erfc | 1 |
| j0 | 2 |
| y0 | 2 |
| j1 | 4 |
| y1 | 2 |
| erfinv | 2 |
| gamma | 4 |
| lgamma | 23 |
| trigamma | 14 |
| digamma | 1023 |
| zeta | 3 |
moon updatemoon add Kaida-Amethyst/math{
"import" :[
"Kaida-Amethyst/math"
]
}fn main {
let angle = 1.0 // 以弧度为单位
let result = @math.sin(angle)
println("The sine of \{angle} is \{result}")
}{
"import" :[
{
"path": "Kaida-Amethyst/math",
"alias" : "kmath"
}
]
}fn main {
let angle = 1.0
let result1 = @kmath.sin(angle) // 使用 Moonbit-Math 的 sin 函数
let result2 = @math.sin(angle) // 使用 Core-Math 的 sin 函数
println("Moonbit-Math: The sine of \{angle} is \{result1}")
println("Core: The sine of \{angle} is \{result2}")
}| 函数名 | 描述 |
|---|---|
| acos | 反余弦函数。 |
| asin | 反正弦函数。 |
| atan | 反正切函数。 |
| atan2 | 计算给定的 y/x 的反正切(结果以弧度表示)。 |
| cos | 余弦函数。 |
| cospi | 计算 x * pi 的余弦。 |
| sin | 正弦函数。 |
| sinc | 归一化 sinc 函数,定义为 sin(πx)/(πx)。 |
| sincos | 同时计算正弦和余弦值。 |
| sincospi | 同时计算 x * pi 的正弦和余弦值。 |
| sinpi | 计算 x * pi 的正弦。 |
| tan | 正切函数。 |
| 函数名 | 描述 |
|---|---|
| acosh | 反双曲余弦函数。 |
| asinh | 反双曲正弦函数。 |
| atanh | 反双曲正切函数。 |
| cosh | 双曲余弦函数。 |
| sinh | 双曲正弦函数。 |
| tanh | 双曲正切函数。 |
| 函数名 | 描述 |
|---|---|
| exp | 指数函数,计算 e 的 x 次方。 |
| exp10 | 以 10 为底的指数函数。 |
| exp2 | 以 2 为底的指数函数。 |
| expm1 | 计算 exp(x) - 1,用于提高小数值的精度。 |
| expx2 | 计算 x * 2n。 |
| ilogb | 返回 x 的以 2 为底的指数部分的整数值。 |
| inv_digamma | digamma 函数的反函数。 |
| lgamma | 伽马函数的绝对值的自然对数。 |
| ln | 自然对数函数(以 e 为底)。 |
| ln_1p | 等同于 log1p。 |
| ln_gamma | 等同于 lgamma。 |
| log | 自然对数函数(以 e 为底)。 |
| log10 | 以 10 为底的对数函数。 |
| log1p | 计算 1 + x 的自然对数,用于提高小数值的精度。 |
| log1pf | 计算 Float 类型的 log1p。 |
| log2 | 以 2 为底的对数函数。 |
| log_ndtr | 标准正态分布累积分布函数对数值。 |
| logaddexp | 计算 log(exp(x) + exp(y)),避免溢出。 |
| logf | 计算 Float 类型的自然对数。 |
| logsumexp | 计算数组中所有值的指数和的对数。 |
| ndtr | 标准正态分布累积分布函数。 |
| ndtri | 标准正态分布累积分布函数的反函数。 |
| pow | 计算 x 的 y 次方。 |
| powi | 计算底数为 Double 类型,指数为 Int 类型的幂。 |
| pown | 计算底数为 Double 类型,指数为 Int 类型的幂。 |
| rsqrt | 计算 1 / sqrt(x)。 |
| sqrt | 平方根函数。 |
| sqrt1pm1 | 计算 sqrt(1 + x) - 1,用于提高小数值的精度。 |
| zeta | Zeta 函数。 |
| 函数名 | 描述 | ||
|---|---|---|---|
| airy_ai | Airy 函数 Ai。 | ||
| bessel_i0 | 第一类修正贝塞尔函数 I₀(x)。 | ||
| bessel_i0e | 比例化的第一类修正贝塞尔函数 exp(- | x | ) * I₀(x)。 |
| bessel_i1 | 第一类修正贝塞尔函数 I₁(x)。 | ||
| bessel_i1e | 比例化的第一类修正贝塞尔函数 exp(- | x | ) * I₁(x)。 |
| bessel_k0 | 第二类修正贝塞尔函数 K₀(x)。 | ||
| bessel_k0e | 比例化的第二类修正贝塞尔函数 exp(-x) * K₀(x)。 | ||
| bessel_k1 | 第二类修正贝塞尔函数 K₁(x)。 | ||
| bessel_k1e | 比例化的第二类修正贝塞尔函数 exp(-x) * K₁(x)。 | ||
| bessel_j0 | 第一类贝塞尔函数 J₀(x)。 | ||
| bessel_j1 | 第一类贝塞尔函数 J₁(x)。 | ||
| bessel_jn | 第一类贝塞尔函数 Jn(x)。 | ||
| bessel_y0 | 第一类贝塞尔函数 y₀(x)。 | ||
| bessel_y1 | 第一类贝塞尔函数 y₁(x)。 | ||
| bessel_yn | 第一类贝塞尔函数 yn(x)。 | ||
| i0 | 等同于 bessel_i0。 | ||
| i0e | 等同于 bessel_i0e。 | ||
| i1 | 等同于 bessel_i1。 | ||
| i1e | 等同于 bessel_i1e。 | ||
| j0 | 等同于 bessel_j0。 | ||
| j1 | 等同于 bessel_j1。 | ||
| jn | 等同于 bessel_jn。 | ||
| y0 | 等同于 bessel_y0。 | ||
| y1 | 等同于 bessel_y1。 | ||
| yn | 等同于 bessel_yn。 | ||
| k0 | 等同于 bessel_k0。 | ||
| k0e | 等同于 bessel_k0e。 | ||
| k1 | 等同于 bessel_k1。 | ||
| k1e | 等同于 bessel_k1e。 | ||
| y0 | 第二类贝塞尔函数 Y₀(x)。也称为 Neumann 函数 N₀(x) 或 Weber 函数。 | ||
| y1 | 第二类贝塞尔函数 Y₁(x)。也称为 Neumann 函数 N₁(x) 或 Weber 函数。 | ||
| yn | 第二类贝塞尔函数 Yn(x)。也称为 Neumann 函数 Nn(x)。 | ||
| erf | 误差函数。 | ||
| erfc | 互补误差函数。 | ||
| erfce | 比例化的互补误差函数 exp(x²) * erfc(x)。 | ||
| erfcinv | 互补误差函数的反函数。 | ||
| erfcx | 比例化的互补误差函数 exp(x²) * erfc(x)。 | ||
| erfinv | 误差函数的反函数。 | ||
| gamma | 伽马函数。 | ||
| gdtr | 伽马分布函数。 | ||
| gdtrc | 伽马分布函数的补函数。 | ||
| polygamma | 多伽马函数 ψ(n)(x)。 | ||
| trigamma | 三伽马函数,是 digamma 函数的导数。 | ||
| digamma | 双伽马函数,是 lgamma 函数的导数。 | ||
| gegenbauer | Gegenbauer 多项式 C(α)<sub>n(x)。 | ||
| gegenbauer_derivative | Gegenbauer 多项式的导数。 | ||
| gegenbauer_prime | Gegenbauer 多项式的导数。 | ||
| hermite | Hermite 多项式 Hn(x)。 |
| 函数名 | 描述 |
|---|---|
| cbrt | 立方根函数。 |
| ceil | 向上取整函数。 |
| clamp | 将值限制在给定的范围内。 |
| div_euclid | 计算欧几里得除法的结果。 |
| entr | 计算以 2 为底的熵 -p * log2(p)。 |
| fdim | 计算 max(x - y, 0)。 |
| floor | 向下取整函数。 |
| gelu | Gaussian Error Linear Unit 激活函数。 |
| hypot | 计算 sqrt(x² + y²)。 |
| isinf | 检查浮点数是否为无穷大。 |
| isnan | 检查浮点数是否为 NaN(非数值)。 |
| isninf | 检查浮点数是否为负无穷大。 |
| isnormal | 检查浮点数是否为正规数(既不是零、次正规数、无穷大也不是 NaN)。 |
| ispinf | 检查浮点数是否为正无穷大。 |
| issubnormal | 检查浮点数是否为次正规数。 |
| ldexp | 计算 x * 2exp。 |
| lerp | 在两个值之间进行线性插值。 |
| norm | 计算数组的欧几里得范数(L2 范数)。 |
| norm3d | 计算三维向量的欧几里得范数。 |
| norm4d | 计算四维向量的欧几里得范数。 |
| normcdf | 标准正态分布累积分布函数。 |
| normcdfinv | 标准正态分布累积分布函数的反函数。 |
| rcbrt | 计算 1 / cbrt(x)。 |
| rem_euclid | 计算欧几里得除法的余数。 |
| rhypot | 计算 1 / sqrt(x² + y²)。 |
| rint | 四舍五入到最接近的整数。 |
| rnorm | 计算数组的欧几里得范数的倒数。 |
| round | 四舍五入到最接近的整数,远离零。 |
| roundeven | 四舍五入到最接近的偶数。 |
| scalbn | 计算 x * 2n。 |
| signum | 返回数字的符号:-1、0 或 1。 |
| to_degrees | 将弧度转换为度。 |
| to_radians | 将度转换为弧度。 |
| trunc | 向零取整函数。 |
| 函数名 | 最大 ULP |
|---|---|
| log | 0 |
| log2 | 1 |
| log10 | 0 |
| log1p | 0 |
| pow | 2 |
| exp | 1 |
| exp2 | 1 |
| exp10 | 1 |
| expm1 | 0 |
| cbrt | 0 |
| atan | 1 |
| atan2 | 1 |
| asin | 1 |
| acos | 1 |
| acosh | 0 |
| asinh | 0 |
| atanh | 0 |
| cosh | 0 |
| sinh | 0 |
| tanh | 0 |
| cos | 0 |
| sin | 0 |
| tan | 0 |
| cospi | 49 |
| sinpi | 3 |
| sqrt | 0 |
| hypot | 1 |
| erf | 1 |
| erfc | 1 |
| j0 | 2 |
| y0 | 2 |
| j1 | 4 |
| y1 | 2 |
| erfinv | 2 |
| gamma | 4 |
| lgamma | 23 |
| trigamma | 14 |
| digamma | 1023 |
| zeta | 3 |
let DOUBLE_EPSILON : Doublelet DOUBLE_MAX : Doublelet DOUBLE_MAX_10_EXP : Intlet DOUBLE_MAX_EXP : Intlet DOUBLE_MIN : Doublelet DOUBLE_MIN_10_EXP : Intlet DOUBLE_MIN_EXP : Intlet DOUBLE_MIN_POSITIVE : Doublelet DOUBLE_PI : Doublelet INT64_MAX : Int64let UINT64_MAX : UInt64fn acos(x : Double) -> Doubleassert_eq(acos(-0.5), 2.0943951023931957)
assert_eq(acos(0.5), 1.0471975511965979)
assert_eq(acos(1), 0)
assert_eq(acos(0), 1.5707963267948966)
assert_eq(acos(-1), 3.141592653589793)fn acosf(x : Float) -> Floatassert_eq(acosf(-0.5), 2.0943951023931957)
assert_eq(acosf(0.5), 1.0471975511965979)
assert_eq(acosf(1), 0)
assert_eq(acosf(0), 1.570796251296997)
assert_eq(acosf(-1), 3.141592502593994)fn acosh(x : Double) -> Doubleassert_eq(acosh(1.0), 0.0);
assert_eq(acosh(2.0), 1.3169578969248166);
assert_eq(acosh(3.0), 1.7627471740390859);
assert_eq(acosh(4.0), 2.0634370688955608);fn acoshf(x : Float) -> Floatassert_eq(acoshf(1.0), 0.0);
assert_eq(acoshf(2.0), 1.3169578969248166);
assert_eq(acoshf(3.0), 1.7627471740390859);
assert_eq(acoshf(4.0), 2.0634370688955608);fn asin(x : Double) -> Doubleassert_eq(asin(0), 0)
assert_eq(asin(1), 1.5707963267948966)
assert_eq(asin(-1), -1.5707963267948966)fn asinf(x : Float) -> Floatassert_eq(asinf(0), 0)
assert_eq(asinf(1), 1.5707963267948966)
assert_eq(asinf(-1), -1.5707963267948966)fn asinh(x : Double) -> Doubleassert_eq(asinh(-1), -0.881373587019543)
assert_eq(asinh(-2), -1.4436354751788103)
assert_eq(asinh(1), 0.881373587019543)
assert_eq(asinh(2), 1.4436354751788103)fn asinhf(x : Float) -> Floatassert_eq(asinhf(-1), -0.881373587019543)
assert_eq(asinhf(-2), -1.4436354751788103)
assert_eq(asinhf(1), 0.881373587019543)
assert_eq(asinhf(2), 1.4436354751788103)fn atan(x : Double) -> Doubleassert_eq(atan(0), 0)
assert_eq(atan(1), 0.7853981633974483)
assert_eq(atan(2), 1.1071487177940904)
assert_eq(atan(-1),-0.7853981633974483)
assert_eq(atan(-2),-1.1071487177940904)
assert_eq(atan(@double.infinity), 1.5707963267948966)
assert_eq(atan(@double.neg_infinity), -1.5707963267948966)fn atan2(y : Double, x : Double) -> Doubleassert_eq(atan2(1, 0), 1.5707963267948966)
assert_eq(atan2(1, 1), 0.7853981633974483)
assert_eq(atan2(0, -1), 3.141592653589793)fn atan2f(y : Float, x : Float) -> Floatassert_eq(atan2f(1, 0), 1.5707963267948966)
assert_eq(atan2f(1, 1), 0.7853981633974483)
assert_eq(atan2f(0, -1), 3.141592653589793)fn atanf(x : Float) -> Floatassert_eq(atanf(0), 0)
assert_eq(atanf(1), 0.7853981633974483)
assert_eq(atanf(2), 1.1071487177940904)
assert_eq(atanf(-1),-0.7853981633974483)
assert_eq(atanf(-2),-1.1071487177940904)
assert_eq(atanf(@float.infinity), 1.570796251296997)
assert_eq(atanf(@float.neg_infinity), -1.570796251296997)fn atanh(x : Double) -> Doubleassert_eq(atanh(0.0), 0.0);
assert_eq(atanh(0.5), 0.5493061443340548);
assert_eq(atanh(1.0), @double.infinity);
assert_eq(atanh(-0.5), -0.5493061443340548);
assert_eq(atanh(-1.0), @double.neg_infinity);fn atanhf(x : Float) -> Floatassert_eq(atanhf(0.0), 0.0);
assert_eq(atanhf(0.5), 0.5493061443340548);
assert_eq(atanhf(1.0), @float.infinity);
assert_eq(atanhf(-0.5), -0.5493061443340548);
assert_eq(atanhf(-1.0), @float.neg_infinity);fn bessel_i0(x : Double) -> Doublefn bessel_i0e(x : Double) -> Doublefn bessel_i1(x : Double) -> Doublefn bessel_i1e(x : Double) -> Doublefn bessel_j0(x : Double) -> Doubleassert_eq(j0(0.0), 1.0);
assert_eq(j0(1.0), 0.7651976865579666);
assert_eq(j0(2.0), 0.22389077914123567);
assert_eq(j0(3.0), -0.2600519549019335);fn bessel_j1(x : Double) -> Doubleassert_eq(j1(0), 0)
assert_eq(j1(1), 0.4400505857449335)
assert_eq(j1(2), 0.5767248077568733)
assert_eq(j1(1.542), 0.5634545029920421)fn bessel_jn(n : Int, x : Double) -> Doublefn bessel_k0(x : Double) -> Doublefn bessel_k0e(x : Double) -> Doublefn bessel_k1(x : Double) -> Doublefn bessel_k1e(x : Double) -> Doublefn bessel_yn(n : Int, x : Double) -> Doublefn cbrt(x : Double) -> Doubleassert_eq(cbrt(3), 1.4422495703074083)
assert_eq(cbrt(-3), -1.4422495703074083)
assert_eq(cbrt(0), 0)
assert_eq(cbrt(1), 1)
assert_eq(cbrt(1000), 10)fn cbrtf(x : Float) -> Floatassert_eq(cbrtf(3), 1.4422495703074083)
assert_eq(cbrtf(-3), -1.4422495703074083)
assert_eq(cbrtf(0), 0)
assert_eq(cbrtf(1), 1)
assert_eq(cbrtf(1000), 10)fn ceil(x : Double) -> Doubleassert_eq(ceil(2.5), 3.0)
assert_eq(ceil(3.14), 4.0)
assert_eq(ceil(-3.14), -3.0)
assert_eq(ceil(5.0), 5.0)
assert_eq(ceil(-5.0), -5.0)fn chbevl(x : Double, arr : ReadOnlyArray[Double]) -> Doublefn clamp(x : Double, min : Double, max : Double) -> Doubleassert_eq(clamp(-3.0, -2.0, 1.0), -2.0);
assert_eq(clamp(0.0, -2.0, 1.0), 0.0);
assert_eq(clamp(2.0, -2.0, 1.0), 1.0);fn cos(x : Double) -> Doubleassert_eq(cos(-1.0), 0.5403023058681398)
assert_eq(cos(0.0), 1)
assert_eq(cos(1.5707963267948966), 0.00000000000000006123233995736766)
assert_eq(cos(3.141592653589793), -1)
assert_eq(cos(10000), -0.9521553682590148)fn cosf(x : Float) -> Floatassert_eq(cosf(-1.0), 0.5403023058681398)
assert_eq(cosf(0.0), 1)
assert_eq(cosf(1.5707963267948966), -4.371138828673793e-8)
assert_eq(cosf(3.141592653589793), -1)
assert_eq(cosf(10000), -0.9521553682590148)fn cosh(x : Double) -> Doubleassert_eq(cosh(0), 1)
assert_eq(cosh(1), 1.5430806348152437)
assert_eq(cosh(2), 3.7621956910836314)
assert_eq(cosh(3), 10.067661995777765)
assert_eq(cosh(-1), 1.5430806348152437)fn coshf(x : Float) -> Floatassert_eq(coshf(0), 1)
assert_eq(coshf(1), 1.5430805683135986)
assert_eq(coshf(2), 3.7621958255767822)
assert_eq(coshf(3), 10.067661995777765)
assert_eq(coshf(-1), 1.5430805683135986)fn cospi(x : Double) -> Doubleassert_eq(cospi(0), 1);
assert_eq(cospi(1), -1);
assert_eq(cospi(0.5), 0);
assert_eq(cospi(-1), -1);
assert_eq(cospi(-0.5), 0);fn digamma(x : Double) -> Doubleassert_eq(digamma(1.0), -0.5772156649015328);
assert_eq(digamma(2.0), 0.422784335098467);
assert_eq(digamma(-0.5), 0.036489973978576895);fn div_euclid(x : Double, y : Double) -> Doublefn entr(x : Double) -> Doubleassert_eq(entr(0.0), 0.0);
assert_eq(entr(0.5), 0.34657359027997264);
assert_eq(entr(1.0), 0.0);fn erf(x : Double) -> Doubleassert_eq(erf(-0.8), -0.7421009647076605)
assert_eq(erf(0), 0)
assert_eq(erf(0.1), 0.1124629160182849)
assert_eq(erf(1), 0.8427007929497149)fn erfc(x : Double) -> Doubleassert_eq(erfc(0.5), 0.4795001221869535)
assert_eq(erfc(1.0), 0.15729920705028513)
assert_eq(erfc(2.0), 0.004677734981047266)
assert_eq(erfc(-0.5), 1.5204998778130465)
assert_eq(erfc(-1.0), 1.842700792949715)
assert_eq(erfc(-2.0), 1.9953222650189528)fn erfcinv(a : Double) -> Doubleassert_eq(erfcinv(0.5), 0.4769362895959522)
assert_eq(erfcinv(0.9), 0.08885598888653257)
assert_eq(erfcinv(1), 0)
assert_eq(erfcinv(1.542), -0.5247751634041989)
assert_eq(erfcinv(2), @double.neg_infinity)fn erfcx(x : Double) -> Doublefn erfinv(x : Double) -> Doubleassert_eq(erfinv(0.5), 0.47693627620446977)
assert_eq(erfinv(-0.5), -0.47693627620446977)
assert_eq(erfinv(0), 0)
assert_eq(erfinv(1), @double.infinity)
assert_eq(erfinv(-1), @double.neg_infinity)fn exp(input : Double) -> Doubleassert_eq(exp(1), 2.718281828459045)
assert_eq(exp(-1), 0.36787944117144233)
assert_eq(exp(-2), 0.1353352832366127)
assert_eq(exp(-3), 0.049787068367863944)fn exp10(x : Double) -> Doubleassert_eq(exp10(-1), 0.1);
assert_eq(exp10(-2), 0.01);
assert_eq(exp10(0), 1.0);
assert_eq(exp10(1), 10.0);
assert_eq(exp10(2), 100.0);fn exp2(x : Double) -> Doubleassert_eq(exp2(-1), 0.5);
assert_eq(exp2(-2), 0.25);
assert_eq(exp2(-3), 0.125);
assert_eq(exp2(-4), 0.0625);
assert_eq(exp2(0), 1);
assert_eq(exp2(1), 2);
assert_eq(exp2(2), 4);
assert_eq(exp2(3), 8);fn expm1(x : Double) -> Doubleassert_eq(expm1(1.0), 1.718281828459045)
assert_eq(expm1(0.0), 0.0)
assert_eq(expm1(-1.0), -0.6321205588285577)
assert_eq(expm1(2.0), 6.38905609893065)fn expm1f(x : Float) -> Floatassert_eq(expm1f(1.0), 1.7182817459106445)
assert_eq(expm1f(0.0), 0.0)
assert_eq(expm1f(-1.0), -0.6321205588285577)
assert_eq(expm1f(2.0), 6.38905609893065)fn fast_rsqrt(x : Float) -> Floatfn fdim(x : Double, y : Double) -> Doublefn floor(x : Double) -> Doubleassert_eq(floor(2.5), 2.0)
assert_eq(floor(3.14), 3.0)
assert_eq(floor(-3.14), -4.0)
assert_eq(floor(5.0), 5.0)
assert_eq(floor(-5.0), -5.0)fn fma(a : Double, b : Double, c : Double) -> Doublefn fract(x : Double) -> Doubleassert_eq(fract(3.25), 0.25);fn frexp(f : Double) -> (Double, Int)fn gamma(x : Double) -> Doubleassert_eq(gamma(1.0), 1.0)
assert_eq(gamma(2.0), 1.0)
assert_eq(gamma(3.0), 2.0)
assert_eq(gamma(6.0), 120.0)
assert_eq(gamma(10.0), 362880.0)
assert_eq(gamma(-0.5), -3.5449077018110318)
assert_eq(gamma(0.5), 1.7724538509055159)
assert_eq(gamma(9.8), 231791.87991967567)fn gdtr(a : Double, b : Double, x : Double) -> Doublefn gdtrc(a : Double, b : Double, x : Double) -> Doublefn gegenbauer(n : UInt, lambda : Double, x : Double) -> Doublefn gegenbauer_derivative(n : UInt, lambda : Double, x : Double, k : UInt) -> Doublefn hermite(n : UInt, x : Double) -> Doublefn hypot(x : Double, y : Double) -> Doubleassert_eq(hypot(3, 4), 5)
assert_eq(hypot(6, 8), 10)
assert_eq(hypot(5, 12), 13)
assert_eq(hypot(7, 24), 25)
assert_eq(hypot(3.14, -2.71), 4.147734321289154)
assert_eq(hypot(-3.14, 2.71), 4.147734321289154)fn hypotf(x : Float, y : Float) -> Floatassert_eq(hypotf(3, 4), 5)
assert_eq(hypotf(6, 8), 10)
assert_eq(hypotf(5, 12), 13)
assert_eq(hypotf(7, 24), 25)
assert_eq(hypotf(3.14, -2.71), 4.147734642028809)
assert_eq(hypotf(-3.14, 2.71), 4.147734642028809)fn igami(a : Double, y0 : Double) -> Doublefn isfinite(x : Double) -> Boolfn isinf(x : Double) -> Boolfn isnan(x : Double) -> Boolfn ldexp(x : Double, pw2 : Int) -> Doublefn lerp(a : Double, b : Double, t : Double) -> Doublefn ln_gamma(x : Double) -> Doublefn log(x : Double) -> Doubleassert_eq(log(0.1), -2.3025850929940455)
assert_eq(log(1), 0)
assert_eq(log(2), 0.6931471805599453)fn log10(x : Double) -> Doubleassert_eq(log10(1), 0)
assert_eq(log10(2), 0.3010299956639812)
assert_eq(log10(3), 0.47712125471966244)
assert_eq(log10(4), 0.6020599913279624)fn log1p(x : Double) -> Doubleassert_eq(log1p(0.1), 0.09531017980432487)
assert_eq(log1p(1), 0.6931471805599453)
assert_eq(log1p(-0.5), -0.6931471805599453)fn log1pf(x : Float) -> Floatassert_eq(log1pf(0.1), 0.09531017980432487)
assert_eq(log1pf(1), 0.6931471805599453)
assert_eq(log1pf(-0.5), -0.6931471805599453)fn log2(x : Double) -> Doubleassert_eq(log2(0.1), -3.321928094887362)
assert_eq(log2(1), 0)
assert_eq(log2(2), 1)
assert_eq(log2(3), 1.584962500721156)fn log_ndtr(x : Double) -> Doublefn logaddexp(x1 : Double, x2 : Double) -> Doublefn ndtri(y0 : Double) -> Doubleassert_eq(nearbyint(2.5), 2.0)
assert_eq(nearbyint(2.5, round_mode=FE_DOWNWARD), 2.0)
assert_eq(nearbyint(2.5, round_mode=FE_UPWARD), 3.0)
assert_eq(nearbyint(2.5, round_mode=FE_TOWARDZERO), 2.0)fn nextafter(x : Double, y : Double) -> Doublefn norm3d(a : Double, b : Double, c : Double) -> Doublefn norm4d(a : Double, b : Double, c : Double, d : Double) -> Doublefn normcdf(x : Double) -> Doublefn normcdfinv(x : Double) -> Doublefn polygamma(x : Double, n : Int) -> Doublefn pow(base : Double, expon : Double) -> Doublefn powf(x : Float, y : Float) -> Floatfn powi(x : Double, i : Int) -> Doublefn pown(x : Double, n : Int) -> Doublefn rem_euclid(x : Double, y : Double) -> Doublelet a: Double = 7.0;
let b = 4.0;
assert_eq(rem_euclid(a, b), 3.0);
assert_eq(rem_euclid(-a, b), 1.0);
assert_eq(rem_euclid(a, -b), 3.0);
assert_eq(rem_euclid(-a, -b), 1.0);fn rhypot(x : Double, y : Double) -> Doubleassert_eq(rint(2.5), 2)
assert_eq(rint(2.5, round_mode=FE_DOWNWARD), 2.0)
assert_eq(rint(2.5, round_mode=FE_UPWARD), 3.0)
assert_eq(rint(2.5, round_mode=FE_TOWARDZERO), 2.0)fn rnorm3d(a : Double, b : Double, c : Double) -> Doublefn rnorm4d(a : Double, b : Double, c : Double, d : Double) -> Doublefn round(x : Double) -> Doubleassert_eq(round(2.5), 3.0)
assert_eq(round(3.14), 3.0)
assert_eq(round(-3.14), -3.0)
assert_eq(round(5.0), 5.0)
assert_eq(round(-5.0), -5.0)fn roundeven(x : Double) -> Doublelet x = 1.4; assert_eq(roundeven(x), 1.0);
let x = 1.5; assert_eq(roundeven(x), 2.0);
let x = 1.6; assert_eq(roundeven(x), 2.0);
let x = 2.4; assert_eq(roundeven(x), 2.0);
let x = 2.5; assert_eq(roundeven(x), 2.0);
let x = 2.6; assert_eq(roundeven(x), 3.0);fn scalbn(input : Double, n : Int) -> Doublefn scalbnf(x : Float, n : Int) -> Floatfn signum(x : Double) -> Doublefn sin(x : Double) -> Doubleassert_eq(sin(-1.0), -0.8414709848078965)
assert_eq(sin(0.0), 0)
assert_eq(sin(1.5707963267948966), 1.0)
assert_eq(sin(3.141592653589793), 0.00000000000000012246467991473532)
assert_eq(sin(10000), -0.30561438888825215)fn sincos(x : Double) -> (Double, Double)let x = 1.0
let (sin_x, cos_x) = sincos(x)
let sin_x_directly = sin(x)
let cos_x_directly = cos(x)
assert_eq(sin_x, sin_x_directly)
assert_eq(cos_x, cos_x_directly)fn sincospi(x : Double) -> (Double, Double)fn sinf(x : Float) -> Floatassert_eq(sinf(-1.0), -0.8414709848078965)
assert_eq(sinf(0.0), 0)
assert_eq(sinf(1.5707963267948966), 1.0)
assert_eq(sinf(3.141592653589793), -8.742277657347586e-8)
assert_eq(sinf(10000), -0.30561438888825215)fn sinh(x : Double) -> Doubleassert_eq(sinh(-0.5), -0.5210953054937474)
assert_eq(sinh(0.0), 0.0)
assert_eq(sinh(0.5), 0.5210953054937474)
assert_eq(sinh(1.0), 1.1752011936438014)fn sinhf(x : Float) -> Floatassert_eq(sinhf(-0.5), -0.5210953054937474)
assert_eq(sinhf(0.0), 0.0)
assert_eq(sinhf(0.5), 0.5210953054937474)
assert_eq(sinhf(1.0), 1.1752011936438014)fn sinpi(x : Double) -> Doublefn sqrt(x : Double) -> Doubleassert_eq(sqrt(0), 0);
assert_eq(sqrt(1), 1);
assert_eq(sqrt(2), 1.4142135623730951);
assert_eq(sqrt(3), 1.7320508075688772);fn sqrt1pm1(x : Double) -> Doublefn tan(x : Double) -> Doubleassert_eq(tan(-1.0), -1.5574077246549023)
assert_eq(tan(3.141592653589793), -0.00000000000000012246467991473532)
assert_eq(tan(1.5707963267948966), 16331239353195370)
assert_eq(tan(0.7853981633974483), 0.9999999999999999)
assert_eq(tan(0.0), 0)
assert_eq(tan(10000), 0.3209711346238147)fn tanf(x : Float) -> Floatassert_eq(tanf(-1.0), -1.5574077246549023)
assert_eq(tanf(3.1415926), -1.5099580252808664e-7)
assert_eq(tanf(1.570796326), -22877334)
assert_eq(tanf(0.7853981), 0.9999998807907104)
assert_eq(tanf(0.0), 0)
assert_eq(tanf(10000), 0.3209711346238147)fn tanh(x : Double) -> Doubleassert_eq(tanh(-0.5), -0.46211715726000974)
assert_eq(tanh(0.5), 0.46211715726000974)
assert_eq(tanh(0.0), 0.0)
assert_eq(tanh(1), 0.7615941559557649)
assert_eq(tanh(2), 0.9640275800758169)fn tanhf(x : Float) -> Floatassert_eq(tanhf(-0.5), -0.46211713552474976)
assert_eq(tanhf(0.5), 0.46211713552474976)
assert_eq(tanhf(0.0), 0.0)
assert_eq(tanhf(1), 0.7615941559557649)
assert_eq(tanhf(2), 0.9640275800758169)fn trigamma(x : Double) -> Doubleassert_eq(trigamma(0.5), 4.93480220054468);
assert_eq(trigamma(1.0), 1.6449340668482262);
assert_eq(trigamma(2.0), 0.6449340668482261);
assert_eq(trigamma(3.0), 0.39493406684822613);fn trunc(x : Double) -> Doubleassert_eq(trunc(2.5), 2.0)
assert_eq(trunc(3.14), 3.0)
assert_eq(trunc(-3.14), -3.0)
assert_eq(trunc(5.0), 5.0)
assert_eq(trunc(-5.0), -5.0)fn y0(x : Double) -> Doublelet inf = 1.0/0.0
assert_eq(y0(0), -inf)
assert_eq(y0(1), 0.08825696421567697)
assert_eq(y0(2), 0.5103756726497451)
assert_eq(y0(1.542), 0.3991886731083115)fn y1(x : Double) -> Doublelet inf = 1.0/0.0
assert_eq(y1(0), -inf);
assert_eq(y1(1), -0.7812128213002887);
assert_eq(y1(2), -0.10703243154093756);
assert_eq(y1(1.542), -0.3848820110973209);fn zeta(x : Double, y : Double) -> Doubleassert_eq(zeta(2.0, 2.0), 0.6449340668482266)
assert_eq(zeta(2.0, 3.14159), 0.3742441373024457)
assert_eq(zeta(3.14159, 2.71828), 0.08044299178527513)
assert_eq(zeta(2, -0.0027818), 129227.143674529)High-precision Math library Implemented By Pure Moonbit