README

#mizchi/js/builtins/math

Mathematical operations with JavaScript's Math API.

#Installation

Add to your moon.pkg.json:

{ "import": [ "mizchi/js", "mizchi/js/builtins/math" ] }

#Overview

Provides bindings for JavaScript's Math object for mathematical operations and constants.

#Usage Example

fn main {
// Basic operations
let abs_val = @math.abs(-5.5) // 5.5
let rounded = @math.round(3.7) // 4.0
let power = @math.pow(2.0, 3.0) // 8.0

// Trigonometry
let sine = @math.sin(0.0) // 0.0
let cosine = @math.cos(0.0) // 1.0

// Random
let random = @math.random() // 0.0 <= x < 1.0

// Constants
let pi = @math.PI
let e = @math.E
}

#Available Functions

  • Rounding: abs, ceil, floor, round, trunc
  • Power/Roots: pow, sqrt, cbrt, exp, log
  • Trigonometry: sin, cos, tan, asin, acos, atan, atan2
  • Min/Max: min, max
  • Random: random

#Reference

#
Math

#external
pub type Math

#
Math::abs

fn Math::abs(x : Double) -> Double

JS: Math.abs(x)

#
Math::acos

fn Math::acos(x : Double) -> Double

JS: Math.acos(x)

#
Math::acosh

fn Math::acosh(x : Double) -> Double

JS: Math.acosh(x) - Inverse hyperbolic cosine

#
Math::asin

fn Math::asin(x : Double) -> Double

JS: Math.asin(x)

#
Math::asinh

fn Math::asinh(x : Double) -> Double

JS: Math.asinh(x) - Inverse hyperbolic sine

#
Math::atan

fn Math::atan(x : Double) -> Double

JS: Math.atan(x)

#
Math::atan2

fn Math::atan2(y : Double, x : Double) -> Double

JS: Math.atan2(y, x)

#
Math::atanh

fn Math::atanh(x : Double) -> Double

JS: Math.atanh(x) - Inverse hyperbolic tangent

#
Math::cbrt

fn Math::cbrt(x : Double) -> Double

JS: Math.cbrt(x) - Cube root

#
Math::ceil

fn Math::ceil(x : Double) -> Int

JS: Math.ceil(x)

#
Math::clz32

fn Math::clz32(x : Int) -> Int

JS: Math.clz32(x) - Count leading zeros in 32-bit binary

#
Math::cos

fn Math::cos(x : Double) -> Double

JS: Math.cos(x)

#
Math::cosh

fn Math::cosh(x : Double) -> Double

JS: Math.cosh(x) - Hyperbolic cosine

#
Math::e

fn Math::e() -> Double

JS: Math.E - Euler's number (approximately 2.718)

#
Math::exp

fn Math::exp(x : Double) -> Double

JS: Math.exp(x)

#
Math::expm1

fn Math::expm1(x : Double) -> Double

JS: Math.expm1(x) - e^x - 1

#
Math::floor

fn Math::floor(x : Double) -> Int

JS: Math.floor(x)

#
Math::fround

fn Math::fround(x : Double) -> Double

JS: Math.fround(x) - Round to nearest 32-bit float

#
Math::hypot

fn Math::hypot(values : Array[Double]) -> Double

JS: Math.hypot(...values) - Square root of sum of squares

#
Math::imul

fn Math::imul(a : Int, b : Int) -> Int

JS: Math.imul(a, b) - 32-bit integer multiplication

#
Math::ln10

fn Math::ln10() -> Double

JS: Math.LN10 - Natural logarithm of 10 (approximately 2.303)

#
Math::ln2

fn Math::ln2() -> Double

JS: Math.LN2 - Natural logarithm of 2 (approximately 0.693)

#
Math::log

fn Math::log(x : Double) -> Double

JS: Math.log(x)

#
Math::log10

fn Math::log10(x : Double) -> Double

JS: Math.log10(x) - Base-10 logarithm

#
Math::log10e

fn Math::log10e() -> Double

JS: Math.LOG10E - Base-10 logarithm of E (approximately 0.434)

#
Math::log1p

fn Math::log1p(x : Double) -> Double

JS: Math.log1p(x) - Natural logarithm of 1 + x

#
Math::log2

fn Math::log2(x : Double) -> Double

JS: Math.log2(x) - Base-2 logarithm

#
Math::log2e

fn Math::log2e() -> Double

JS: Math.LOG2E - Base-2 logarithm of E (approximately 1.443)

#
Math::max

fn Math::max(values : Array[Double]) -> Double

JS: Math.max(...values)

#
Math::min

fn Math::min(values : Array[Double]) -> Double

JS: Math.min(...values)

#
Math::pi

fn Math::pi() -> Double

JS: Math.PI - Pi (approximately 3.14159)

#
Math::pow

fn Math::pow(base : Double, exp : Double) -> Double

JS: Math.pow(base, exp)

#
Math::random

fn Math::random() -> Double

JS: Math.random()

#
Math::round

fn Math::round(x : Double) -> Int

JS: Math.round(x)

#
Math::sign

fn Math::sign(x : Double) -> Double

JS: Math.sign(x)

#
Math::sin

fn Math::sin(x : Double) -> Double

JS: Math.sin(x)

#
Math::sinh

fn Math::sinh(x : Double) -> Double

JS: Math.sinh(x) - Hyperbolic sine

#
Math::sqrt

fn Math::sqrt(x : Double) -> Double

JS: Math.sqrt(x)

#
Math::sqrt1_2

fn Math::sqrt1_2() -> Double

JS: Math.SQRT1_2 - Square root of 1/2 (approximately 0.707)

#
Math::sqrt2

fn Math::sqrt2() -> Double

JS: Math.SQRT2 - Square root of 2 (approximately 1.414)

#
Math::tan

fn Math::tan(x : Double) -> Double

JS: Math.tan(x)

#
Math::tanh

fn Math::tanh(x : Double) -> Double

JS: Math.tanh(x)

#
Math::trunc

fn Math::trunc(x : Double) -> Double

JS: Math.trunc(x)

Source Files