Skip to content

Commit 6df63c4

Browse files
authored
fix: Fix MIN_NORMAL_VALUE definitions and unify f32/F32, f64/F64 constants (#1443)
1 parent 45bfe04 commit 6df63c4

File tree

6 files changed

+77
-19
lines changed

6 files changed

+77
-19
lines changed

std/assembly/builtins.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export declare function assert<T>(isTrueish: T, message?: string): T;
168168
@unsafe @builtin
169169
export declare function unchecked<T>(expr: T): T;
170170

171-
// @ts-ignore: decorator
171+
// @ts-ignore: decorator
172172
@unsafe @builtin
173173
export declare function call_indirect<T>(index: u32, ...args: auto[]): T;
174174

@@ -846,6 +846,18 @@ export namespace f32 {
846846
@lazy
847847
export const MAX_SAFE_INTEGER: f32 = 16777215;
848848

849+
// @ts-ignore: decorator
850+
@lazy
851+
export const POSITIVE_INFINITY: f32 = Infinity;
852+
853+
// @ts-ignore: decorator
854+
@lazy
855+
export const NEGATIVE_INFINITY: f32 = -Infinity;
856+
857+
// @ts-ignore: decorator
858+
@lazy
859+
export const NaN: f32 = 0.0 / 0.0;
860+
849861
// @ts-ignore: decorator
850862
@builtin
851863
export declare function abs(value: f32): f32;
@@ -925,6 +937,18 @@ export namespace f64 {
925937
@lazy
926938
export const MAX_SAFE_INTEGER: f64 = 9007199254740991;
927939

940+
// @ts-ignore: decorator
941+
@lazy
942+
export const POSITIVE_INFINITY: f64 = Infinity;
943+
944+
// @ts-ignore: decorator
945+
@lazy
946+
export const NEGATIVE_INFINITY: f64 = -Infinity;
947+
948+
// @ts-ignore: decorator
949+
@lazy
950+
export const NaN: f64 = 0.0 / 0.0;
951+
928952
// @ts-ignore: decorator
929953
@builtin
930954
export declare function abs(value: f64): f64;

std/assembly/index.d.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,17 @@ declare namespace f32 {
506506
/** Largest representable value. */
507507
export const MAX_VALUE: f32;
508508
/** Smallest normalized positive value. */
509-
export const MIN_POSITIVE_VALUE: f32;
509+
export const MIN_NORMAL_VALUE: f32;
510510
/** Smallest safely representable integer value. */
511511
export const MIN_SAFE_INTEGER: f32;
512512
/** Largest safely representable integer value. */
513513
export const MAX_SAFE_INTEGER: f32;
514+
/** Positive infinity value. */
515+
export const POSITIVE_INFINITY: f32;
516+
/** Negative infinity value. */
517+
export const NEGATIVE_INFINITY: f32;
518+
/** Not a number value. */
519+
export const NaN: f32;
514520
/** Difference between 1 and the smallest representable value greater than 1. */
515521
export const EPSILON: f32;
516522
/** Loads a 32-bit float from memory. */
@@ -526,11 +532,17 @@ declare namespace f64 {
526532
/** Largest representable value. */
527533
export const MAX_VALUE: f64;
528534
/** Smallest normalized positive value. */
529-
export const MIN_POSITIVE_VALUE: f64;
535+
export const MIN_NORMAL_VALUE: f64;
530536
/** Smallest safely representable integer value. */
531537
export const MIN_SAFE_INTEGER: f64;
532538
/** Largest safely representable integer value. */
533539
export const MAX_SAFE_INTEGER: f64;
540+
/** Positive infinity value. */
541+
export const POSITIVE_INFINITY: f64;
542+
/** Negative infinity value. */
543+
export const NEGATIVE_INFINITY: f64;
544+
/** Not a number value. */
545+
export const NaN: f64;
534546
/** Difference between 1 and the smallest representable value greater than 1. */
535547
export const EPSILON: f64;
536548
/** Loads a 64-bit float from memory. */

std/assembly/number.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,15 @@ export abstract class F32 {
268268

269269
// @ts-ignore: decorator
270270
@lazy
271-
static readonly POSITIVE_INFINITY: f32 = Infinity;
271+
static readonly POSITIVE_INFINITY: f32 = f32.POSITIVE_INFINITY;
272272

273273
// @ts-ignore: decorator
274274
@lazy
275-
static readonly NEGATIVE_INFINITY: f32 = -Infinity;
275+
static readonly NEGATIVE_INFINITY: f32 = f32.NEGATIVE_INFINITY;
276276

277277
// @ts-ignore: decorator
278278
@lazy
279-
static readonly NaN: f32 = NaN;
279+
static readonly NaN: f32 = f32.NaN;
280280

281281
static isNaN(value: f32): bool {
282282
return isNaN<f32>(value);
@@ -332,15 +332,15 @@ export abstract class F64 {
332332

333333
// @ts-ignore: decorator
334334
@lazy
335-
static readonly POSITIVE_INFINITY: f64 = Infinity;
335+
static readonly POSITIVE_INFINITY: f64 = f64.POSITIVE_INFINITY;
336336

337337
// @ts-ignore: decorator
338338
@lazy
339-
static readonly NEGATIVE_INFINITY: f64 = -Infinity;
339+
static readonly NEGATIVE_INFINITY: f64 = f64.NEGATIVE_INFINITY;
340340

341341
// @ts-ignore: decorator
342342
@lazy
343-
static readonly NaN: f64 = NaN;
343+
static readonly NaN: f64 = f64.NaN;
344344

345345
static isNaN(value: f64): bool {
346346
return isNaN<f64>(value);

std/portable/index.d.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,18 @@ declare namespace f32 {
230230
/** Largest representable value. */
231231
export const MAX_VALUE: f32;
232232
/** Smallest normalized positive value. */
233-
export const MIN_POSITIVE_VALUE: f32;
233+
export const MIN_NORMAL_VALUE: f32;
234234
/** Smallest safely representable integer value. */
235235
export const MIN_SAFE_INTEGER: f32;
236236
/** Largest safely representable integer value. */
237237
export const MAX_SAFE_INTEGER: f32;
238+
/** Positive infinity value. */
239+
export const POSITIVE_INFINITY: f32;
240+
/** Negative infinity value. */
241+
export const NEGATIVE_INFINITY: f32;
242+
/** Not a number value. */
243+
/* eslint no-shadow-restricted-names: "off" */
244+
export const NaN: f32;
238245
/** Difference between 1 and the smallest representable value greater than 1. */
239246
export const EPSILON: f32;
240247
/** Returns a boolean value that indicates whether a value is the reserved value NaN (not a number). */
@@ -258,11 +265,18 @@ declare namespace f64 {
258265
/** Largest representable value. */
259266
export const MAX_VALUE: f64;
260267
/** Smallest normalized positive value. */
261-
export const MIN_POSITIVE_VALUE: f64;
268+
export const MIN_NORMAL_VALUE: f64;
262269
/** Smallest safely representable integer value. */
263270
export const MIN_SAFE_INTEGER: f64;
264271
/** Largest safely representable integer value. */
265272
export const MAX_SAFE_INTEGER: f64;
273+
/** Positive infinity value. */
274+
export const POSITIVE_INFINITY: f64;
275+
/** Negative infinity value. */
276+
export const NEGATIVE_INFINITY: f64;
277+
/** Not a number value. */
278+
/* eslint no-shadow-restricted-names: "off" */
279+
export const NaN: f64;
266280
/** Difference between 1 and the smallest representable value greater than 1. */
267281
export const EPSILON: f64;
268282
/** Returns a boolean value that indicates whether a value is the reserved value NaN (not a number). */

std/portable/index.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,30 @@ Object.defineProperties(
7575
Object.defineProperties(
7676
globalScope["f32"] = function f32(value) { return Math.fround(value); },
7777
{
78-
"EPSILON": { value: Math.fround(1.1920929e-07), writable: false },
79-
"MIN_VALUE": { value: Math.fround(1.4012985e-45), writable: false },
80-
"MAX_VALUE": { value: Math.fround(3.4028235e+38), writable: false },
81-
"MIN_NORMAL_VALUE": { value: Math.fround(1.17549435e-38), writable: false },
78+
"EPSILON": { value: 1.1920928955078125e-07, writable: false },
79+
"MIN_VALUE": { value: 1.4012984643248170e-45, writable: false },
80+
"MAX_VALUE": { value: 3.4028234663852886e+38, writable: false },
81+
"MIN_NORMAL_VALUE": { value: 1.1754943508222875e-38, writable: false },
8282
"MIN_SAFE_INTEGER": { value: -16777215, writable: false },
83-
"MAX_SAFE_INTEGER": { value: 16777215, writable: false }
83+
"MAX_SAFE_INTEGER": { value: 16777215, writable: false },
84+
"POSITIVE_INFINITY": { value: Infinity, writable: false },
85+
"NEGATIVE_INFINITY": { value: -Infinity, writable: false },
86+
"NaN": { value: NaN, writable: false }
8487
}
8588
);
8689

8790
Object.defineProperties(
8891
globalScope["f64"] = function f64(value) { return +value; },
8992
{
90-
"EPSILON": { value: 2.2204460492503131e-16, writable: false },
93+
"EPSILON": { value: 2.2204460492503131e-016, writable: false },
9194
"MIN_VALUE": { value: 5e-324, writable: false },
9295
"MAX_VALUE": { value: 1.7976931348623157e+308, writable: false },
93-
"MIN_NORMAL_VALUE": { value: 2.2250738585072014e-308 , writable: false },
96+
"MIN_NORMAL_VALUE": { value: 2.2250738585072014e-308, writable: false },
9497
"MIN_SAFE_INTEGER": { value: -9007199254740991, writable: false },
95-
"MAX_SAFE_INTEGER": { value: 9007199254740991, writable: false }
98+
"MAX_SAFE_INTEGER": { value: 9007199254740991, writable: false },
99+
"POSITIVE_INFINITY": { value: Infinity, writable: false },
100+
"NEGATIVE_INFINITY": { value: -Infinity, writable: false },
101+
"NaN": { value: NaN, writable: false }
96102
}
97103
);
98104

tests/compiler/number.untouched.wat

+2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@
5252
(global $~lib/util/number/_K (mut i32) (i32.const 0))
5353
(global $~lib/util/number/_frc_pow (mut i64) (i64.const 0))
5454
(global $~lib/util/number/_exp_pow (mut i32) (i32.const 0))
55+
(global $~lib/builtins/f32.NaN f32 (f32.const nan:0x400000))
5556
(global $~lib/number/F32.NaN f32 (f32.const nan:0x400000))
5657
(global $~lib/builtins/f32.MIN_SAFE_INTEGER f32 (f32.const -16777215))
5758
(global $~lib/builtins/f32.MAX_SAFE_INTEGER f32 (f32.const 16777215))
5859
(global $~lib/builtins/f32.EPSILON f32 (f32.const 1.1920928955078125e-07))
60+
(global $~lib/builtins/f64.NaN f64 (f64.const nan:0x8000000000000))
5961
(global $~lib/number/F64.NaN f64 (f64.const nan:0x8000000000000))
6062
(global $~lib/builtins/f64.MIN_SAFE_INTEGER f64 (f64.const -9007199254740991))
6163
(global $~lib/builtins/f64.MAX_SAFE_INTEGER f64 (f64.const 9007199254740991))

0 commit comments

Comments
 (0)