Number overview
A simple extension to the Effect Number module
Table of contents
Constructors
fromBigDecimal
Same as fromBigDecimalOption
but returns an Either of a number.
Signature
export declare const fromBigDecimal: (self: BigDecimal.BigDecimal) => Either.Either<number, Brand.Brand.BrandErrors>
fromBigDecimalOption
Builds a number from a BigDecimal. Returns a some
if the BigDecimal is in the 64-bit range of a number. Returns a none
otherwise
Signature
export declare const fromBigDecimalOption: MTypes.OneArgFunction<BigDecimal.BigDecimal, Option.Option<number>>
fromBigDecimalOrThrow
Same as fromBigDecimal
but throws in case of an error
Signature
export declare const fromBigDecimalOrThrow: MTypes.OneArgFunction<BigDecimal.BigDecimal, number>
fromBigInt
Same as fromBigIntOption
but returns an Either of a number.
Signature
export declare const fromBigInt: (self: bigint) => Either.Either<number, Brand.Brand.BrandErrors>
fromBigIntOption
Builds a number from a BigInt. Returns a some
if the BigInt is in the 64-bit range of a number. Returns a none
otherwise
Signature
export declare const fromBigIntOption: MTypes.OneArgFunction<bigint, Option.Option<number>>
fromBigIntOrThrow
Same as fromBigInt
but throws in case of an error
Signature
export declare const fromBigIntOrThrow: MTypes.OneArgFunction<bigint, number>
unsafeFromBigDecimal
Builds a number from a BigDecimal. No checks are carried out. If the number is too big or too small, it is turned into +Infinity or -Infinity
Signature
export declare const unsafeFromBigDecimal: MTypes.OneArgFunction<BigDecimal.BigDecimal, number>
unsafeFromBigInt
Builds a number from a BigInt. No checks are carried out. If the number is too big or too small, it is turned into +Infinity or -Infinity
Signature
export declare const unsafeFromBigInt: MTypes.OneArgFunction<bigint, number>
unsafeFromString
Constructs a number from a string. Return NaN
if the string does not represent a number. Returns Infinity if the string is ‘Infinity’ or ‘+Infinity’ and -Infinity if the string is ‘-Infinity’
Signature
export declare const unsafeFromString: MTypes.NumberFromString
Destructors
quotientAndRemainder
Returns the quotient
and remainder
of the division of self
by divisor
. remainder
always has the sign of divisor
. Use only with finite integers
Signature
export declare const quotientAndRemainder: (divisor: number) => (self: number) => [quotient: number, remainder: number]
Predicates
equals
Predicate that returns true if two numbers are equal
Signature
export declare const equals: (n: number) => Predicate.Predicate<number>
isFinite
Returns true if the provided number is not NaN, Infinity, +Infinity or -Infinity
Signature
export declare const isFinite: Predicate.Predicate<number>
isInt
Returns true if the provided number is an integer
Signature
export declare const isInt: Predicate.Predicate<number>
isMultipleOf
Returns true if self
is a multiple of a
. Works even if self
or a
or both are negative
Signature
export declare const isMultipleOf: (a: number) => Predicate.Predicate<number>
isNotFinite
Returns true if the provided number is NaN, Infinity, +Infinity or -Infinity
Signature
export declare const isNotFinite: Predicate.Predicate<number>
isNotInt
Returns true if the provided number is not an integer
Signature
export declare const isNotInt: Predicate.Predicate<number>
Utils
intModulo
This function always returns a positive integer even if self
or divisor
is negative. Use only with finite integers.
Signature
export declare const intModulo: (divisor: number) => MTypes.OneArgFunction<number>
opposite
Returns the opposite of self
Signature
export declare const opposite: (self: number) => number
shift
Returns self
multiplied by 10^n
Signature
export declare const shift: (n: number) => (self: number) => number
sign2
Returns the sign of self
. Same as Math.sign but 0 and +0 are considered positive while -0 is considered negative.
Signature
export declare const sign2: (n: number) => 1 | -1
trunc
Truncates a number after precision
decimal digits. precision
must be a positive finite integer. If not provided, precision
is taken equal to 0.
Signature
export declare const trunc: (precision?: number) => (self: number) => number
utils
MAX_SAFE_INTEGER
Maximum safe integer in JavaScript (2^53 – 1).
Signature
export declare const MAX_SAFE_INTEGER: number
MIN_SAFE_INTEGER
Minimum safe integer in JavaScript -(2^53 – 1).
Signature
export declare const MIN_SAFE_INTEGER: number