Skip to content

BigInt

class BigInt

@brief Arbitrary-precision integer, for the opt-in bigint mode.

WAL++ represents integers as int64_t, which is the right default: it is what a waveform's values and indices need, and it costs nothing. Upstream WAL is written in Python, whose integers are unbounded, so a program that computes past 2^63 runs there and used to fail here before it even started, because the literal would not parse.

This type closes that gap without making every program pay for it. It is used only when bigint mode is on (see bigint_mode()), and only for values that do not fit in an int64_t, so ordinary arithmetic keeps the native path.

The magnitude is little-endian base 1e9, which makes decimal reading and printing exact and simple. That is slower than a binary limb representation, and deliberately so: this is the mode a user asks for when correctness past 64 bits matters more than speed.

Variables

Name Description
limbs_ little-endian, base 1e9, no leading zeros

Functions

Name Description
from_decimal Read a decimal literal.
fits_int64 Whether this value would survive a conversion to int64_t.
to_double Lossy, for mixing with floats.
compare -1, 0 or 1.
sub_magnitude Requires

Variable Details

limbs_

std::vector<uint32_t> limbs_

little-endian, base 1e9, no leading zeros

Function Details

compare

int compare(const BigInt& other) const

-1, 0 or 1.

fits_int64

bool fits_int64() const

Whether this value would survive a conversion to int64_t.

from_decimal

static std::optional<BigInt> from_decimal(const std::string& text)

Read a decimal literal. Returns nullopt if text is not one.

sub_magnitude

static std::vector<uint32_t> sub_magnitude(const std::vector<uint32_t>& a, const std::vector<uint32_t>& b)

Requires |a| >= |b|.

to_double

double to_double() const

Lossy, for mixing with floats. Large values saturate the double range.