silk.json.schema_number.

Compare JSON numbers and test divisibility without rounding to binary floating point.

Details#

Inputs must be valid JSON number spellings. Exponents and coefficients have no machine-integer limit. Comparisons, integer checks, and bounded conversions do not allocate. Divisibility uses decimal integer arithmetic and needs storage proportional to the significands, not exponents.

Import as SchemaNumber with import silk.json.schema_number { SchemaNumber }.

Public declarations: 1.

SchemaNumber#

silk
pub struct SchemaNumber

Exact operations on validated JSON number spellings, including arbitrary-length exponents.

Implementation SchemaNumber#

silk
impl SchemaNumber

Associated function compare#

silk
pub fn compare(left: string, right: string) -> i32

Returns -1, 0, or 1 according to the mathematical order of two valid JSON numbers. Signs, decimal places, exponent spelling, and negative zero do not affect equality. This operation does not allocate or convert either number to floating point.

Associated function isInteger#

silk
pub fn isInteger(value: string) -> bool

Returns whether a valid JSON number is mathematically integral, including 1.0 and 1e3. Zero is integral for every exponent. This operation does not allocate.

Associated function multipleOf#

silk
pub effect fn multipleOf(value: string, divisor: string) -> bool
    ! OutOfMemoryError ? &mut Allocator

Returns whether value is an exact integer multiple of the positive JSON number divisor. Decimal fractions are exact: 0.3 is a multiple of 0.1. Negative values and zero are accepted; a nonpositive divisor returns false. Storage depends on significand length only.

Errors#

  • OutOfMemoryError if decimal integer scratch storage cannot be allocated.

Associated function asUsize#

silk
pub fn asUsize(value: string) -> Option<usize>

Converts a valid JSON number to usize if it is nonnegative, integral, and in range. Returns None for negative nonzero numbers, fractions, and overflow. Negative zero is zero. This operation is exact and does not allocate.

Category: Data formats.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page