aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/math/unsafe.js.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/unsafe.js.v
downloadcli-tools-windows-master.tar.gz
cli-tools-windows-master.tar.bz2
cli-tools-windows-master.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/vlib/math/unsafe.js.v')
-rw-r--r--v_windows/v/vlib/math/unsafe.js.v59
1 files changed, 59 insertions, 0 deletions
diff --git a/v_windows/v/vlib/math/unsafe.js.v b/v_windows/v/vlib/math/unsafe.js.v
new file mode 100644
index 0000000..38ee167
--- /dev/null
+++ b/v_windows/v/vlib/math/unsafe.js.v
@@ -0,0 +1,59 @@
+module math
+
+// f32_bits returns the IEEE 754 binary representation of f,
+// with the sign bit of f and the result in the same bit position.
+// f32_bits(f32_from_bits(x)) == x.
+pub fn f32_bits(f f32) u32 {
+ p := u32(0)
+ #let buffer = new ArrayBuffer(4)
+ #let floatArr = new Float32Array(buffer)
+ #floatArr[0] = f.val
+ #let uintArr = new Uint32Array(buffer)
+ #p.val = uintArr[0]
+
+ return p
+}
+
+// f32_from_bits returns the floating-point number corresponding
+// to the IEEE 754 binary representation b, with the sign bit of b
+// and the result in the same bit position.
+// f32_from_bits(f32_bits(x)) == x.
+pub fn f32_from_bits(b u32) f32 {
+ p := f32(0.0)
+ #let buffer = new ArrayBuffer(4)
+ #let floatArr = new Float32Array(buffer)
+ #let uintArr = new Uint32Array(buffer)
+ #uintArr[0] = Number(b.val)
+ #p.val = floatArr[0]
+
+ return p
+}
+
+// f64_bits returns the IEEE 754 binary representation of f,
+// with the sign bit of f and the result in the same bit position,
+// and f64_bits(f64_from_bits(x)) == x.
+pub fn f64_bits(f f64) u64 {
+ p := u64(0)
+ #let buffer = new ArrayBuffer(8)
+ #let floatArr = new Float64Array(buffer)
+ #floatArr[0] = f.val
+ #let uintArr = new BigUint64Array(buffer)
+ #p.val = uintArr[0]
+
+ return p
+}
+
+// f64_from_bits returns the floating-point number corresponding
+// to the IEEE 754 binary representation b, with the sign bit of b
+// and the result in the same bit position.
+// f64_from_bits(f64_bits(x)) == x.
+pub fn f64_from_bits(b u64) f64 {
+ p := 0.0
+ #let buffer = new ArrayBuffer(8)
+ #let floatArr = new Float64Array(buffer)
+ #let uintArr = new BigUint64Array(buffer)
+ #uintArr[0] = Number(b.val)
+ #p.val = floatArr[0]
+
+ return p
+}