aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/math/modf.v
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/math/modf.v
downloadcli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/vlib/math/modf.v')
-rw-r--r--v_windows/v/vlib/math/modf.v29
1 files changed, 29 insertions, 0 deletions
diff --git a/v_windows/v/vlib/math/modf.v b/v_windows/v/vlib/math/modf.v
new file mode 100644
index 0000000..bac08bf
--- /dev/null
+++ b/v_windows/v/vlib/math/modf.v
@@ -0,0 +1,29 @@
+module math
+
+const (
+ modf_maxpowtwo = 4.503599627370496000e+15
+)
+
+// modf returns integer and fractional floating-point numbers
+// that sum to f. Both values have the same sign as f.
+//
+// special cases are:
+// modf(±inf) = ±inf, nan
+// modf(nan) = nan, nan
+pub fn modf(f f64) (f64, f64) {
+ abs_f := abs(f)
+ mut i := 0.0
+ if abs_f >= math.modf_maxpowtwo {
+ i = f // it must be an integer
+ } else {
+ i = abs_f + math.modf_maxpowtwo // shift fraction off right
+ i -= math.modf_maxpowtwo // shift back without fraction
+ for i > abs_f { // above arithmetic might round
+ i -= 1.0 // test again just to be sure
+ }
+ if f < 0.0 {
+ i = -i
+ }
+ }
+ return i, f - i // signed fractional part
+}