Skip to content
Next Next commit
init
  • Loading branch information
MaxGraey committed Aug 24, 2022
commit 8bc2f397b014629b8be24f9d8ad4f2a1ddc86dde
10 changes: 7 additions & 3 deletions std/assembly/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1390,8 +1390,10 @@ declare class _Integer {
static readonly MIN_VALUE: number;
/** Largest representable value. */
static readonly MAX_VALUE: number;
/** Converts a string to an integer of this type. */
/** @deprecated Converts a string to an integer of this type. Please use "parse" method. */
static parseInt(value: string, radix?: number): number;
/** Converts a string to an integer of this type. */
static parse(value: string, radix?: number): number;
/** Converts this integer to a string. */
toString(radix?: number): string;
}
Expand Down Expand Up @@ -1423,10 +1425,12 @@ declare class _Float {
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. */
/** @deprecated Converts a string to an integer. Please use "parse" method. */
static parseInt(value: string, radix?: i32): f32 | f64;
/** Converts a string to a floating-point number. */
/** @deprecated Converts a string to a floating-point number. Please use "parse" method. */
static parseFloat(value: string): f32 | f64;
/** Converts a string to a floating-point number. */
static parse(value: string): f32 | f64;
/** Converts this floating-point number to a string. */
toString(radix?: number): string;
}
Expand Down
62 changes: 62 additions & 0 deletions std/assembly/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ export abstract class I8 {
@lazy
static readonly MAX_VALUE: i8 = i8.MAX_VALUE;

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): i8 {
return <i8>strtol<i32>(value, radix);
}

static parse(value: string, radix: i32 = 0): i8 {
return <i8>strtol<i32>(value, radix);
}

toString(this: i8, radix: i32 = 10): String {
return itoa32(this, radix);
}
Expand All @@ -48,10 +53,15 @@ export abstract class I16 {
@lazy
static readonly MAX_VALUE: i16 = i16.MAX_VALUE;

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): i16 {
return <i16>strtol<i32>(value, radix);
}

static parse(value: string, radix: i32 = 0): i16 {
return <i16>strtol<i32>(value, radix);
}

toString(this: i16, radix: i32 = 10): String {
return itoa32(this, radix);
}
Expand All @@ -68,10 +78,15 @@ export abstract class I32 {
@lazy
static readonly MAX_VALUE: i32 = i32.MAX_VALUE;

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): i32 {
return <i32>strtol<i32>(value, radix);
}

static parse(value: string, radix: i32 = 0): i32 {
return <i32>strtol<i32>(value, radix);
}

toString(this: i32, radix: i32 = 10): String {
return itoa32(this, radix);
}
Expand All @@ -88,10 +103,15 @@ export abstract class I64 {
@lazy
static readonly MAX_VALUE: i64 = i64.MAX_VALUE;

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): i64 {
return strtol<i64>(value, radix);
}

static parse(value: string, radix: i32 = 0): i64 {
return strtol<i64>(value, radix);
}

toString(this: i64, radix: i32 = 10): String {
return itoa64(this, radix);
}
Expand All @@ -108,10 +128,15 @@ export abstract class Isize {
@lazy
static readonly MAX_VALUE: isize = isize.MAX_VALUE;

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): isize {
return <isize>strtol<i64>(value, radix);
}

static parse(value: string, radix: i32 = 0): isize {
return <isize>strtol<i64>(value, radix);
}

toString(this: isize, radix: i32 = 10): String {
if (sizeof<isize>() == 4) {
return itoa32(<i32>this, radix);
Expand All @@ -132,10 +157,15 @@ export abstract class U8 {
@lazy
static readonly MAX_VALUE: u8 = u8.MAX_VALUE;

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): u8 {
return <u8>strtol<i32>(value, radix);
}

static parse(value: string, radix: i32 = 0): u8 {
return <u8>strtol<i32>(value, radix);
}

toString(this: u8, radix: i32 = 10): String {
return utoa32(this, radix);
}
Expand All @@ -152,10 +182,15 @@ export abstract class U16 {
@lazy
static readonly MAX_VALUE: u16 = u16.MAX_VALUE;

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): u16 {
return <u16>strtol<i32>(value, radix);
}

static parse(value: string, radix: i32 = 0): u16 {
return <u16>strtol<i32>(value, radix);
}

toString(this: u16, radix: i32 = 10): String {
return utoa32(this, radix);
}
Expand All @@ -172,10 +207,15 @@ export abstract class U32 {
@lazy
static readonly MAX_VALUE: u32 = u32.MAX_VALUE;

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): u32 {
return <u32>strtol<i32>(value, radix);
}

static parse(value: string, radix: i32 = 0): u32 {
return <u32>strtol<i32>(value, radix);
}

toString(this: u32, radix: i32 = 10): String {
return utoa32(this, radix);
}
Expand All @@ -192,10 +232,15 @@ export abstract class U64 {
@lazy
static readonly MAX_VALUE: u64 = u64.MAX_VALUE;

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): u64 {
return <u64>strtol<i64>(value, radix);
}

static parse(value: string, radix: i32 = 0): u64 {
return <u64>strtol<i64>(value, radix);
}

toString(this: u64, radix: i32 = 10): String {
return utoa64(this, radix);
}
Expand All @@ -212,10 +257,15 @@ export abstract class Usize {
@lazy
static readonly MAX_VALUE: usize = usize.MAX_VALUE;

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): usize {
return <usize>strtol<i64>(value, radix);
}

static parse(value: string, radix: i32 = 0): usize {
return <usize>strtol<i64>(value, radix);
}

toString(this: usize, radix: i32 = 10): String {
if (sizeof<usize>() == 4) {
return utoa32(<u32>this, radix);
Expand Down Expand Up @@ -294,14 +344,20 @@ export abstract class F32 {
return isFinite<f32>(value) && trunc<f32>(value) == value;
}

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): f32 {
return <f32>strtol<f64>(value, radix);
}

/** @deprecated */
static parseFloat(value: string): f32 {
return <f32>parseFloat(value);
}

static parse(value: string): f32 {
return <f32>parseFloat(value);
}

toString(this: f32, radix: i32 = 0): String {
return dtoa(this);
}
Expand Down Expand Up @@ -358,14 +414,20 @@ export abstract class F64 {
return isFinite<f64>(value) && trunc<f64>(value) == value;
}

/** @deprecated */
static parseInt(value: string, radix: i32 = 0): f64 {
return strtol<f64>(value, radix);
}

/** @deprecated */
static parseFloat(value: string): f64 {
return parseFloat(value);
}

static parse(value: string): f64 {
return parseFloat(value);
}

toString(this: f64, radix: i32 = 0): String {
return dtoa(this);
}
Expand Down