1212 */
1313module Float64
1414
15+ from "runtime/unsafe/offsets" include Offsets
16+ use Offsets.{
17+ _FLOAT64_VALUE_OFFSET as _VALUE_OFFSET,
18+ _INT64_VALUE_OFFSET,
19+ _UINT64_VALUE_OFFSET,
20+ }
1521from "runtime/unsafe/wasmi32" include WasmI32
1622from "runtime/unsafe/wasmf64" include WasmF64
1723use WasmF64.{ (-), (+), (*), (/), (<), (<=), (>), (>=) }
@@ -26,9 +32,6 @@ use Numbers.{
2632from "runtime/math/trig" include Trig
2733use Trig.{ sin, cos, tan }
2834
29- @unsafe
30- let _VALUE_OFFSET = 8n
31-
3235/**
3336 * Infinity represented as a Float64 value.
3437 * This is an alternative to the `Infinityd` literal.
@@ -70,6 +73,42 @@ provide let e = 2.718281828459045d
7073
7174provide { fromNumber, toNumber }
7275
76+ /**
77+ * Interprets an Int64 as a Float64.
78+ *
79+ * @param value: The value to convert
80+ * @returns The Int64 interpreted as an Float64
81+ *
82+ * @example assert Float64.reinterpretInt64(4607182418800017408L) == 1.0d
83+ * @example assert Float64.reinterpretInt64(-4616189618054758400L) == -1.0d
84+ *
85+ * @since v0.7.0
86+ */
87+ @unsafe
88+ provide let reinterpretInt64 = (value: Int64) => {
89+ let x = WasmF64.load(WasmI32.fromGrain(value), _INT64_VALUE_OFFSET)
90+ let result = newFloat64(x)
91+ WasmI32.toGrain(result): Float64
92+ }
93+
94+ /**
95+ * Interprets an Uint64 as a Float64.
96+ *
97+ * @param value: The value to convert
98+ * @returns The Uint64 interpreted as an Float64
99+ *
100+ * @example assert Float64.reinterpretUint64(4607182418800017408uL) == 1.0d
101+ * @example assert Float64.reinterpretUint64(13830554455654793216uL) == -1.0d
102+ *
103+ * @since v0.7.0
104+ */
105+ @unsafe
106+ provide let reinterpretUint64 = (value: Uint64) => {
107+ let x = WasmF64.load(WasmI32.fromGrain(value), _UINT64_VALUE_OFFSET)
108+ let result = newFloat64(x)
109+ WasmI32.toGrain(result): Float64
110+ }
111+
73112/**
74113 * Computes the sum of its operands.
75114 *
0 commit comments