Skip to content

Number conversions ​

Conversion functions and constants for numbers: Int(x), Float(x), Int.MAX, Number.isInteger and friends. The types themselves are lowercase: int, uint, float, and int8 to float32 for packed storage.

Always available

No import needed. These names are in scope in every file.

Number conversion ​

ts
Number(value: any): float64

Coerce value to the most appropriate numeric form: an int when the value fits in int32, a uint when it fits in uint32, otherwise a float64. Strings parse as decimal numbers; non-numeric strings yield NaN. Booleans become 0 or 1; objects are NaN.

Carries static helpers: Number.isFinite, Number.isNaN, Number.isInteger, Number.parseInt, Number.parseFloat.

Number.toFixed ​

ts
toFixed(digits?: int): string

Instance surface shared by every numeric type (Int8 through Float): a method declared here works on all of them.

Number.toString ​

ts
toString(radix?: int): string

Format the number as a string; radix selects the base.

Number.isFinite ​

ts
static isFinite(value: any): boolean

true for an int, uint, or finite float; false for NaN, infinities, and non-numbers.

Number.isNaN ​

ts
static isNaN(value: any): boolean

true only for a float NaN; any non-number is false.

Number.isInteger ​

ts
static isInteger(value: any): boolean

true for an int or uint, or a finite float with no fraction; false otherwise.

Example

ts
console.log(Number.isInteger(5)); // true
console.log(Number.isInteger(5.5)); // false

Number.parseInt ​

ts
static parseInt(value: string, radix?: int): int

Parse the leading integer of a string (decimal); NaN when it does not start with a number. A numeric argument truncates toward zero.

Number.parseFloat ​

ts
static parseFloat(value: string): float64

Parse a decimal number from the start of a string; NaN when it does not start with a number.

Boolean class ​

ts
class Boolean

Final: it cannot be subclassed.

Convert value to its truthiness. Strings, arrays, maps, and objects are truthy; 0, NaN, "", null, and undefined are falsy.

Boolean.callable ​

ts
callable(value: any): boolean

Convert value to its truthiness; Boolean(0) is false.

Boolean.valueOf ​

ts
valueOf(): boolean

Return the boolean itself.

Other members of Boolean ​

ts
toString(): string

Int conversion ​

ts
Int(value: any, radix?: int): int

Convert value to a 32-bit signed integer. Floats truncate toward zero; strings parse in radix (default auto-detect: 0x hex, 0b binary, 0o octal, otherwise decimal). Throws on out-of-range or non-coercible input. Use tryInt for the non-throwing variant.

Int.MAX ​

ts
static readonly MAX: int

Largest Int value.

Int.MIN ​

ts
static readonly MIN: int

Smallest Int value.

Int.wrap ​

ts
static wrap(value: float): int

Two's-complement wrap of value (fraction truncated toward zero) into int. Never raises for a finite number.

Int.clamp ​

ts
static clamp(value: float): int

Saturate value (fraction truncated toward zero) to the int range. Never raises for a finite number.

Int8 conversion ​

ts
Int8(value: any, radix?: int): int

Convert value to an 8-bit signed integer in [-128, 127]. Throws RangeError if outside that range. radix applies to string inputs.

Int8.MAX ​

ts
static readonly MAX: int

Largest Int8 value.

Int8.MIN ​

ts
static readonly MIN: int

Smallest Int8 value.

Int8.wrap ​

ts
static wrap(value: float): int

Two's-complement wrap of value (fraction truncated toward zero) into int8. Never raises for a finite number.

Int8.clamp ​

ts
static clamp(value: float): int

Saturate value (fraction truncated toward zero) to the int8 range. Never raises for a finite number.

Int16 conversion ​

ts
Int16(value: any, radix?: int): int

Convert value to a 16-bit signed integer in [-32768, 32767].

Int16.MAX ​

ts
static readonly MAX: int

Largest Int16 value.

Int16.MIN ​

ts
static readonly MIN: int

Smallest Int16 value.

Int16.wrap ​

ts
static wrap(value: float): int

Two's-complement wrap of value (fraction truncated toward zero) into int16. Never raises for a finite number.

Int16.clamp ​

ts
static clamp(value: float): int

Saturate value (fraction truncated toward zero) to the int16 range. Never raises for a finite number.

Int32 conversion ​

ts
Int32(value: any, radix?: int): int

Convert value to a 32-bit signed integer (alias of the platform int; same range as Int).

Int32.MAX ​

ts
static readonly MAX: int

Largest Int32 value.

Int32.MIN ​

ts
static readonly MIN: int

Smallest Int32 value.

Int32.wrap ​

ts
static wrap(value: float): int32

Two's-complement wrap of value (fraction truncated toward zero) into int32. Never raises for a finite number.

Int32.clamp ​

ts
static clamp(value: float): int32

Saturate value (fraction truncated toward zero) to the int32 range. Never raises for a finite number.

Float conversion ​

ts
Float(value: any): float64

Convert value to a 64-bit float (alias of Float64). Strings parse with strtod; non-coercible input throws.

Float.MAX ​

ts
static readonly MAX: float64

Largest Float value.

Float.MIN_POSITIVE ​

ts
static readonly MIN_POSITIVE: float64

Smallest positive normal Float value.

Float.EPSILON ​

ts
static readonly EPSILON: float64

Difference between 1 and the next larger Float value.

Float.NaN ​

ts
static readonly NaN: float64

Not-a-number value.

Float.POSITIVE_INFINITY ​

ts
static readonly POSITIVE_INFINITY: float64

Positive infinity.

Float.NEGATIVE_INFINITY ​

ts
static readonly NEGATIVE_INFINITY: float64

Negative infinity.

Float64 conversion ​

ts
Float64(value: any): float64

Convert value to a 64-bit float. Same as Float; the explicit name is preferred when the bit width matters.

Float64.MAX ​

ts
static readonly MAX: float64

Largest Float64 value.

Float64.MIN_POSITIVE ​

ts
static readonly MIN_POSITIVE: float64

Smallest positive normal Float64 value.

Float64.EPSILON ​

ts
static readonly EPSILON: float64

Difference between 1 and the next larger Float64 value.

Float64.NaN ​

ts
static readonly NaN: float64

Not-a-number value.

Float64.POSITIVE_INFINITY ​

ts
static readonly POSITIVE_INFINITY: float64

Positive infinity.

Float64.NEGATIVE_INFINITY ​

ts
static readonly NEGATIVE_INFINITY: float64

Negative infinity.

Float32 conversion ​

ts
Float32(value: any): float

Convert value to a 32-bit float. The result is rounded to float32 precision and returned as a float.

Float32.MAX ​

ts
static readonly MAX: float

Largest Float32 value.

Float32.MIN_POSITIVE ​

ts
static readonly MIN_POSITIVE: float

Smallest positive normal Float32 value.

Float32.EPSILON ​

ts
static readonly EPSILON: float

Difference between 1 and the next larger Float32 value.

Float32.NaN ​

ts
static readonly NaN: float

Not-a-number value.

Float32.POSITIVE_INFINITY ​

ts
static readonly POSITIVE_INFINITY: float

Positive infinity.

Float32.NEGATIVE_INFINITY ​

ts
static readonly NEGATIVE_INFINITY: float

Negative infinity.

Float32.round ​

ts
static round(value: float): float

Round value to float32 precision. Overflow becomes Infinity or -Infinity; never raises.

UInt conversion ​

ts
UInt(value: any, radix?: int): uint

Convert value to a 32-bit unsigned integer (alias of UInt32). Throws RangeError if negative or above UINT32_MAX.

UInt.MAX ​

ts
static readonly MAX: uint

Largest UInt value.

UInt.MIN ​

ts
static readonly MIN: uint

Smallest UInt value.

UInt.wrap ​

ts
static wrap(value: float): uint

Two's-complement wrap of value (fraction truncated toward zero) into uint. Never raises for a finite number.

UInt.clamp ​

ts
static clamp(value: float): uint

Saturate value (fraction truncated toward zero) to the uint range. Never raises for a finite number.

UInt8 conversion ​

ts
UInt8(value: any, radix?: int): uint

Convert value to an 8-bit unsigned integer in [0, 255].

UInt8.MAX ​

ts
static readonly MAX: uint

Largest UInt8 value.

UInt8.MIN ​

ts
static readonly MIN: uint

Smallest UInt8 value.

UInt8.wrap ​

ts
static wrap(value: float): uint

Two's-complement wrap of value (fraction truncated toward zero) into uint8. Never raises for a finite number.

UInt8.clamp ​

ts
static clamp(value: float): uint

Saturate value (fraction truncated toward zero) to the uint8 range. Never raises for a finite number.

UInt16 conversion ​

ts
UInt16(value: any, radix?: int): uint

Convert value to a 16-bit unsigned integer in [0, 65535].

UInt16.MAX ​

ts
static readonly MAX: uint

Largest UInt16 value.

UInt16.MIN ​

ts
static readonly MIN: uint

Smallest UInt16 value.

UInt16.wrap ​

ts
static wrap(value: float): uint

Two's-complement wrap of value (fraction truncated toward zero) into uint16. Never raises for a finite number.

UInt16.clamp ​

ts
static clamp(value: float): uint

Saturate value (fraction truncated toward zero) to the uint16 range. Never raises for a finite number.

UInt32 conversion ​

ts
UInt32(value: any, radix?: int): uint

Convert value to a 32-bit unsigned integer in [0, 4294967295].

UInt32.MAX ​

ts
static readonly MAX: uint

Largest UInt32 value.

UInt32.MIN ​

ts
static readonly MIN: uint

Smallest UInt32 value.

UInt32.wrap ​

ts
static wrap(value: float): uint32

Two's-complement wrap of value (fraction truncated toward zero) into uint32. Never raises for a finite number.

UInt32.clamp ​

ts
static clamp(value: float): uint32

Saturate value (fraction truncated toward zero) to the uint32 range. Never raises for a finite number.


Generated from lang/types/builtin_numerics.d.tks in the ThicketScript repository.