FloatingMath
Computes square root for f16.
Module std.math
import std.math;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
Sqrt
pub fn Sqrt(Value: f16) -> f16Computes square root for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Example
module example.floating_math;
from std.math import Sqrt, Cbrt, Sin, Cos, Tan, Asin, Acos, Atan, Atan2,
Exp, Exp2, Log, Log2, Log10, Pow, Floor, Ceil, Truncate, Remainder,
Round, IsNaN, IsFinite, IsInfinity, CopySign;
// These known exact results deliberately use IEEE equality, including zero.
@allow("W2101")
fn Main() -> i32 {
if Sqrt(4_f16) != 2_f16 { return 1; }
if Sqrt(4_f32) != 2_f32 { return 1; }
if Sqrt(4_f64) != 2_f64 { return 1; }
if Cbrt(8_f16) != 2_f16 { return 1; }
if Cbrt(8_f32) != 2_f32 { return 1; }
if Cbrt(8_f64) != 2_f64 { return 1; }
if Sin(0_f16) != 0_f16 { return 1; }
if Sin(0_f32) != 0_f32 { return 1; }
if Sin(0_f64) != 0_f64 { return 1; }
if Cos(0_f16) != 1_f16 { return 1; }
if Cos(0_f32) != 1_f32 { return 1; }
if Cos(0_f64) != 1_f64 { return 1; }
if Tan(0_f16) != 0_f16 { return 1; }
if Tan(0_f32) != 0_f32 { return 1; }
if Tan(0_f64) != 0_f64 { return 1; }
if Asin(0_f16) != 0_f16 { return 1; }
if Asin(0_f32) != 0_f32 { return 1; }
if Asin(0_f64) != 0_f64 { return 1; }
if Acos(1_f16) != 0_f16 { return 1; }
if Acos(1_f32) != 0_f32 { return 1; }
if Acos(1_f64) != 0_f64 { return 1; }
if Atan(0_f16) != 0_f16 { return 1; }
if Atan(0_f32) != 0_f32 { return 1; }
if Atan(0_f64) != 0_f64 { return 1; }
if Atan2(0_f16, 1_f16) != 0_f16 { return 1; }
if Atan2(0_f32, 1_f32) != 0_f32 { return 1; }
if Atan2(0_f64, 1_f64) != 0_f64 { return 1; }
if Exp(0_f16) != 1_f16 { return 1; }
if Exp(0_f32) != 1_f32 { return 1; }
if Exp(0_f64) != 1_f64 { return 1; }
if Exp2(0_f16) != 1_f16 { return 1; }
if Exp2(0_f32) != 1_f32 { return 1; }
if Exp2(0_f64) != 1_f64 { return 1; }
if Log(1_f16) != 0_f16 { return 1; }
if Log(1_f32) != 0_f32 { return 1; }
if Log(1_f64) != 0_f64 { return 1; }
if Log2(1_f16) != 0_f16 { return 1; }
if Log2(1_f32) != 0_f32 { return 1; }
if Log2(1_f64) != 0_f64 { return 1; }
if Log10(1_f16) != 0_f16 { return 1; }
if Log10(1_f32) != 0_f32 { return 1; }
if Log10(1_f64) != 0_f64 { return 1; }
if Pow(2_f16, 3_f16) != 8_f16 { return 1; }
if Pow(2_f32, 3_f32) != 8_f32 { return 1; }
if Pow(2_f64, 3_f64) != 8_f64 { return 1; }
if Floor(1.75_f16) != 1_f16 { return 1; }
if Floor(1.75_f32) != 1_f32 { return 1; }
if Floor(1.75_f64) != 1_f64 { return 1; }
if Ceil(1.25_f16) != 2_f16 { return 1; }
if Ceil(1.25_f32) != 2_f32 { return 1; }
if Ceil(1.25_f64) != 2_f64 { return 1; }
if Truncate(-1.75_f16) != -1_f16 { return 1; }
if Truncate(-1.75_f32) != -1_f32 { return 1; }
if Truncate(-1.75_f64) != -1_f64 { return 1; }
if Remainder(5_f16, 2_f16) != 1_f16 { return 1; }
if Remainder(5_f32, 2_f32) != 1_f32 { return 1; }
if Remainder(5_f64, 2_f64) != 1_f64 { return 1; }
if Round(2.5_f32) != 2_f32 || Round(3.5_f64) != 4_f64 || Round(-2.5_f16) != -2_f16 { return 2; }
if !IsNaN(Sqrt(-1_f32)) || IsFinite(Sqrt(-1_f32)) { return 3; }
if !IsInfinity(Log(0_f64)) || CopySign(3_f32, -1_f32) != -3_f32 { return 4; }
return 0;
}Sqrt
pub fn Sqrt(Value: f32) -> f32Computes square root for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Sqrt
pub fn Sqrt(Value: f64) -> f64Computes square root for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Cbrt
pub fn Cbrt(Value: f16) -> f16Computes real cube root for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Cbrt
pub fn Cbrt(Value: f32) -> f32Computes real cube root for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Cbrt
pub fn Cbrt(Value: f64) -> f64Computes real cube root for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Sin
pub fn Sin(Value: f16) -> f16Computes sine of a radian angle for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Sin
pub fn Sin(Value: f32) -> f32Computes sine of a radian angle for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Sin
pub fn Sin(Value: f64) -> f64Computes sine of a radian angle for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Cos
pub fn Cos(Value: f16) -> f16Computes cosine of a radian angle for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Cos
pub fn Cos(Value: f32) -> f32Computes cosine of a radian angle for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Cos
pub fn Cos(Value: f64) -> f64Computes cosine of a radian angle for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Tan
pub fn Tan(Value: f16) -> f16Computes tangent of a radian angle for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Tan
pub fn Tan(Value: f32) -> f32Computes tangent of a radian angle for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Tan
pub fn Tan(Value: f64) -> f64Computes tangent of a radian angle for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Asin
pub fn Asin(Value: f16) -> f16Computes inverse sine in radians for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Asin
pub fn Asin(Value: f32) -> f32Computes inverse sine in radians for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Asin
pub fn Asin(Value: f64) -> f64Computes inverse sine in radians for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Acos
pub fn Acos(Value: f16) -> f16Computes inverse cosine in radians for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Acos
pub fn Acos(Value: f32) -> f32Computes inverse cosine in radians for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Acos
pub fn Acos(Value: f64) -> f64Computes inverse cosine in radians for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Atan
pub fn Atan(Value: f16) -> f16Computes inverse tangent in radians for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Atan
pub fn Atan(Value: f32) -> f32Computes inverse tangent in radians for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Atan
pub fn Atan(Value: f64) -> f64Computes inverse tangent in radians for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Atan2
pub fn Atan2(Y: f16, X: f16) -> f16Computes quadrant-aware inverse tangent in radians for f16. Y: Numeric input passed by value; angles use radians. X: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Atan2
pub fn Atan2(Y: f32, X: f32) -> f32Computes quadrant-aware inverse tangent in radians for f32. Y: Numeric input passed by value; angles use radians. X: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Atan2
pub fn Atan2(Y: f64, X: f64) -> f64Computes quadrant-aware inverse tangent in radians for f64. Y: Numeric input passed by value; angles use radians. X: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Exp
pub fn Exp(Value: f16) -> f16Computes base-e exponential for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Exp
pub fn Exp(Value: f32) -> f32Computes base-e exponential for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Exp
pub fn Exp(Value: f64) -> f64Computes base-e exponential for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Exp2
pub fn Exp2(Value: f16) -> f16Computes base-two exponential for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Exp2
pub fn Exp2(Value: f32) -> f32Computes base-two exponential for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Exp2
pub fn Exp2(Value: f64) -> f64Computes base-two exponential for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Log
pub fn Log(Value: f16) -> f16Computes natural logarithm for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Log
pub fn Log(Value: f32) -> f32Computes natural logarithm for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Log
pub fn Log(Value: f64) -> f64Computes natural logarithm for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Log2
pub fn Log2(Value: f16) -> f16Computes base-two logarithm for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Log2
pub fn Log2(Value: f32) -> f32Computes base-two logarithm for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Log2
pub fn Log2(Value: f64) -> f64Computes base-two logarithm for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Log10
pub fn Log10(Value: f16) -> f16Computes base-ten logarithm for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Log10
pub fn Log10(Value: f32) -> f32Computes base-ten logarithm for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Log10
pub fn Log10(Value: f64) -> f64Computes base-ten logarithm for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Pow
pub fn Pow(Base: f16, Exponent: f16) -> f16Computes base raised to an exponent for f16. Base: Numeric input passed by value; angles use radians. Exponent: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Pow
pub fn Pow(Base: f32, Exponent: f32) -> f32Computes base raised to an exponent for f32. Base: Numeric input passed by value; angles use radians. Exponent: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Pow
pub fn Pow(Base: f64, Exponent: f64) -> f64Computes base raised to an exponent for f64. Base: Numeric input passed by value; angles use radians. Exponent: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Floor
pub fn Floor(Value: f16) -> f16Computes integer-valued floor for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Floor
pub fn Floor(Value: f32) -> f32Computes integer-valued floor for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Floor
pub fn Floor(Value: f64) -> f64Computes integer-valued floor for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Ceil
pub fn Ceil(Value: f16) -> f16Computes integer-valued ceiling for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Ceil
pub fn Ceil(Value: f32) -> f32Computes integer-valued ceiling for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Ceil
pub fn Ceil(Value: f64) -> f64Computes integer-valued ceiling for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Truncate
pub fn Truncate(Value: f16) -> f16Computes integer-valued truncation toward zero for f16. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Truncate
pub fn Truncate(Value: f32) -> f32Computes integer-valued truncation toward zero for f32. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Truncate
pub fn Truncate(Value: f64) -> f64Computes integer-valued truncation toward zero for f64. Value: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Remainder
pub fn Remainder(Value: f16, Divisor: f16) -> f16Computes remainder after quotient truncation toward zero for f16. Value: Numeric input passed by value; angles use radians. Divisor: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained. Note: Computes through f32, then rounds to f16; no correctly-rounded transcendental promise.
Remainder
pub fn Remainder(Value: f32, Divisor: f32) -> f32Computes remainder after quotient truncation toward zero for f32. Value: Numeric input passed by value; angles use radians. Divisor: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Remainder
pub fn Remainder(Value: f64, Divisor: f64) -> f64Computes remainder after quotient truncation toward zero for f64. Value: Numeric input passed by value; angles use radians. Divisor: Numeric input passed by value; angles use radians. Return: Native IEEE result; domain/range errors produce NaN/infinity rather than exceptions. Note: Safe runtime call. No input borrow or managed allocation is retained.
Round
pub fn Round(Value: f16) -> f16Rounds f16 to an integer-valued float using nearest-even ties. Value: Floating input; NaN/infinity pass through and zero preserves its sign. Return: Rounded value independently of ambient rounding mode; no managed allocation.
Round
pub fn Round(Value: f32) -> f32Rounds f32 to an integer-valued float using nearest-even ties. Value: Floating input; NaN/infinity pass through and zero preserves its sign. Return: Rounded value independently of ambient rounding mode; no managed allocation.
Round
pub fn Round(Value: f64) -> f64Rounds f64 to an integer-valued float using nearest-even ties. Value: Floating input; NaN/infinity pass through and zero preserves its sign. Return: Rounded value independently of ambient rounding mode; no managed allocation.