math
Generated by tinox doc
tinox.core.math, bundled with the compiler and also available as a standalone tinox-central package.
Basic helpers
import tinox.core.math
class Main
{
fnc main() -> Int32
{
println("pi = " + Math::pi().toString())
println("abs(-5) = " + Math::abs(-5).toString())
println("max(3, 7) = " + Math::max(3, 7).toString())
println("2^10 = " + Math::pow(2, 10).toString())
println("5! = " + Math::factorial(5).toString())
return 0
}
}
@Errorclass ArithmeticError
* Invalid argument, Int64 overflow or division by zero in a `Math` function.
Fields
message | String |
class Math
* Math helper class with common mathematical operations * including constants, arithmetic, power functions, and random number generation
Methods
fn pi() → Float64
* Returns the value of pi (3.14159...)
* @return the mathematical constant pi
fn e() → Float64
* Returns Euler's number (2.71828...)
* @return the mathematical constant e
fn tau() → Float64
* Returns tau (2 * pi = 6.28318...)
* @return the mathematical constant tau
fn abs(x: Int64) → Int64
* Returns the absolute value of x
* @param x the input value
* @return the absolute value (always non-negative)
fn min(a: Int64, b: Int64) → Int64
* Returns the smaller of two values
* @param a the first value
* @param b the second value
* @return a if a < b, otherwise b
fn max(a: Int64, b: Int64) → Int64
* Returns the larger of two values
* @param a the first value
* @param b the second value
* @return a if a > b, otherwise b
fn square(x: Int64) → Int64
* Returns x squared (x * x)
* @param x the input value
* @return x multiplied by itself
@Throwsfn pow(base: Int64, exp: Int64) → Int64
* Returns base raised to the power of exp
* @param base the base value
* @param exp the exponent (must be non-negative)
* @return base raised to the power of exp
@Throwsfn factorial(n: Int64) → Int64
* Returns the factorial of n (n!)
* Computes n * (n-1) * ... * 2 * 1.
* @param n the input value (must be non-negative)
* @return n factorial; throws on a negative argument or Int64 overflow
@Throwsfn addChecked(a: Int64, b: Int64) → Int64
* a + b, throwing instead of silently wrapping on Int64 overflow.
@Throwsfn subChecked(a: Int64, b: Int64) → Int64
* a - b, throwing instead of silently wrapping on Int64 overflow.
@Throwsfn divChecked(a: Int64, b: Int64) → Int64
* a / b, throwing on division by zero and on Int64.MIN / -1.
@Throwsfn remChecked(a: Int64, b: Int64) → Int64
* a % b, throwing on division by zero.
@Throwsfn mulChecked(a: Int64, b: Int64) → Int64
* a * b, throwing instead of silently wrapping on Int64 overflow.
fn randomSeed(seed: Int64) → Int64
* Generates a pseudo-random number from a seed
* Uses a linear congruential generator (LCG) algorithm.
* The same seed always produces the same result.
* @param seed the seed value
* @return a pseudo-random integer