added: `math.fmod`
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 30 Mar 2023 23:10:30 +0000 (18:10 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 30 Mar 2023 23:10:30 +0000 (18:10 -0500)
core/math/math.onyx

index 43740c2803dbee37fbd73001861bff3967339855..1bb168ed7bea066fb0cbab9c49e17ec7c335b97e 100644 (file)
@@ -249,6 +249,18 @@ ilog2 :: (a: u64) -> u64 {
 }
 
 
+fmod :: #match #local {}
+
+#overload
+fmod :: (x, y: f64) -> f64 {
+    return x - trunc(x / y) * y;
+}
+
+#overload
+fmod :: (x, y: f32) -> f32 {
+    return x - trunc(x / y) * y;
+}
+
 
 // These function are overloaded in order to use the builtin WASM intrinsics for the
 // operation first, and then default to a polymorphic function that works on any type.