Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
0.2.0 Preview 1 · Frozen documentation

FloatingMath

Computes square root for f16.

Sn is under heavy development. Reference extracted from this release’s bundled standard library. Public API examples are not an exhaustive compatibility test. Read the matching release guide for tested workflows and limitations. Read the status →

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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Computes 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) -> f32

Computes 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) -> f64

Computes 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) -> f16

Rounds 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) -> f32

Rounds 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) -> f64

Rounds 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.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library