Skip to content

fix: MIN_NORMAL_VALUE and add POSITIVE_INFINITY/NEGATIVE_INFINITY #1443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion std/assembly/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export declare function assert<T>(isTrueish: T, message?: string): T;
@unsafe @builtin
export declare function unchecked<T>(expr: T): T;

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

Expand Down Expand Up @@ -846,6 +846,18 @@ export namespace f32 {
@lazy
export const MAX_SAFE_INTEGER: f32 = 16777215;

// @ts-ignore: decorator
@lazy
export const POSITIVE_INFINITY: f32 = Infinity;

// @ts-ignore: decorator
@lazy
export const NEGATIVE_INFINITY: f32 = -Infinity;

// @ts-ignore: decorator
@lazy
export const NaN: f32 = 0.0 / 0.0;

// @ts-ignore: decorator
@builtin
export declare function abs(value: f32): f32;
Expand Down Expand Up @@ -925,6 +937,18 @@ export namespace f64 {
@lazy
export const MAX_SAFE_INTEGER: f64 = 9007199254740991;

// @ts-ignore: decorator
@lazy
export const POSITIVE_INFINITY: f64 = Infinity;

// @ts-ignore: decorator
@lazy
export const NEGATIVE_INFINITY: f64 = -Infinity;

// @ts-ignore: decorator
@lazy
export const NaN: f64 = 0.0 / 0.0;

// @ts-ignore: decorator
@builtin
export declare function abs(value: f64): f64;
Expand Down
16 changes: 14 additions & 2 deletions std/assembly/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,17 @@ declare namespace f32 {
/** Largest representable value. */
export const MAX_VALUE: f32;
/** Smallest normalized positive value. */
export const MIN_POSITIVE_VALUE: f32;
export const MIN_NORMAL_VALUE: f32;
/** Smallest safely representable integer value. */
export const MIN_SAFE_INTEGER: f32;
/** Largest safely representable integer value. */
export const MAX_SAFE_INTEGER: f32;
/** Positive infinity value. */
export const POSITIVE_INFINITY: f32;
/** Negative infinity value. */
export const NEGATIVE_INFINITY: f32;
/** Not a number value. */
export const NaN: f32;
/** Difference between 1 and the smallest representable value greater than 1. */
export const EPSILON: f32;
/** Loads a 32-bit float from memory. */
Expand All @@ -526,11 +532,17 @@ declare namespace f64 {
/** Largest representable value. */
export const MAX_VALUE: f64;
/** Smallest normalized positive value. */
export const MIN_POSITIVE_VALUE: f64;
export const MIN_NORMAL_VALUE: f64;
/** Smallest safely representable integer value. */
export const MIN_SAFE_INTEGER: f64;
/** Largest safely representable integer value. */
export const MAX_SAFE_INTEGER: f64;
/** Positive infinity value. */
export const POSITIVE_INFINITY: f64;
/** Negative infinity value. */
export const NEGATIVE_INFINITY: f64;
/** Not a number value. */
export const NaN: f64;
/** Difference between 1 and the smallest representable value greater than 1. */
export const EPSILON: f64;
/** Loads a 64-bit float from memory. */
Expand Down
12 changes: 6 additions & 6 deletions std/assembly/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,15 @@ export abstract class F32 {

// @ts-ignore: decorator
@lazy
static readonly POSITIVE_INFINITY: f32 = Infinity;
static readonly POSITIVE_INFINITY: f32 = f32.POSITIVE_INFINITY;

// @ts-ignore: decorator
@lazy
static readonly NEGATIVE_INFINITY: f32 = -Infinity;
static readonly NEGATIVE_INFINITY: f32 = f32.NEGATIVE_INFINITY;

// @ts-ignore: decorator
@lazy
static readonly NaN: f32 = NaN;
static readonly NaN: f32 = f32.NaN;

static isNaN(value: f32): bool {
return isNaN<f32>(value);
Expand Down Expand Up @@ -332,15 +332,15 @@ export abstract class F64 {

// @ts-ignore: decorator
@lazy
static readonly POSITIVE_INFINITY: f64 = Infinity;
static readonly POSITIVE_INFINITY: f64 = f64.POSITIVE_INFINITY;

// @ts-ignore: decorator
@lazy
static readonly NEGATIVE_INFINITY: f64 = -Infinity;
static readonly NEGATIVE_INFINITY: f64 = f64.NEGATIVE_INFINITY;

// @ts-ignore: decorator
@lazy
static readonly NaN: f64 = NaN;
static readonly NaN: f64 = f64.NaN;

static isNaN(value: f64): bool {
return isNaN<f64>(value);
Expand Down
18 changes: 16 additions & 2 deletions std/portable/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,18 @@ declare namespace f32 {
/** Largest representable value. */
export const MAX_VALUE: f32;
/** Smallest normalized positive value. */
export const MIN_POSITIVE_VALUE: f32;
export const MIN_NORMAL_VALUE: f32;
/** Smallest safely representable integer value. */
export const MIN_SAFE_INTEGER: f32;
/** Largest safely representable integer value. */
export const MAX_SAFE_INTEGER: f32;
/** Positive infinity value. */
export const POSITIVE_INFINITY: f32;
/** Negative infinity value. */
export const NEGATIVE_INFINITY: f32;
/** Not a number value. */
/* eslint no-shadow-restricted-names: "off" */
export const NaN: f32;
/** Difference between 1 and the smallest representable value greater than 1. */
export const EPSILON: f32;
/** Returns a boolean value that indicates whether a value is the reserved value NaN (not a number). */
Expand All @@ -258,11 +265,18 @@ declare namespace f64 {
/** Largest representable value. */
export const MAX_VALUE: f64;
/** Smallest normalized positive value. */
export const MIN_POSITIVE_VALUE: f64;
export const MIN_NORMAL_VALUE: f64;
/** Smallest safely representable integer value. */
export const MIN_SAFE_INTEGER: f64;
/** Largest safely representable integer value. */
export const MAX_SAFE_INTEGER: f64;
/** Positive infinity value. */
export const POSITIVE_INFINITY: f64;
/** Negative infinity value. */
export const NEGATIVE_INFINITY: f64;
/** Not a number value. */
/* eslint no-shadow-restricted-names: "off" */
export const NaN: f64;
/** Difference between 1 and the smallest representable value greater than 1. */
export const EPSILON: f64;
/** Returns a boolean value that indicates whether a value is the reserved value NaN (not a number). */
Expand Down
22 changes: 14 additions & 8 deletions std/portable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,30 @@ Object.defineProperties(
Object.defineProperties(
globalScope["f32"] = function f32(value) { return Math.fround(value); },
{
"EPSILON": { value: Math.fround(1.1920929e-07), writable: false },
"MIN_VALUE": { value: Math.fround(1.4012985e-45), writable: false },
"MAX_VALUE": { value: Math.fround(3.4028235e+38), writable: false },
"MIN_NORMAL_VALUE": { value: Math.fround(1.17549435e-38), writable: false },
"EPSILON": { value: 1.1920928955078125e-07, writable: false },
"MIN_VALUE": { value: 1.4012984643248170e-45, writable: false },
"MAX_VALUE": { value: 3.4028234663852886e+38, writable: false },
"MIN_NORMAL_VALUE": { value: 1.1754943508222875e-38, writable: false },
"MIN_SAFE_INTEGER": { value: -16777215, writable: false },
"MAX_SAFE_INTEGER": { value: 16777215, writable: false }
"MAX_SAFE_INTEGER": { value: 16777215, writable: false },
"POSITIVE_INFINITY": { value: Infinity, writable: false },
"NEGATIVE_INFINITY": { value: -Infinity, writable: false },
"NaN": { value: NaN, writable: false }
}
);

Object.defineProperties(
globalScope["f64"] = function f64(value) { return +value; },
{
"EPSILON": { value: 2.2204460492503131e-16, writable: false },
"EPSILON": { value: 2.2204460492503131e-016, writable: false },
"MIN_VALUE": { value: 5e-324, writable: false },
"MAX_VALUE": { value: 1.7976931348623157e+308, writable: false },
"MIN_NORMAL_VALUE": { value: 2.2250738585072014e-308 , writable: false },
"MIN_NORMAL_VALUE": { value: 2.2250738585072014e-308, writable: false },
"MIN_SAFE_INTEGER": { value: -9007199254740991, writable: false },
"MAX_SAFE_INTEGER": { value: 9007199254740991, writable: false }
"MAX_SAFE_INTEGER": { value: 9007199254740991, writable: false },
"POSITIVE_INFINITY": { value: Infinity, writable: false },
"NEGATIVE_INFINITY": { value: -Infinity, writable: false },
"NaN": { value: NaN, writable: false }
}
);

Expand Down
2 changes: 2 additions & 0 deletions tests/compiler/number.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@
(global $~lib/util/number/_K (mut i32) (i32.const 0))
(global $~lib/util/number/_frc_pow (mut i64) (i64.const 0))
(global $~lib/util/number/_exp_pow (mut i32) (i32.const 0))
(global $~lib/builtins/f32.NaN f32 (f32.const nan:0x400000))
(global $~lib/number/F32.NaN f32 (f32.const nan:0x400000))
(global $~lib/builtins/f32.MIN_SAFE_INTEGER f32 (f32.const -16777215))
(global $~lib/builtins/f32.MAX_SAFE_INTEGER f32 (f32.const 16777215))
(global $~lib/builtins/f32.EPSILON f32 (f32.const 1.1920928955078125e-07))
(global $~lib/builtins/f64.NaN f64 (f64.const nan:0x8000000000000))
(global $~lib/number/F64.NaN f64 (f64.const nan:0x8000000000000))
(global $~lib/builtins/f64.MIN_SAFE_INTEGER f64 (f64.const -9007199254740991))
(global $~lib/builtins/f64.MAX_SAFE_INTEGER f64 (f64.const 9007199254740991))
Expand Down