UNPKG

ts-prims

Version:
153 lines 6.61 kB
import type { width, Width, _64bit, _96bit, _128bit, _160bit, _192bit, _256bit, _512bit, _4Kbit } from './width.js'; import { type prim } from './prim.js'; /** * Big int type with high int width `W`. * * ```ts * import type { big, _4Kbit } from 'ts-prims' * * type big4k = big<_4Kbit> * // type big4k = bigint & supertype<bigint> & width<15> * ``` * * `big` numbers are always backed by `bigint` values, which is less performant * than `number`, so for small `W`, prefer `int` instead. If you need a type * that uses either `number` or `bigint` depending on the width, use `varint`. * * @template W The width * @returns The bigint type with the specified (high) width * * @see {@link big64} for the first big int in the high-width (slow) range * @see {@link int} for the ints in the low-width (fast) range * @see {@link varint} for the low-level type that accepts all widths * @see {@link Width} for all supported number widths */ export type big<W extends Width> = prim<bigint, width<W>>; /** * Returns a constructor for `big` integer numbers with the given Width `W`. * * `big` numbers are always backed by `bigint` values, which is less performant * than `number`, so for small `W`, prefer `int` instead. If you need a type * that uses either `number` or `bigint` depending on the width, use `varint`. * * @template W The `Width`, inferred from parameter `w`. * * @param w The width of this type * @returns The constructor for `big<W>` * * @see {@link big} For the prim type * @see {@link Width} The widths of the big int types * @see {@link isInteger} constraint that values must be integer * @see {@link widthConstraint} constraint that values must be within width `W` * @see {@link varint} for the low-level type that accepts all widths */ export declare const Big: <W extends Width>(w: W) => import("./prim.js").PrimConstructor<big<W>>; /** * `64`-bit integer in the `HighWidth` (slow) range. * * **warning: may degrade performance!** * The Javascript platform only supports up to `54`-bit integers with the * native `number` type. Therefore, values of type `big64` are unfortunately * stored as `bigint`, which is a variable-width format that supports ints * with hundreds or even thousands of bits, but is much slower than * native `number`. If it is possible to use `int54` instead, prefer that. * Most other platforms have native support for `64`-bit integers, but if * you want true cross-platform performance guarantees, stick to `int54`. * * @see {@link int54} for the last int in the low-width (fast) range * @see {@link big128} for the next int in the high-width (slow) range */ export type big64 = big<_64bit>; /** Constructor for {@link big64} */ export declare const Big64: import("./prim.js").PrimConstructor<big<8>>; /** * `96`-bit integer in the `HighWidth` (slow) range. * * **warning: may degrade performance!** * Most platforms have no native support for `96`-bit numbers. We emulate * them, in this case with `bigint` and on other platforms in similar ways. * * @see {@link big64} for the previous int in the high-width (slow) range * @see {@link big128} for the next int in the high-width (slow) range */ export type big96 = big<_96bit>; /** Constructor for {@link big96} */ export declare const Big96: import("./prim.js").PrimConstructor<big<9>>; /** * `128`-bit integer in the `HighWidth` (slow) range. * * **warning: may degrade performance!** * Most platforms have no native support for `128`-bit numbers. We emulate * them, in this case with `bigint` and on other platforms in similar ways. * * @see {@link big96} for the previous int in the high-width (slow) range * @see {@link big160} for the next int in the high-width (slow) range */ export type big128 = big<_128bit>; /** Constructor for {@link big128} */ export declare const Big128: import("./prim.js").PrimConstructor<big<10>>; /** * `160`-bit integer in the `HighWidth` (slow) range. * * **warning: may degrade performance!** * Most platforms have no native support for `160`-bit numbers. We emulate * them, in this case with `bigint` and on other platforms in similar ways. * * @see {@link big128} for the previous int in the high-width (slow) range * @see {@link big192} for the next int in the high-width (slow) range */ export type big160 = big<_160bit>; /** Constructor for {@link big160} */ export declare const Big160: import("./prim.js").PrimConstructor<big<11>>; /** * `192`-bit integer in the `HighWidth` (slow) range. * * **warning: may degrade performance!** * Most platforms have no native support for `192`-bit numbers. We emulate * them, in this case with `bigint` and on other platforms in similar ways. * * @see {@link big160} for the previous int in the high-width (slow) range * @see {@link big256} for the next int in the high-width (slow) range */ export type big192 = big<_192bit>; /** Constructor for {@link big192} */ export declare const Big192: import("./prim.js").PrimConstructor<big<12>>; /** * `256`-bit integer in the `HighWidth` (slow) range. * * **warning: may degrade performance!** * Most platforms have no native support for `256`-bit numbers. We emulate * them, in this case with `bigint` and on other platforms in similar ways. * * @see {@link big192} for the previous int in the high-width (slow) range * @see {@link big512} for the next int in the high-width (slow) range */ export type big256 = big<_256bit>; /** Constructor for {@link big256} */ export declare const Big256: import("./prim.js").PrimConstructor<big<13>>; /** * `512`-bit integer in the `HighWidth` (slow) range. * * **warning: may degrade performance!** * Most platforms have no native support for `512`-bit numbers. We emulate * them, in this case with `bigint` and on other platforms in similar ways. * * @see {@link big256} for the previous int in the high-width (slow) range * @see {@link big4K} for the next int in the high-width (slow) range */ export type big512 = big<_512bit>; /** Constructor for {@link big512} */ export declare const Big512: import("./prim.js").PrimConstructor<big<14>>; /** * `4K`-bit integer in the `HighWidth` (slow) range. * * **warning: may degrade performance!** * Most platforms have no native support for `4K`-bit numbers. We emulate * them, in this case with `bigint` and on other platforms in similar ways. * * @see {@link big512} for the previous int in the high-width (slow) range */ export type big4K = big<_4Kbit>; /** Constructor for {@link big4K} */ export declare const Big4K: import("./prim.js").PrimConstructor<big<15>>; //# sourceMappingURL=big.d.ts.map