std::math
Math Module
Double-precision math wrappers backed by the C math library (libm).
Function Reference
| Category | Functions |
|---|---|
| Constants | PI, E, TAU |
| Trigonometry | sin, cos, tan, asin, acos, atan, atan2 |
| Exponential | exp, log, log10, pow, sqrt |
| Rounding | floor, ceil, round, trunc |
| Absolute value | fabs |
All functions operate on f64 and follow the underlying libm semantics
of the target platform.
Example
import Math from "std::math";
import Io from "std::io";
import String from "std::string";
function main(): i32 {
let angle: f64 = Math::PI / 2.0;
let value: f64 = Math::sin(angle);
let dist: f64 = Math::sqrt((3.0 * 3.0) + (4.0 * 4.0));
Io::println(String::toString(value));
Io::println(String::toString(dist));
return 0;
}
namespace __mathFunctions
function acos(x: f64): f64C acos wrapper; returns the arc cosine of x in radians.
function asin(x: f64): f64C asin wrapper; returns the arc sine of x in radians.
function atan(x: f64): f64C atan wrapper; returns the arc tangent of x in radians.
function atan2(y: f64, x: f64): f64C atan2 wrapper; returns the angle for coordinates y and x.
function ceil(x: f64): f64C ceiling wrapper.
function cos(x: f64): f64C cos wrapper; returns the cosine of x radians.
function exp(x: f64): f64C exp wrapper; returns e raised to x.
function fabs(x: f64): f64C absolute-value wrapper for f64.
function floor(x: f64): f64C floor wrapper.
function log(x: f64): f64C natural logarithm wrapper.
function log10(x: f64): f64C base-10 logarithm wrapper.
function pow(base: f64, exp: f64): f64C power wrapper; returns base raised to exp.
function round(x: f64): f64C round-to-nearest wrapper using platform libm semantics.
function sin(x: f64): f64C sin wrapper; returns the sine of x radians.
function sqrt(x: f64): f64C square-root wrapper.
function tan(x: f64): f64C tan wrapper; returns the tangent of x radians.
function trunc(x: f64): f64C truncation wrapper.
Constants
const E: f64const PI: f64const TAU: f64namespace MathPublic double-precision math functions and constants.
All functions delegate to the target platform C math library and therefore follow the host libm behavior for NaN, infinity, and domain errors.
Functions
function acos(x: f64): f64Returns the arc-cosine of x.
Example
import Math from "std::math";
let y: f64 = Math::acos(1.0);
function asin(x: f64): f64Returns the arc-sine of x.
Example
import Math from "std::math";
let y: f64 = Math::asin(1.0);
function atan(x: f64): f64Returns the arc-tangent of x.
Example
import Math from "std::math";
let y: f64 = Math::atan(1.0);
function atan2(y: f64, x: f64): f64Returns the arc-tangent of y / x with quadrant handling.
Example
import Math from "std::math";
let y: f64 = Math::atan2(1.0, 1.0);
function ceil(x: f64): f64Rounds x up to the nearest integer.
Example
import Math from "std::math";
let y: f64 = Math::ceil(2.1);
function cos(x: f64): f64Returns the cosine of x.
Example
import Math from "std::math";
let y: f64 = Math::cos(0.0);
function exp(x: f64): f64Returns e^x.
Example
import Math from "std::math";
let y: f64 = Math::exp(1.0);
function fabs(x: f64): f64Returns the absolute value of x.
Example
import Math from "std::math";
let y: f64 = Math::fabs(-3.5);
function floor(x: f64): f64Rounds x down to the nearest integer.
Example
import Math from "std::math";
let y: f64 = Math::floor(2.9);
function log(x: f64): f64Returns the natural logarithm of x.
Example
import Math from "std::math";
let y: f64 = Math::log(Math::E);
function log10(x: f64): f64Returns the base-10 logarithm of x.
Example
import Math from "std::math";
let y: f64 = Math::log10(1000.0);
function pow(base: f64, exp: f64): f64Returns base^exp.
Example
import Math from "std::math";
let y: f64 = Math::pow(2.0, 8.0);
function round(x: f64): f64Rounds x to the nearest integer.
Example
import Math from "std::math";
let y: f64 = Math::round(2.5);
function sin(x: f64): f64Returns the sine of x.
Example
import Math from "std::math";
let y: f64 = Math::sin(Math::PI / 2.0);
function sqrt(x: f64): f64Returns the square root of x.
Example
import Math from "std::math";
let y: f64 = Math::sqrt(25.0);
function tan(x: f64): f64Returns the tangent of x.
Example
import Math from "std::math";
let y: f64 = Math::tan(1.0);
function trunc(x: f64): f64Truncates x toward zero.
Example
import Math from "std::math";
let y: f64 = Math::trunc(-2.9);
Constants
const E: f64const PI: f64const TAU: f64