Skip to main content

Module big_number

Module big_number 

Source
Expand description

Big number types represented as strings.

These types are simple string wrappers that allow users to parse and format big numbers using their preferred library.

§Accepted input

FromStr validates the structure of the input, not just its character set. BigInteger uses the JSON integer grammar with one deliberate relaxation (leading zeros), while BigDecimal accepts the forms supported by the CBOR decimal-fraction implementation:

BigInteger := '-'? DIGIT+
BigDecimal := ('+' | '-')? ( DIGIT+ ( '.' DIGIT* )? | '.' DIGIT+ )
              ( ('e' | 'E') ('+' | '-')? DIGIT+ )?

Both types accept "-12" and "00123"; BigDecimal also accepts "+5", ".5", "5.", and "1.23E-10". Neither type accepts "1.2.3", "--5", "1e", "e10", or "-". Decimal exponents and the resulting scale must also fit the supported range; otherwise parsing returns BigNumberError::ExponentOutOfRange.

Leading zeros are accepted because they have exactly one numeric reading and were accepted by previously released versions. They are not valid RFC 8259 JSON numbers, so a protocol that emits an arbitrary-precision value as a raw JSON number rejects them at the wire boundary instead.

Structs§

BigDecimal
A big decimal represented as a string.
BigInteger
A BigInteger represented as a string.

Enums§

BigNumberError
Error type for BigInteger and BigDecimal parsing.