numpy-ts supports 14 data types that mirror NumPy’s numeric type system. Every NDArray has a single dtype that determines how its elements are stored in memory and how arithmetic behaves.
JavaScript number only has 53 bits of integer precision. For full 64-bit integer support, numpy-ts uses BigInt64Array and BigUint64Array under the hood. This means int64 and uint64 arrays exchange values as bigint, not number.
When working with int64 or uint64 arrays, get() returns bigint and set() expects bigint. Mixing number and bigint in JavaScript throws a TypeError, so be explicit about conversions.
const a = np.array([1, 2, 3], { dtype: 'int64' });// Getting values returns bigintconst val = a.get([0]); // 1n (bigint)// Setting values requires biginta.set([0], 100n);// toArray() returns bigintsa.toArray(); // [100n, 2n, 3n]// Converting between number and bigintconst num = Number(val); // bigint -> numberconst big = BigInt(42); // number -> bigint
When you combine arrays with different dtypes in an operation, numpy-ts promotes to a common type that can represent both without data loss. The promotion follows NumPy’s rules:
For in-range finite floats, astype() truncates toward zero (matching NumPy). For out-of-range floats, the behavior depends on the target width:
Source value
Target
Result
Rule
1.7
int32
1
truncate toward zero
-1.7
int32
-1
truncate toward zero
2**31 (out of int32 range)
int32
2147483647
saturate at target bound
2**31
int16
-1
saturate to int32 first, then bit-truncate
2**31
uint8
255
saturate to int32 first, then bit-truncate
-2**31 - 1
uint16
0
saturate to int32 first, then bit-truncate
The two-step rule for narrow targets (8/16-bit) matches NumPy 2.x: saturate to int32 range, then bit-truncate via the target’s ToIntN. Earlier numpy-ts versions saturated against the final target width directly and could return 0 where NumPy returns -1 / 255 / 65535.
This requires care internally — naive Number(bigint) rounds 2^63-class values to a multiple of 2^11 before any truncation can happen. numpy-ts masks in BigInt-space (v & 0xFFFFFFFFn) before converting, so the low bits survive into the TypedArray store.
Finite float whose truncated value falls outside the target’s range (e.g. 2**31 → int32: arm64 saturates to 2147483647, x86 wraps to -2147483648).
numpy-ts picks the arm64 convention as a stable, predictable rule across all runtimes:
Source
Target
numpy-ts result
NaN
any integer
0
+Inf
signed
target max (e.g. 127 for int8)
+Inf
unsigned
target max (e.g. 255 for uint8)
-Inf
signed
target min
-Inf
unsigned
0
negative finite
unsigned
0
out-of-range finite
signed
saturated to target min/max
In-range finite casts (1.7 → int32, etc.) match every platform.
If you cast pathological float values to an integer dtype in code compared against NumPy, expect divergence on x86 NumPy. Filter, clamp, or replace these values explicitly before astype() if cross-platform parity matters.