← Back to the index

Module std/float.vv

The float module provides standard utilities for floating-point numbers.

Example:

import float from "std/float.vv"

let s = float.to_string(3.14) // "3.14"
let f = float.floor(3.9)      // 3.0

Table of Contents

Exports

fun to_string(f) extern "native"

Converts a floating-point number to its string representation.

Example:

let s = float.to_string(3.14) // "3.14"

fun floor(f) extern "native"

Returns the largest integer less than or equal to f.

Example:

let f = float.floor(3.7)  // 3.0
let g = float.floor(-3.2) // -4.0

fun ceil(f) extern "native"

Returns the smallest integer greater than or equal to f.

Example:

let f = float.ceil(3.2)  // 4.0
let g = float.ceil(-3.7) // -3.0

fun from_int(i) extern "native"

Converts an integer to a floating-point number.

Example:

let f = float.from_int(42) // 42.0

fun round(f) extern "native"

Returns the nearest integer to f, rounding half away from zero.

Example:

let f = float.round(3.5)  // 4.0
let g = float.round(-3.5) // -4.0

fun abs(f) extern "native"

Returns the absolute value of f.

Example:

let f = float.abs(-5.5) // 5.5
let g = float.abs(5.5)  // 5.5

fun min(a, b) extern "native"

Returns the smaller of a and b.

Example:

let m = float.min(10.5, 5.2) // 5.2

fun max(a, b) extern "native"

Returns the larger of a and b.

Example:

let m = float.max(10.5, 5.2) // 10.5