diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-03-12 16:42:51 +0000 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-03-12 16:42:51 +0000 |
| commit | aaec8bf423a40f887d43d12403c2e40f187d424c (patch) | |
| tree | 98958a8c7db53197a0176fcc7607bdcad0a4d8c3 /core/math.odin | |
| parent | 0fcbda951aea462248304a7e16f5c4eb9da9939d (diff) | |
windows.odin TYPE_NAME to Type_Name; More SSA work and SSA printing for debugging
Diffstat (limited to 'core/math.odin')
| -rw-r--r-- | core/math.odin | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/core/math.odin b/core/math.odin index f0b53950f..dc5b7ba76 100644 --- a/core/math.odin +++ b/core/math.odin @@ -27,14 +27,14 @@ Mat4 :: [4]Vec4; sqrt :: proc(x: f32) -> f32 #foreign __llvm_core "llvm.sqrt.f32"; sqrt :: proc(x: f64) -> f64 #foreign __llvm_core "llvm.sqrt.f64"; -sin :: proc(x: f32) -> f32 #foreign __llvm_core "llvm.sin.f32"; -sin :: proc(x: f64) -> f64 #foreign __llvm_core "llvm.sin.f64"; +sin :: proc(x: f32) -> f32 #foreign __llvm_core "llvm.sin.f32"; +sin :: proc(x: f64) -> f64 #foreign __llvm_core "llvm.sin.f64"; -cos :: proc(x: f32) -> f32 #foreign __llvm_core "llvm.cos.f32"; -cos :: proc(x: f64) -> f64 #foreign __llvm_core "llvm.cos.f64"; +cos :: proc(x: f32) -> f32 #foreign __llvm_core "llvm.cos.f32"; +cos :: proc(x: f64) -> f64 #foreign __llvm_core "llvm.cos.f64"; -tan :: proc(x: f32) -> f32 #inline { return sin(x)/cos(x); } -tan :: proc(x: f64) -> f64 #inline { return sin(x)/cos(x); } +tan :: proc(x: f32) -> f32 #inline { return sin(x)/cos(x); } +tan :: proc(x: f64) -> f64 #inline { return sin(x)/cos(x); } lerp :: proc(a, b, t: f32) -> f32 { return a*(1-t) + b*t; } lerp :: proc(a, b, t: f64) -> f64 { return a*(1-t) + b*t; } @@ -53,36 +53,42 @@ fmuladd :: proc(a, b, c: f64) -> f64 #foreign __llvm_core "llvm.fmuladd.f64"; copy_sign :: proc(x, y: f32) -> f32 { ix := transmute(u32)x; iy := transmute(u32)y; - ix &= 0x7fffffff; - ix |= iy & 0x80000000; + ix &= 0x7fff_ffff; + ix |= iy & 0x8000_0000; return transmute(f32)ix; } -round :: proc(x: f32) -> f32 { - if x >= 0 { - return floor(x + 0.5); - } - return ceil(x - 0.5); -} -floor :: proc(x: f32) -> f32 { - if x >= 0 { - return cast(f32)cast(int)x; - } - return cast(f32)cast(int)(x-0.5); -} -ceil :: proc(x: f32) -> f32 { - if x < 0 { - return cast(f32)cast(int)x; - } - return cast(f32)cast(int)(x+1); -} -remainder32 :: proc(x, y: f32) -> f32 { - return x - round(x/y) * y; +copy_sign :: proc(x, y: f64) -> f64 { + ix := transmute(u64)x; + iy := transmute(u64)y; + ix &= 0x7fff_ffff_ffff_ff; + ix |= iy & 0x8000_0000_0000_0000; + return transmute(f64)ix; } -fmod32 :: proc(x, y: f32) -> f32 { +round :: proc(x: f32) -> f32 { return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5); } +round :: proc(x: f64) -> f64 { return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5); } + +floor :: proc(x: f32) -> f32 { return x >= 0 ? cast(f32)cast(i64)x : cast(f32)cast(i64)(x-0.5); } // TODO: Get accurate versions +floor :: proc(x: f64) -> f64 { return x >= 0 ? cast(f64)cast(i64)x : cast(f64)cast(i64)(x-0.5); } // TODO: Get accurate versions + +ceil :: proc(x: f32) -> f32 { return x < 0 ? cast(f32)cast(i64)x : cast(f32)cast(i64)(x+1); } // TODO: Get accurate versions +ceil :: proc(x: f64) -> f64 { return x < 0 ? cast(f64)cast(i64)x : cast(f64)cast(i64)(x+1); } // TODO: Get accurate versions + +remainder :: proc(x, y: f32) -> f32 { return x - round(x/y) * y; } +remainder :: proc(x, y: f64) -> f64 { return x - round(x/y) * y; } + +mod :: proc(x, y: f32) -> f32 { + y = abs(y); + result := remainder(abs(x), y); + if sign(result) < 0 { + result += y; + } + return copy_sign(result, x); +} +mod :: proc(x, y: f64) -> f64 { y = abs(y); - result := remainder32(abs(x), y); + result := remainder(abs(x), y); if sign(result) < 0 { result += y; } @@ -95,7 +101,6 @@ to_degrees :: proc(radians: f32) -> f32 { return radians * 360 / TAU; } - dot :: proc(a, b: Vec2) -> f32 { c := a*b; return c.x + c.y; } dot :: proc(a, b: Vec3) -> f32 { c := a*b; return c.x + c.y + c.z; } dot :: proc(a, b: Vec4) -> f32 { c := a*b; return c.x + c.y + c.z + c.w; } |