mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-14 15:31:31 +00:00
Implement explicit this type (#373)
* Add backing classes for basic types (I32...) * Move standard numeric constants to backing classes
This commit is contained in:
@ -47,16 +47,12 @@
|
||||
export namespace i8 {
|
||||
export const MIN_VALUE: i8 = -128;
|
||||
export const MAX_VALUE: i8 = 127;
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): i8 { return <i8>parseI32(value, radix) }
|
||||
@inline export function parseFloat(value: string): i8 { return <i8>parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function i16(value: void): i16;
|
||||
export namespace i16 {
|
||||
export const MIN_VALUE: i16 = -32768;
|
||||
export const MAX_VALUE: i16 = 32767;
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): i16 { return <i16>parseI32(value, radix) }
|
||||
@inline export function parseFloat(value: string): i16 { return <i16>parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function i32(value: void): i32;
|
||||
@ -77,8 +73,6 @@ export namespace i32 {
|
||||
@builtin export declare function store8(offset: usize, value: i32, constantOffset?: usize): void;
|
||||
@builtin export declare function store16(offset: usize, value: i32, constantOffset?: usize): void;
|
||||
@builtin export declare function store(offset: usize, value: i32, constantOffset?: usize): void;
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): i32 { return <i32>parseI32(value, radix) }
|
||||
@inline export function parseFloat(value: string): i32 { return <i32>parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function i64(value: void): i64;
|
||||
@ -102,8 +96,6 @@ export namespace i64 {
|
||||
@builtin export declare function store16(offset: usize, value: i64, constantOffset?: usize): void;
|
||||
@builtin export declare function store32(offset: usize, value: i64, constantOffset?: usize): void;
|
||||
@builtin export declare function store(offset: usize, value: i64, constantOffset?: usize): void;
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): i64 { return <i64>parseI64(value, radix) }
|
||||
@inline export function parseFloat(value: string): i64 { return <i64>parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function isize(value: void): isize;
|
||||
@ -114,40 +106,30 @@ export namespace isize {
|
||||
export const MAX_VALUE: isize = sizeof<i32>() == sizeof<isize>()
|
||||
? 2147483647
|
||||
: <isize>9223372036854775807;
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): isize { return <isize>parseI64(value, radix) }
|
||||
@inline export function parseFloat(value: string): isize { return <isize>parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function u8(value: void): u8;
|
||||
export namespace u8 {
|
||||
export const MIN_VALUE: u8 = 0;
|
||||
export const MAX_VALUE: u8 = 255;
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): u8 { return <u8>parseI32(value, radix) }
|
||||
@inline export function parseFloat(value: string): u8 { return <u8>parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function u16(value: void): u16;
|
||||
export namespace u16 {
|
||||
export const MIN_VALUE: u16 = 0;
|
||||
export const MAX_VALUE: u16 = 65535;
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): u16 { return <u16>parseI32(value, radix) }
|
||||
@inline export function parseFloat(value: string): u16 { return <u16>parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function u32(value: void): u32;
|
||||
export namespace u32 {
|
||||
export const MIN_VALUE: u32 = 0;
|
||||
export const MAX_VALUE: u32 = 4294967295;
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): u32 { return <u32>parseI32(value, radix) }
|
||||
@inline export function parseFloat(value: string): u32 { return <u32>parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function u64(value: void): u64;
|
||||
export namespace u64 {
|
||||
export const MIN_VALUE: u64 = 0;
|
||||
export const MAX_VALUE: u64 = 18446744073709551615;
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): u64 { return <u64>parseI64(value, radix) }
|
||||
@inline export function parseFloat(value: string): u64 { return <u64>parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function usize(value: void): usize;
|
||||
@ -156,8 +138,6 @@ export namespace usize {
|
||||
export const MAX_VALUE: usize = sizeof<u32>() == sizeof<usize>()
|
||||
? 4294967295
|
||||
: <usize>18446744073709551615;
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): usize { return <usize>parseI64(value, radix) }
|
||||
@inline export function parseFloat(value: string): usize { return <usize>parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function bool(value: void): bool;
|
||||
@ -174,9 +154,6 @@ export namespace f32 {
|
||||
export const MIN_NORMAL_VALUE = reinterpret<f32>(0x00800000); // 0x1p-126f
|
||||
export const MIN_SAFE_INTEGER: f32 = -16777215;
|
||||
export const MAX_SAFE_INTEGER: f32 = 16777215;
|
||||
export const POSITIVE_INFINITY: f32 = Infinity;
|
||||
export const NEGATIVE_INFINITY: f32 = -Infinity;
|
||||
export const NaN: f32 = NaN;
|
||||
@builtin export declare function abs(value: f32): f32;
|
||||
@builtin export declare function ceil(value: f32): f32;
|
||||
@builtin export declare function copysign(x: f32, y: f32): f32;
|
||||
@ -189,12 +166,6 @@ export namespace f32 {
|
||||
@builtin export declare function sqrt(value: f32): f32;
|
||||
@builtin export declare function store(offset: usize, value: f32, constantOffset?: usize): void;
|
||||
@builtin export declare function trunc(value: f32): f32;
|
||||
@inline export function isNaN(value: f32): bool { return isNaN<f32>(value) }
|
||||
@inline export function isFinite(value: f32): bool { return isFinite<f32>(value) }
|
||||
@inline export function isSafeInteger(value: f32): bool { return abs<f32>(value) <= f32.MAX_SAFE_INTEGER && trunc<f32>(value) == value }
|
||||
@inline export function isInteger(value: f32): bool { return isFinite<f32>(value) && trunc<f32>(value) == value }
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): f32 { return <f32>parseI64(value, radix) }
|
||||
@inline export function parseFloat(value: string): f32 { return <f32>parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function f64(value: void): f64;
|
||||
@ -205,9 +176,6 @@ export namespace f64 {
|
||||
export const MIN_NORMAL_VALUE = reinterpret<f64>(0x0010000000000000); // 0x1p-1022
|
||||
export const MIN_SAFE_INTEGER: f64 = -9007199254740991;
|
||||
export const MAX_SAFE_INTEGER: f64 = 9007199254740991;
|
||||
export const POSITIVE_INFINITY: f64 = Infinity;
|
||||
export const NEGATIVE_INFINITY: f64 = -Infinity;
|
||||
export const NaN: f64 = NaN;
|
||||
@builtin export declare function abs(value: f64): f64;
|
||||
@builtin export declare function ceil(value: f64): f64;
|
||||
@builtin export declare function copysign(x: f64, y: f64): f64;
|
||||
@ -220,12 +188,6 @@ export namespace f64 {
|
||||
@builtin export declare function sqrt(value: f64): f64;
|
||||
@builtin export declare function store(offset: usize, value: f64, constantOffset?: usize): void;
|
||||
@builtin export declare function trunc(value: f64): f64;
|
||||
@inline export function isNaN(value: f64): bool { return isNaN<f64>(value) }
|
||||
@inline export function isFinite(value: f64): bool { return isFinite<f64>(value) }
|
||||
@inline export function isSafeInteger(value: f64): bool { return abs<f64>(value) <= f64.MAX_SAFE_INTEGER && trunc<f64>(value) == value }
|
||||
@inline export function isInteger(value: f64): bool { return isFinite<f64>(value) && trunc<f64>(value) == value }
|
||||
@inline export function parseInt(value: string, radix: i32 = 0): f64 { return <f64>parseI64(value, radix) }
|
||||
@inline export function parseFloat(value: string): f64 { return parseFloat(value) }
|
||||
}
|
||||
|
||||
@builtin export declare function start(): void;
|
||||
|
89
std/assembly/index.d.ts
vendored
89
std/assembly/index.d.ts
vendored
@ -238,7 +238,7 @@ declare namespace i64 {
|
||||
export function parseInt(string: string, radix?: i32): i64;
|
||||
}
|
||||
/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) signed integer. */
|
||||
declare var isize: i32 | i64;
|
||||
declare var isize: typeof i32 | typeof i64;
|
||||
/** Converts any other numeric value to an 8-bit unsigned integer. */
|
||||
declare function u8(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i8;
|
||||
declare namespace u8 {
|
||||
@ -288,7 +288,7 @@ declare namespace u64 {
|
||||
export function parseInt(string: string, radix?: i32): u64;
|
||||
}
|
||||
/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) unsigned integer. */
|
||||
declare var usize: u32 | u64;
|
||||
declare var usize: typeof u32 | typeof u64;
|
||||
/** Converts any other numeric value to a 1-bit unsigned integer. */
|
||||
declare function bool(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): bool;
|
||||
declare namespace bool {
|
||||
@ -330,7 +330,7 @@ declare namespace f32 {
|
||||
export function isInteger(value: f32): bool;
|
||||
/** Converts a string to a floating-point number. */
|
||||
export function parseFloat(string: string): f32;
|
||||
/** Converts A string to an integer. */
|
||||
/** Converts a string to an integer. */
|
||||
export function parseInt(string: string, radix?: i32): f32;
|
||||
}
|
||||
/** Converts any other numeric value to a 64-bit float. */
|
||||
@ -352,22 +352,81 @@ declare namespace f64 {
|
||||
export function load(offset: usize, constantOffset?: usize): f64;
|
||||
/** Stores a 64-bit float to memory. */
|
||||
export function store(offset: usize, value: f64, constantOffset?: usize): void;
|
||||
/** Returns a boolean value that indicates whether a value is the reserved value NaN (not a number). */
|
||||
export function isNaN(value: f32): bool;
|
||||
/** Returns true if passed value is finite. */
|
||||
export function isFinite(value: f32): bool;
|
||||
/** Returns true if the value passed is a safe integer. */
|
||||
export function isSafeInteger(value: f64): bool;
|
||||
/** Returns true if the value passed is an integer, false otherwise. */
|
||||
export function isInteger(value: f64): bool;
|
||||
/** Converts a string to a floating-point number. */
|
||||
export function parseFloat(string: string): f64;
|
||||
/** Converts A string to an integer. */
|
||||
export function parseInt(string: string, radix?: i32): f64;
|
||||
}
|
||||
/** Macro type evaluating to the underlying native WebAssembly type. */
|
||||
declare type NATIVE<T> = T;
|
||||
|
||||
/** Pseudo-class representing the backing class of integer types. */
|
||||
declare class _Integer {
|
||||
/** Smallest representable value. */
|
||||
static readonly MIN_VALUE: number;
|
||||
/** Largest representable value. */
|
||||
static readonly MAX_VALUE: number;
|
||||
/** Converts a string to an integer of this type. */
|
||||
static parseInt(value: string, radix?: number): number;
|
||||
/** Converts this integer to a string. */
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
/** Pseudo-class representing the backing class of floating-point types. */
|
||||
declare class _Float {
|
||||
/** Difference between 1 and the smallest representable value greater than 1. */
|
||||
static readonly EPSILON: f32 | f64;
|
||||
/** Smallest representable value. */
|
||||
static readonly MIN_VALUE: f32 | f64;
|
||||
/** Largest representable value. */
|
||||
static readonly MAX_VALUE: f32 | f64;
|
||||
/** Smallest safely representable integer value. */
|
||||
static readonly MIN_SAFE_INTEGER: f32 | f64;
|
||||
/** Largest safely representable integer value. */
|
||||
static readonly MAX_SAFE_INTEGER: f32 | f64;
|
||||
/** Value representing positive infinity. */
|
||||
static readonly POSITIVE_INFINITY: f32 | f64;
|
||||
/** Value representing negative infinity. */
|
||||
static readonly NEGATIVE_INFINITY: f32 | f64;
|
||||
/** Value representing 'not a number'. */
|
||||
static readonly NaN: f32 | f64;
|
||||
/** Returns a boolean value that indicates whether a value is the reserved value NaN (not a number). */
|
||||
static isNaN(value: f32 | f64): bool;
|
||||
/** Returns true if passed value is finite. */
|
||||
static isFinite(value: f32 | f64): bool;
|
||||
/** Returns true if the value passed is a safe integer. */
|
||||
static isSafeInteger(value: f32 | f64): bool;
|
||||
/** Returns true if the value passed is an integer, false otherwise. */
|
||||
static isInteger(value: f32 | f64): bool;
|
||||
/** Converts A string to an integer. */
|
||||
static parseInt(value: string, radix?: i32): f32 | f64;
|
||||
/** Converts a string to a floating-point number. */
|
||||
static parseFloat(value: string): f32 | f64;
|
||||
/** Converts this floating-point number to a string. */
|
||||
toString(this: f64): string;
|
||||
}
|
||||
|
||||
/** Backing class of signed 8-bit integers. */
|
||||
declare const I8: typeof _Integer;
|
||||
/** Backing class of signed 16-bit integers. */
|
||||
declare const I16: typeof _Integer;
|
||||
/** Backing class of signed 32-bit integers. */
|
||||
declare const I32: typeof _Integer;
|
||||
/** Backing class of signed 64-bit integers. */
|
||||
declare const I64: typeof _Integer;
|
||||
/** Backing class of signed size integers. */
|
||||
declare const Isize: typeof _Integer;
|
||||
/** Backing class of unsigned 8-bit integers. */
|
||||
declare const U8: typeof _Integer;
|
||||
/** Backing class of unsigned 16-bit integers. */
|
||||
declare const U16: typeof _Integer;
|
||||
/** Backing class of unsigned 32-bit integers. */
|
||||
declare const U32: typeof _Integer;
|
||||
/** Backing class of unsigned 64-bit integers. */
|
||||
declare const U64: typeof _Integer;
|
||||
/** Backing class of unsigned size integers. */
|
||||
declare const Usize: typeof _Integer;
|
||||
/** Backing class of 32-bit floating-point values. */
|
||||
declare const F32: typeof _Float;
|
||||
/** Backing class of 64-bit floating-point values. */
|
||||
declare const F64: typeof _Float;
|
||||
|
||||
// User-defined diagnostic macros
|
||||
|
||||
/** Emits a user-defined diagnostic error when encountered. */
|
||||
|
@ -1,4 +1,35 @@
|
||||
// export abstract class Iterator<T> {
|
||||
// abstract get done(): bool;
|
||||
// abstract next(): T;
|
||||
// }
|
||||
export abstract class Iterable<T> {
|
||||
// ?
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class Iterator<T> {
|
||||
|
||||
// private constructor(iterable: Iterable<T>) {
|
||||
// }
|
||||
|
||||
// TODO: these need to evaluate the classId at the respective reference in order to obtain the
|
||||
// next value, i.e. arrays work differently than maps. we'd then have:
|
||||
//
|
||||
// ╒═══════════════════ Iterator layout (32-bit) ══════════════════╕
|
||||
// 3 2 1
|
||||
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits
|
||||
// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤
|
||||
// │ index │
|
||||
// ├─────────────────────────────────────────────────────────┬───┬─┤
|
||||
// │ reference │ 0 │D│
|
||||
// └─────────────────────────────────────────────────────────┴───┴─┘
|
||||
// D: Done flag
|
||||
|
||||
// get value(this: u64): T {
|
||||
// ?
|
||||
// }
|
||||
|
||||
// next(this: u64): Iterator<T> {
|
||||
// ?
|
||||
// }
|
||||
|
||||
done(this: u64): bool {
|
||||
return <bool>(this & 1);
|
||||
}
|
||||
}
|
||||
|
271
std/assembly/number.ts
Normal file
271
std/assembly/number.ts
Normal file
@ -0,0 +1,271 @@
|
||||
import {
|
||||
itoa,
|
||||
dtoa
|
||||
} from "./internal/number";
|
||||
|
||||
import {
|
||||
isNaN as builtin_isNaN,
|
||||
isFinite as builtin_isFinite
|
||||
} from "./builtins";
|
||||
|
||||
@sealed
|
||||
export abstract class I8 {
|
||||
|
||||
static readonly MIN_VALUE: i8 = i8.MIN_VALUE;
|
||||
static readonly MAX_VALUE: i8 = i8.MAX_VALUE;
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): i8 {
|
||||
return <i8>parseI32(value, radix);
|
||||
}
|
||||
|
||||
toString(this: i8): String {
|
||||
// TODO: radix
|
||||
return itoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class I16 {
|
||||
|
||||
static readonly MIN_VALUE: i16 = i16.MIN_VALUE;
|
||||
static readonly MAX_VALUE: i16 = i16.MAX_VALUE;
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): i16 {
|
||||
return <i16>parseI32(value, radix);
|
||||
}
|
||||
|
||||
toString(this: i16): String {
|
||||
// TODO: radix
|
||||
return itoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class I32 {
|
||||
|
||||
static readonly MIN_VALUE: i32 = i32.MIN_VALUE;
|
||||
static readonly MAX_VALUE: i32 = i32.MAX_VALUE;
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): i32 {
|
||||
return <i32>parseI32(value, radix);
|
||||
}
|
||||
|
||||
toString(this: i32): String {
|
||||
// TODO: radix
|
||||
return itoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class I64 {
|
||||
|
||||
static readonly MIN_VALUE: i64 = i64.MIN_VALUE;
|
||||
static readonly MAX_VALUE: i64 = i64.MAX_VALUE;
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): i64 {
|
||||
return <i64>parseI64(value, radix);
|
||||
}
|
||||
|
||||
toString(this: i64): String {
|
||||
// TODO: radix
|
||||
return itoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class Isize {
|
||||
|
||||
static readonly MIN_VALUE: isize = isize.MIN_VALUE;
|
||||
static readonly MAX_VALUE: isize = isize.MAX_VALUE;
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): isize {
|
||||
return <isize>parseI64(value, radix);
|
||||
}
|
||||
|
||||
toString(this: isize): String {
|
||||
// TODO: radix
|
||||
return itoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class U8 {
|
||||
|
||||
static readonly MIN_VALUE: u8 = u8.MIN_VALUE;
|
||||
static readonly MAX_VALUE: u8 = u8.MAX_VALUE;
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): u8 {
|
||||
return <u8>parseI32(value, radix);
|
||||
}
|
||||
|
||||
toString(this: u8): String {
|
||||
// TODO: radix
|
||||
return itoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class U16 {
|
||||
|
||||
static readonly MIN_VALUE: u16 = u16.MIN_VALUE;
|
||||
static readonly MAX_VALUE: u16 = u16.MAX_VALUE;
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): u16 {
|
||||
return <u16>parseI32(value, radix);
|
||||
}
|
||||
|
||||
toString(this: u16): String {
|
||||
// TODO: radix
|
||||
return itoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class U32 {
|
||||
|
||||
static readonly MIN_VALUE: u32 = u32.MIN_VALUE;
|
||||
static readonly MAX_VALUE: u32 = u32.MAX_VALUE;
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): u32 {
|
||||
return <u32>parseI32(value, radix);
|
||||
}
|
||||
|
||||
toString(this: u32): String {
|
||||
// TODO: radix
|
||||
return itoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class U64 {
|
||||
|
||||
static readonly MIN_VALUE: u64 = u64.MIN_VALUE;
|
||||
static readonly MAX_VALUE: u64 = u64.MAX_VALUE;
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): u64 {
|
||||
return <u64>parseI64(value, radix);
|
||||
}
|
||||
|
||||
toString(this: u64): String {
|
||||
// TODO: radix
|
||||
return itoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class Usize {
|
||||
|
||||
static readonly MIN_VALUE: usize = usize.MIN_VALUE;
|
||||
static readonly MAX_VALUE: usize = usize.MAX_VALUE;
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): usize {
|
||||
return <usize>parseI64(value, radix);
|
||||
}
|
||||
|
||||
toString(this: usize): String {
|
||||
// TODO: radix
|
||||
return itoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class Bool {
|
||||
|
||||
static readonly MIN_VALUE: bool = bool.MIN_VALUE;
|
||||
static readonly MAX_VALUE: bool = bool.MAX_VALUE;
|
||||
|
||||
toString(this: bool): String {
|
||||
// TODO: radix?
|
||||
return this ? "true" : "false";
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class Boolean extends Bool {}
|
||||
|
||||
@sealed
|
||||
export abstract class F32 {
|
||||
|
||||
static readonly EPSILON: f32 = f32.EPSILON;
|
||||
static readonly MIN_VALUE: f32 = f32.MIN_VALUE;
|
||||
static readonly MAX_VALUE: f32 = f32.MAX_VALUE;
|
||||
static readonly MIN_SAFE_INTEGER: f32 = f32.MIN_SAFE_INTEGER;
|
||||
static readonly MAX_SAFE_INTEGER: f32 = f32.MAX_SAFE_INTEGER;
|
||||
static readonly POSITIVE_INFINITY: f32 = Infinity;
|
||||
static readonly NEGATIVE_INFINITY: f32 = -Infinity;
|
||||
static readonly NaN: f32 = NaN;
|
||||
|
||||
static isNaN(value: f32): bool {
|
||||
return isNaN<f32>(value);
|
||||
}
|
||||
|
||||
static isFinite(value: f32): bool {
|
||||
return isFinite<f32>(value);
|
||||
}
|
||||
|
||||
static isSafeInteger(value: f32): bool {
|
||||
return abs<f32>(value) <= f32.MAX_SAFE_INTEGER && trunc<f32>(value) == value;
|
||||
}
|
||||
|
||||
static isInteger(value: f32): bool {
|
||||
return isFinite<f32>(value) && trunc<f32>(value) == value;
|
||||
}
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): f32 {
|
||||
return <f32>parseI64(value, radix);
|
||||
}
|
||||
|
||||
static parseFloat(value: string): f32 {
|
||||
return <f32>parseFloat(value);
|
||||
}
|
||||
|
||||
toString(this: f32): String {
|
||||
// TODO: radix
|
||||
return dtoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class F64 {
|
||||
|
||||
static readonly EPSILON: f64 = f64.EPSILON;
|
||||
static readonly MIN_VALUE: f64 = f64.MIN_VALUE;
|
||||
static readonly MAX_VALUE: f64 = f64.MAX_VALUE;
|
||||
static readonly MIN_SAFE_INTEGER: f64 = f64.MIN_SAFE_INTEGER;
|
||||
static readonly MAX_SAFE_INTEGER: f64 = f64.MAX_SAFE_INTEGER;
|
||||
static readonly POSITIVE_INFINITY: f64 = Infinity;
|
||||
static readonly NEGATIVE_INFINITY: f64 = -Infinity;
|
||||
static readonly NaN: f64 = NaN;
|
||||
|
||||
static isNaN(value: f64): bool {
|
||||
return builtin_isNaN<f64>(value);
|
||||
}
|
||||
|
||||
static isFinite(value: f64): bool {
|
||||
return builtin_isFinite<f64>(value);
|
||||
}
|
||||
|
||||
static isSafeInteger(value: f64): bool {
|
||||
return abs<f64>(value) <= f64.MAX_SAFE_INTEGER && trunc<f64>(value) == value;
|
||||
}
|
||||
|
||||
static isInteger(value: f64): bool {
|
||||
return builtin_isFinite<f64>(value) && trunc<f64>(value) == value;
|
||||
}
|
||||
|
||||
static parseInt(value: string, radix: i32 = 0): f64 {
|
||||
return <f64>parseI64(value, radix);
|
||||
}
|
||||
|
||||
static parseFloat(value: string): f64 {
|
||||
return parseFloat(value);
|
||||
}
|
||||
|
||||
toString(this: f64): String {
|
||||
// TODO: radix
|
||||
return dtoa(this);
|
||||
}
|
||||
}
|
||||
|
||||
@sealed
|
||||
export abstract class Number extends F64 {}
|
@ -64,10 +64,7 @@ Object.defineProperties(
|
||||
"MAX_VALUE": { value: Math.fround(3.4028235e+38), writable: false },
|
||||
"MIN_NORMAL_VALUE": { value: Math.fround(1.17549435e-38), writable: false },
|
||||
"MIN_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 }
|
||||
"MAX_SAFE_INTEGER": { value: 16777215, writable: false }
|
||||
});
|
||||
|
||||
Object.defineProperties(
|
||||
@ -78,10 +75,7 @@ Object.defineProperties(
|
||||
"MAX_VALUE": { value: 1.7976931348623157e+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 },
|
||||
"POSITIVE_INFINITY": { value: Infinity, writable: false },
|
||||
"NEGATIVE_INFINITY": { value: -Infinity, writable: false },
|
||||
"NaN": { value: NaN, writable: false }
|
||||
"MAX_SAFE_INTEGER": { value: 9007199254740991, writable: false }
|
||||
});
|
||||
|
||||
globalScope["clz"] = Math.clz32;
|
||||
|
Reference in New Issue
Block a user