Module

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 __math

Functions

function acos(x: f64): f64

C acos wrapper; returns the arc cosine of x in radians.

function asin(x: f64): f64

C asin wrapper; returns the arc sine of x in radians.

function atan(x: f64): f64

C atan wrapper; returns the arc tangent of x in radians.

function atan2(y: f64, x: f64): f64

C atan2 wrapper; returns the angle for coordinates y and x.

function ceil(x: f64): f64

C ceiling wrapper.

function cos(x: f64): f64

C cos wrapper; returns the cosine of x radians.

function exp(x: f64): f64

C exp wrapper; returns e raised to x.

function fabs(x: f64): f64

C absolute-value wrapper for f64.

function floor(x: f64): f64

C floor wrapper.

function log(x: f64): f64

C natural logarithm wrapper.

function log10(x: f64): f64

C base-10 logarithm wrapper.

function pow(base: f64, exp: f64): f64

C power wrapper; returns base raised to exp.

function round(x: f64): f64

C round-to-nearest wrapper using platform libm semantics.

function sin(x: f64): f64

C sin wrapper; returns the sine of x radians.

function sqrt(x: f64): f64

C square-root wrapper.

function tan(x: f64): f64

C tan wrapper; returns the tangent of x radians.

function trunc(x: f64): f64

C truncation wrapper.

Constants

const E: f64
const PI: f64
const TAU: f64
namespace Math

Public 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): f64

Returns the arc-cosine of x.

Example

import Math from "std::math";

let y: f64 = Math::acos(1.0);
function asin(x: f64): f64

Returns the arc-sine of x.

Example

import Math from "std::math";

let y: f64 = Math::asin(1.0);
function atan(x: f64): f64

Returns the arc-tangent of x.

Example

import Math from "std::math";

let y: f64 = Math::atan(1.0);
function atan2(y: f64, x: f64): f64

Returns 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): f64

Rounds x up to the nearest integer.

Example

import Math from "std::math";

let y: f64 = Math::ceil(2.1);
function cos(x: f64): f64

Returns the cosine of x.

Example

import Math from "std::math";

let y: f64 = Math::cos(0.0);
function exp(x: f64): f64

Returns e^x.

Example

import Math from "std::math";

let y: f64 = Math::exp(1.0);
function fabs(x: f64): f64

Returns the absolute value of x.

Example

import Math from "std::math";

let y: f64 = Math::fabs(-3.5);
function floor(x: f64): f64

Rounds x down to the nearest integer.

Example

import Math from "std::math";

let y: f64 = Math::floor(2.9);
function log(x: f64): f64

Returns the natural logarithm of x.

Example

import Math from "std::math";

let y: f64 = Math::log(Math::E);
function log10(x: f64): f64

Returns 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): f64

Returns base^exp.

Example

import Math from "std::math";

let y: f64 = Math::pow(2.0, 8.0);
function round(x: f64): f64

Rounds x to the nearest integer.

Example

import Math from "std::math";

let y: f64 = Math::round(2.5);
function sin(x: f64): f64

Returns the sine of x.

Example

import Math from "std::math";

let y: f64 = Math::sin(Math::PI / 2.0);
function sqrt(x: f64): f64

Returns the square root of x.

Example

import Math from "std::math";

let y: f64 = Math::sqrt(25.0);
function tan(x: f64): f64

Returns the tangent of x.

Example

import Math from "std::math";

let y: f64 = Math::tan(1.0);
function trunc(x: f64): f64

Truncates x toward zero.

Example

import Math from "std::math";

let y: f64 = Math::trunc(-2.9);

Constants

const E: f64
const PI: f64
const TAU: f64