peon/src/peon/stdlib/math.pn

38 lines
596 B
Plaintext

## Peon's math module
import std;
const pi* = 3.141592653589793;
const e* = 2.718281828459045;
const tau* = 6.283185307179586;
fn abs*[T: SignedInteger](n: T): T {
## Returns the absolute value of
## the given number
if n < 0 {
return -n;
}
return n;
}
fn abs*(f: float64): float64 {
## Returns the absolute value of
## the given number
if f < 0.0 {
return -f;
}
return f;
}
fn abs*(f: float32): float32 {
## Returns the absolute value of
## the given number
if f < 0.0'f32 {
return -f;
}
return f;
}