Add more numeric builtins (#330)

This commit is contained in:
Max Graey
2018-11-12 08:42:28 +02:00
committed by Daniel Wirtz
parent 3f9758f35a
commit 4e89456dcb
5 changed files with 1510 additions and 7 deletions

View File

@ -114,6 +114,10 @@ declare namespace i8 {
export const MIN_VALUE: i8;
/** Largest representable value. */
export const MAX_VALUE: i8;
/** Converts a string to a floating-point number and cast to target integer after. */
export function parseFloat(string: string): i8;
/** Converts A string to an integer. */
export function parseInt(string: string, radix?: i32): i8;
}
/** Converts any other numeric value to a 16-bit signed integer. */
declare function i16(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i8;
@ -122,6 +126,10 @@ declare namespace i16 {
export const MIN_VALUE: i16;
/** Largest representable value. */
export const MAX_VALUE: i16;
/** Converts a string to a floating-point number and cast to target integer after. */
export function parseFloat(string: string): i16;
/** Converts A string to an integer. */
export function parseInt(string: string, radix?: i32): i16;
}
/** Converts any other numeric value to a 32-bit signed integer. */
declare function i32(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i32;
@ -130,6 +138,10 @@ declare namespace i32 {
export const MIN_VALUE: i32;
/** Largest representable value. */
export const MAX_VALUE: i32;
/** Converts a string to a floating-point number and cast to target integer after. */
export function parseFloat(string: string): i32;
/** Converts A string to an integer. */
export function parseInt(string: string, radix?: i32): i32;
}
/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) signed integer. */
declare function isize(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): isize;
@ -138,6 +150,10 @@ declare namespace isize {
export const MIN_VALUE: isize;
/** Largest representable value. */
export const MAX_VALUE: isize;
/** Converts a string to a floating-point number and cast to target integer after. */
export function parseFloat(string: string): isize;
/** Converts A string to an integer. */
export function parseInt(string: string, radix?: i32): isize;
}
/** Converts any other numeric value to an 8-bit unsigned integer. */
declare function u8(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i8;
@ -146,6 +162,10 @@ declare namespace u8 {
export const MIN_VALUE: u8;
/** Largest representable value. */
export const MAX_VALUE: u8;
/** Converts a string to a floating-point number and cast to target integer after. */
export function parseFloat(string: string): u8;
/** Converts A string to an integer. */
export function parseInt(string: string, radix?: i32): u8;
}
/** Converts any other numeric value to a 16-bit unsigned integer. */
declare function u16(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i8;
@ -154,6 +174,10 @@ declare namespace u16 {
export const MIN_VALUE: u16;
/** Largest representable value. */
export const MAX_VALUE: u16;
/** Converts a string to a floating-point number and cast to target integer after. */
export function parseFloat(string: string): u16;
/** Converts A string to an integer. */
export function parseInt(string: string, radix?: i32): u16;
}
/** Converts any other numeric value to a 32-bit unsigned integer. */
declare function u32(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i32;
@ -162,6 +186,10 @@ declare namespace u32 {
export const MIN_VALUE: u32;
/** Largest representable value. */
export const MAX_VALUE: u32;
/** Converts a string to a floating-point number and cast to target integer after. */
export function parseFloat(string: string): u32;
/** Converts A string to an integer. */
export function parseInt(string: string, radix?: i32): u32;
}
/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) unsigned integer. */
declare function usize(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): isize;
@ -170,6 +198,10 @@ declare namespace usize {
export const MIN_VALUE: usize;
/** Largest representable value. */
export const MAX_VALUE: usize;
/** Converts a string to a floating-point number and cast to target integer after. */
export function parseFloat(string: string): usize;
/** Converts A string to an integer. */
export function parseInt(string: string, radix?: i32): usize;
}
/** Converts any other numeric value to a 1-bit unsigned integer. */
declare function bool(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): bool;
@ -194,6 +226,18 @@ declare namespace f32 {
export const MAX_SAFE_INTEGER: 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). */
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: f32): bool;
/** Returns true if the value passed is an integer, false otherwise. */
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. */
export function parseInt(string: string, radix?: i32): f32;
}
/** Converts any other numeric value to a 64-bit float. */
declare function f64(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): f64;
@ -210,6 +254,18 @@ declare namespace f64 {
export const MAX_SAFE_INTEGER: 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). */
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;
}
// Polyfills