x-lang

← Index

x/num/bigint

Arbitrary-precision integers, homed on the Bigint class.

Auto-promotes when integers exceed native range; the generic operators

dispatch bigint operands through the type ops. API: (Bigint + a b), …

bigint-digits-per-limb

bigint-base

bigint

Predicates

bigint?

big-limbs

ensure-big

Arithmetic

big-add

big-sub

big-mul

big-div

big-mod

Comparison

big-lt

big-eq

Operator Overrides

+

Add numbers, promoting to bigint on overflow.

Parameters:

Returns: INTEGER|BIGINT — Sum

Examples:

(+ 1 2 3) => 6
(+ 9223372036854775807 1) => 9223372036854775808

-

Subtract numbers, promoting to bigint on overflow. Unary form negates.

Parameters:

Returns: INTEGER|BIGINT — Difference

Examples:

(- 10 3 2) => 5
(- 5) => -5
(- -9223372036854775807 2) => -9223372036854775809

*

Multiply numbers, promoting to bigint on overflow.

Parameters:

Returns: INTEGER|BIGINT — Product

Examples:

(* 2 3 4) => 24
(* 4294967296 4294967296) => 18446744073709551616

/

Divide numbers; bigint operands dispatch through the type ops.

Parameters:

Returns: INTEGER|BIGINT — Quotient

Examples:

(/ 100 5 2) => 10
(/ 18446744073709551616 4294967296) => 4294967296

big-digits

big-sign-state

int-capped-digits

int-capped-base

int-capped-sign

bigint-type

Class Bigint

(Bigint type)

The bigint type handle, for Convert and Type.

Returns: ATOM — The BIGINT type handle

(Bigint bigint? x)

Test whether a value is an arbitrary-precision integer.

Parameters:

Returns: BOOL — True if x is a bigint

(Bigint + a b)

Add two bigints (ints promote).

Parameters:

Returns: INTEGER|BIGINT — Sum, demoted to integer if it fits

(Bigint - a b)

Subtract two bigints (ints promote).

Parameters:

Returns: INTEGER|BIGINT — Difference, demoted to integer if it fits

(Bigint * a b)

Multiply two bigints (ints promote).

Parameters:

Returns: INTEGER|BIGINT — Product, demoted to integer if it fits

(Bigint / a b)

Divide two bigints (truncating; ints promote).

Parameters:

Returns: INTEGER|BIGINT — Quotient, demoted to integer if it fits

(Bigint % a b)

Remainder of bigint division (ints promote).

Parameters:

Returns: INTEGER|BIGINT — Remainder, demoted to integer if it fits

(Bigint < a b)

Test whether a is less than b (ints promote).

Parameters:

Returns: BOOL — True if a < b

(Bigint = a b)

Test whether a equals b (ints promote).

Parameters:

Returns: BOOL — True if a equals b

(Bigint would-overflow-add? a b)

Test whether addition of two native integers would overflow.

Parameters:

Returns: BOOL — True if a + b would overflow native integer

(Bigint would-overflow-mul? a b)

Test whether multiplication of two native integers would overflow.

Parameters:

Returns: BOOL — True if a * b would overflow native integer

number?

Test whether a value is any numeric type (now including bigints).

Parameters:

Returns: BOOL — True if x is a number

Examples:

(number? (* 4294967296 4294967296 4294967296)) => #t