Module

std::number

Number Module

Numeric helpers built on top of std::math.

Namespaces

Number — absolute value

Input type Return type Notes
i8 u8 Widens to i16 internally
i16 u16 Widens to i32 internally
i32 u32 Widens to i64 internally
i64 u64 Handles MIN without overflow
f32 f32 Simple negation
f64 f64 Delegates to Math::fabs

All overloads are @extension methods and can be called as Number::abs(value).

Float — rounding helpers

Method Types Description
toFixed f64, f32 Round to digits decimal places
round f64, f32 Round to nearest integer
floor f64, f32 Round toward negative infinity
ceil f64, f32 Round toward positive infinity

f32 overloads widen to f64, delegate to Math, then narrow back.

Example

import Number, Float from "std::number";
import Io from "std::io";
import String from "std::string";

function main(): i32 {
  let a: u32 = Number::abs(-42);
  let b: f64 = Float::toFixed(3.141592, 2);
  let c: f32 = Float::ceil(2.2);

  Io::println(String::toString(a));
  Io::println(String::toString(b));
  Io::println(String::toString(c));
  return 0;
}
namespace Float

Floating-point formatting and rounding helpers.

Functions in this namespace complement Number with operations specific to decimal floating-point presentation.

Functions

function ceil(value: f64): f64

Rounds up to the nearest integer.

Example

import Float from "std::number";

let x: f64 = Float::ceil(2.1);
function ceil(value: f64): f64

Rounds up to the nearest integer.

Example

import Float from "std::number";

let x: f64 = Float::ceil(2.1);
function floor(value: f64): f64

Rounds down to the nearest integer.

Example

import Float from "std::number";

let x: f64 = Float::floor(2.9);
function floor(value: f64): f64

Rounds down to the nearest integer.

Example

import Float from "std::number";

let x: f64 = Float::floor(2.9);
function round(value: f64): f64

Rounds to the nearest integer.

Example

import Float from "std::number";

let x: f64 = Float::round(2.6);
function round(value: f64): f64

Rounds to the nearest integer.

Example

import Float from "std::number";

let x: f64 = Float::round(2.6);
function toFixed(value: f32, digits: u32): f32

Rounds value to digits decimal places.

Example

import Float from "std::number";

let x: f32 = Float::toFixed(3.141592 as f32, 2);
function toFixed(value: f32, digits: u32): f32

Rounds value to digits decimal places.

Example

import Float from "std::number";

let x: f32 = Float::toFixed(3.141592 as f32, 2);
namespace Number

Numeric helpers for integer and floating-point values.

The namespace currently provides absolute-value overloads that avoid signed overflow for minimum integer values by returning unsigned magnitudes.

Functions

function abs(value: f64): f64

Returns the absolute value of an f64.

Example

import Number from "std::number";

let x: f64 = Number::abs(-3.5);
function abs(value: f64): f64

Returns the absolute value of an f64.

Example

import Number from "std::number";

let x: f64 = Number::abs(-3.5);
function abs(value: f64): f64

Returns the absolute value of an f64.

Example

import Number from "std::number";

let x: f64 = Number::abs(-3.5);
function abs(value: f64): f64

Returns the absolute value of an f64.

Example

import Number from "std::number";

let x: f64 = Number::abs(-3.5);
function abs(value: f64): f64

Returns the absolute value of an f64.

Example

import Number from "std::number";

let x: f64 = Number::abs(-3.5);
function abs(value: f64): f64

Returns the absolute value of an f64.

Example

import Number from "std::number";

let x: f64 = Number::abs(-3.5);