aboutsummaryrefslogtreecommitdiff
path: root/core/math.odin
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-07-20 19:40:51 +0100
committerGinger Bill <bill@gingerbill.org>2017-07-20 19:40:51 +0100
commit9a3b4167bb8495f9422ffa5cb242198fed3a315b (patch)
treed5e1f4fe1ff66282cb67896c7c432a487b5a55df /core/math.odin
parent13bc6eeea4cc89b06bcfc3aaef7bfb85c1cb5b01 (diff)
Fix polymorphic element types usage; Empty `union` as opaque type
Diffstat (limited to 'core/math.odin')
-rw-r--r--core/math.odin25
1 files changed, 14 insertions, 11 deletions
diff --git a/core/math.odin b/core/math.odin
index bf85b5026..04af9593a 100644
--- a/core/math.odin
+++ b/core/math.odin
@@ -54,8 +54,8 @@ unlerp :: proc(a, b, x: f32) -> (t: f32) do return (x-a)/(b-a);
unlerp :: proc(a, b, x: f64) -> (t: f64) do return (x-a)/(b-a);
-sign :: proc(x: f32) -> f32 do return x >= 0 ? +1 : -1;
-sign :: proc(x: f64) -> f64 do return x >= 0 ? +1 : -1;
+sign :: proc(x: f32) -> f32 { if x >= 0 do return +1; return -1; }
+sign :: proc(x: f64) -> f64 { if x >= 0 do return +1; return -1; }
@@ -75,14 +75,14 @@ copy_sign :: proc(x, y: f64) -> f64 {
return transmute(f64, ix);
}
-round :: proc(x: f32) -> f32 do return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
-round :: proc(x: f64) -> f64 do return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
+round :: proc(x: f32) -> f32 { if x >= 0 do return floor(x + 0.5); return ceil(x - 0.5); }
+round :: proc(x: f64) -> f64 { if x >= 0 do return floor(x + 0.5); return ceil(x - 0.5); }
-floor :: proc(x: f32) -> f32 do return x >= 0 ? f32(i64(x)) : f32(i64(x-0.5)); // TODO: Get accurate versions
-floor :: proc(x: f64) -> f64 do return x >= 0 ? f64(i64(x)) : f64(i64(x-0.5)); // TODO: Get accurate versions
+floor :: proc(x: f32) -> f32 { if x >= 0 do f32(i64(x)) return f32(i64(x-0.5)); } // TODO: Get accurate versions
+floor :: proc(x: f64) -> f64 { if x >= 0 do f64(i64(x)) return f64(i64(x-0.5)); } // TODO: Get accurate versions
-ceil :: proc(x: f32) -> f32 do return x < 0 ? f32(i64(x)) : f32(i64(x+1)); // TODO: Get accurate versions
-ceil :: proc(x: f64) -> f64 do return x < 0 ? f64(i64(x)) : f64(i64(x+1)); // TODO: Get accurate versions
+ceil :: proc(x: f32) -> f32 { if x < 0 do f32(i64(x)) return f32(i64(x+1)); }// TODO: Get accurate versions
+ceil :: proc(x: f64) -> f64 { if x < 0 do f64(i64(x)) return f64(i64(x+1)); }// TODO: Get accurate versions
remainder :: proc(x, y: f32) -> f32 do return x - round(x/y) * y;
remainder :: proc(x, y: f64) -> f64 do return x - round(x/y) * y;
@@ -133,17 +133,20 @@ norm :: proc(v: $T/[vector 4]$E) -> T do return v / mag(v);
norm0 :: proc(v: $T/[vector 2]$E) -> T {
m := mag(v);
- return m == 0 ? 0 : v/m;
+ if m == 0 do return 0;
+ return v/m;
}
norm0 :: proc(v: $T/[vector 3]$E) -> T {
m := mag(v);
- return m == 0 ? 0 : v/m;
+ if m == 0 do return 0;
+ return v/m;
}
norm0 :: proc(v: $T/[vector 4]$E) -> T {
m := mag(v);
- return m == 0 ? 0 : v/m;
+ if m == 0 do return 0;
+ return v/m;
}