logos.lang.writ.decimal

Module lang · package logos-lang

Types

structWDecimal

struct WDecimal

Represents a fixed-precision signed decimal (neg ? -1 : 1) * coeff / 10^scale (wire code 102). Fixed-size tagged arena object; scale is limited to 0..4095 and the coefficient to u64.

Fields

coeff: u64

Holds the coefficient magnitude, i.e. |value| * 10^scale.

spec: u32

Packs the scale in bits [0:11] (0..4095) and the sign in bit 31 (1 = negative).

Methods

fn is_neg(self: &WDecimal) -> bool

Returns true if the sign bit is set; may hold for a zero coefficient (-0), which hdec_cmp/hdec_add treat as non-negative.

fn scale(self: &WDecimal) -> u32

Returns the decimal scale (number of fractional digits, 0..4095).

fn to_f64(self: &WDecimal) -> f64

Returns the approximate value as f64 (coeff / 10^scale, signed). Convenience float view; exact arithmetic stays on the integer coeff+scale.

Functions

fnhdec_add

fn hdec_add(h: &Writ, x: WAny, y: WAny) -> WAny

Adds two decimals with scale alignment and sign handling; result carries the larger scale. Both arguments must satisfy is_decimal(). Returns a null WAny if scale alignment or the sum overflows u64.

fnhdec_cmp

fn hdec_cmp(x: WAny, y: WAny) -> i32

Compares two decimals by value, ignoring representation (1.50 == 1.5): -1 / 0 / 1. Both arguments must satisfy is_decimal(); -0 compares equal to 0.

fnhdec_from_str

fn hdec_from_str(h: &Writ, s: &[u8]) -> WAny

Parses "[-]digits[.digits]" into a decimal in the arena of h. Returns a null WAny on: empty digits, more than 19 significant digits (u64 overflow guard), a second decimal point, junk bytes, or scale > 4095.