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

LibCMath

Computes square root through native sqrtf.

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.libc.math

import std.libc.math;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

<

pub fn<.C> sqrtf(Value: f32) -> f32;

Computes square root through native sqrtf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

Example

module example.native_math;
import std.libc.math as NativeMath;
// These known exact libm results deliberately use IEEE equality.
@allow("W2101")
fn Main() -> i32 {
    unsafe {
        if NativeMath.sqrtf(4_f32) != 2_f32 { return 1; }
        if NativeMath.sqrt(4_f64) != 2_f64 { return 1; }
        if NativeMath.cbrtf(8_f32) != 2_f32 { return 1; }
        if NativeMath.cbrt(8_f64) != 2_f64 { return 1; }
        if NativeMath.sinf(0_f32) != 0_f32 { return 1; }
        if NativeMath.sin(0_f64) != 0_f64 { return 1; }
        if NativeMath.cosf(0_f32) != 1_f32 { return 1; }
        if NativeMath.cos(0_f64) != 1_f64 { return 1; }
        if NativeMath.tanf(0_f32) != 0_f32 { return 1; }
        if NativeMath.tan(0_f64) != 0_f64 { return 1; }
        if NativeMath.asinf(0_f32) != 0_f32 { return 1; }
        if NativeMath.asin(0_f64) != 0_f64 { return 1; }
        if NativeMath.acosf(1_f32) != 0_f32 { return 1; }
        if NativeMath.acos(1_f64) != 0_f64 { return 1; }
        if NativeMath.atanf(0_f32) != 0_f32 { return 1; }
        if NativeMath.atan(0_f64) != 0_f64 { return 1; }
        if NativeMath.atan2f(0_f32, 1_f32) != 0_f32 { return 1; }
        if NativeMath.atan2(0_f64, 1_f64) != 0_f64 { return 1; }
        if NativeMath.expf(0_f32) != 1_f32 { return 1; }
        if NativeMath.exp(0_f64) != 1_f64 { return 1; }
        if NativeMath.exp2f(0_f32) != 1_f32 { return 1; }
        if NativeMath.exp2(0_f64) != 1_f64 { return 1; }
        if NativeMath.logf(1_f32) != 0_f32 { return 1; }
        if NativeMath.log(1_f64) != 0_f64 { return 1; }
        if NativeMath.log2f(1_f32) != 0_f32 { return 1; }
        if NativeMath.log2(1_f64) != 0_f64 { return 1; }
        if NativeMath.log10f(1_f32) != 0_f32 { return 1; }
        if NativeMath.log10(1_f64) != 0_f64 { return 1; }
        if NativeMath.powf(2_f32, 3_f32) != 8_f32 { return 1; }
        if NativeMath.pow(2_f64, 3_f64) != 8_f64 { return 1; }
        if NativeMath.floorf(1.75_f32) != 1_f32 { return 1; }
        if NativeMath.floor(1.75_f64) != 1_f64 { return 1; }
        if NativeMath.ceilf(1.25_f32) != 2_f32 { return 1; }
        if NativeMath.ceil(1.25_f64) != 2_f64 { return 1; }
        if NativeMath.truncf(-1.75_f32) != -1_f32 { return 1; }
        if NativeMath.trunc(-1.75_f64) != -1_f64 { return 1; }
        if NativeMath.fmodf(5_f32, 2_f32) != 1_f32 { return 1; }
        if NativeMath.fmod(5_f64, 2_f64) != 1_f64 { return 1; }
    }
    return 0;
}

<

pub fn<.C> sqrt(Value: f64) -> f64;

Computes square root through native sqrt. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> cbrtf(Value: f32) -> f32;

Computes real cube root through native cbrtf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> cbrt(Value: f64) -> f64;

Computes real cube root through native cbrt. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> sinf(Value: f32) -> f32;

Computes sine of a radian angle through native sinf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> sin(Value: f64) -> f64;

Computes sine of a radian angle through native sin. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> cosf(Value: f32) -> f32;

Computes cosine of a radian angle through native cosf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> cos(Value: f64) -> f64;

Computes cosine of a radian angle through native cos. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> tanf(Value: f32) -> f32;

Computes tangent of a radian angle through native tanf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> tan(Value: f64) -> f64;

Computes tangent of a radian angle through native tan. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> asinf(Value: f32) -> f32;

Computes inverse sine in radians through native asinf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> asin(Value: f64) -> f64;

Computes inverse sine in radians through native asin. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> acosf(Value: f32) -> f32;

Computes inverse cosine in radians through native acosf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> acos(Value: f64) -> f64;

Computes inverse cosine in radians through native acos. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> atanf(Value: f32) -> f32;

Computes inverse tangent in radians through native atanf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> atan(Value: f64) -> f64;

Computes inverse tangent in radians through native atan. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> atan2f(Y: f32, X: f32) -> f32;

Computes quadrant-aware inverse tangent in radians through native atan2f. Y: Scalar input passed by value; no pointer/lifetime obligation. X: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> atan2(Y: f64, X: f64) -> f64;

Computes quadrant-aware inverse tangent in radians through native atan2. Y: Scalar input passed by value; no pointer/lifetime obligation. X: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> expf(Value: f32) -> f32;

Computes base-e exponential through native expf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> exp(Value: f64) -> f64;

Computes base-e exponential through native exp. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> exp2f(Value: f32) -> f32;

Computes base-two exponential through native exp2f. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> exp2(Value: f64) -> f64;

Computes base-two exponential through native exp2. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> logf(Value: f32) -> f32;

Computes natural logarithm through native logf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> log(Value: f64) -> f64;

Computes natural logarithm through native log. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> log2f(Value: f32) -> f32;

Computes base-two logarithm through native log2f. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> log2(Value: f64) -> f64;

Computes base-two logarithm through native log2. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> log10f(Value: f32) -> f32;

Computes base-ten logarithm through native log10f. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> log10(Value: f64) -> f64;

Computes base-ten logarithm through native log10. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> powf(Base: f32, Exponent: f32) -> f32;

Computes base raised to an exponent through native powf. Base: Scalar input passed by value; no pointer/lifetime obligation. Exponent: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> pow(Base: f64, Exponent: f64) -> f64;

Computes base raised to an exponent through native pow. Base: Scalar input passed by value; no pointer/lifetime obligation. Exponent: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> floorf(Value: f32) -> f32;

Computes integer-valued floor through native floorf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> floor(Value: f64) -> f64;

Computes integer-valued floor through native floor. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> ceilf(Value: f32) -> f32;

Computes integer-valued ceiling through native ceilf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> ceil(Value: f64) -> f64;

Computes integer-valued ceiling through native ceil. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> truncf(Value: f32) -> f32;

Computes integer-valued truncation toward zero through native truncf. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> trunc(Value: f64) -> f64;

Computes integer-valued truncation toward zero through native trunc. Value: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> fmodf(Value: f32, Divisor: f32) -> f32;

Computes remainder after quotient truncation toward zero through native fmodf. Value: Scalar input passed by value; no pointer/lifetime obligation. Divisor: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

<

pub fn<.C> fmod(Value: f64, Divisor: f64) -> f64;

Computes remainder after quotient truncation toward zero through native fmod. Value: Scalar input passed by value; no pointer/lifetime obligation. Divisor: Scalar input passed by value; no pointer/lifetime obligation. Return: Native IEEE result, including NaN/infinity for domain/range errors. Pre: Safety: selected provider matches the declared C scalar ABI; no foreign unwind crosses Sn. Warning: Native floating status/errno may change; this declaration requires unsafe authorization.

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