forked from ocen-lang/ocen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath.oc
More file actions
73 lines (56 loc) · 2.75 KB
/
Copy pathmath.oc
File metadata and controls
73 lines (56 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Common math functions
@compiler c_flag "-lm"
@compiler c_include "math.h"
[extern "sqrtf"] def f32::sqrt(this): f32
[extern "cosf"] def f32::cos(this): f32
[extern "sinf"] def f32::sin(this): f32
[extern "tanf"] def f32::tan(this): f32
[extern "atan2f"] def f32::atan2(this, y: f32): f32
[extern "asin"] def f32::asin(this): f32
[extern "acos"] def f32::acos(this): f32
[extern "logf"] def f32::log(this): f32
[extern "log2f"] def f32::log2(this): f32
[extern "ceilf"] def f32::ceil(this): f32
[extern "floorf"] def f32::floor(this): f32
[extern "isnan"] def f32::isnan(this): bool
[extern "exp"] def f32::exp(this): f32
[extern "INFINITY"] const INFINITY: f64
def f32::inf(): f32 => INFINITY as f32
def f64::inf(): f64 => INFINITY
[extern "sqrt"] def f64::sqrt(this): f64
[extern "cos"] def f64::cos(this): f64
[extern "sin"] def f64::sin(this): f64
[extern "tan"] def f64::tan(this): f64
[extern "atan2"] def f64::atan2(this, y: f64): f64
[extern "log"] def f64::log(this): f64
[extern "log2"] def f64::log2(this): f64
[extern "ceil"] def f64::ceil(this): f64
[extern "floor"] def f64::floor(this): f64
[extern "fabsf"] def f32::abs(this): f32
[extern "fabs"] def f64::abs(this): f64
[extern "rand"] def randint(): i32
[extern "drand48"] def rand01(): f32
[extern "powf"] def f32::pow(this, exp: f32): f32
[extern "pow"] def f64::pow(this, exp: f64): f64
[operator "%"] [extern "fmodf"] def f32::mod(this, b: f32): f32
[operator "%"] [extern "fmod"] def f64::mod(this, b: f64): f64
def f32::min(this, b: f32): f32 => if this < b then this else b
def f32::max(this, b: f32): f32 => if this > b then this else b
def f64::min(this, b: f64): f64 => if this < b then this else b
def f64::max(this, b: f64): f64 => if this > b then this else b
def i32::clamp(this, min: i32, max: i32): i32 => i32::max(i32::min(this, max), min)
def u32::clamp(this, min: u32, max: u32): u32 => u32::max(u32::min(this, max), min)
def f32::clamp(this, min: f32, max: f32): f32 => f32::max(f32::min(this, max), min)
def f32::clamp01(this): f32 => this.clamp(0.0, 1.0)
def f64::clamp(this, min: f64, max: f64): f64 => f64::max(f64::min(this, max), min)
def f64::clamp01(this): f64 => this.clamp(0.0, 1.0)
def f32::is_close(this, other: f32, thresh: f32 = 0.0001): bool => (this - other).abs() < thresh
def f64::is_close(this, other: f64, thresh: f64 = 0.0001): bool => (this - other).abs() < thresh
def i8::abs(this): i8 => if this < 0 then -this else this
def i16::abs(this): i16 => if this < 0 then -this else this
def i32::abs(this): i32 => if this < 0 then -this else this
def i64::abs(this): i64 => if this < 0 then -this else this
[extern "M_PI"] const PI: f32
const TAU: f32 = PI * 2.0
def degrees(radians: f32): f32 { return radians * 180.0 / PI; }
def radians(degrees: f32): f32 { return degrees * PI / 180.0; }