pub fn normalize(
ty: Option<Logical>,
v: Physical<'_>,
) -> Result<Normalized, NormalizeError>Expand description
Encode one scalar for equality, with the domain its term belongs to.
Integers of every width share domain::INTEGER: a sign byte (0x00
negative, 0x01 otherwise) then the value as a big-endian 128-bit
two’s-complement word, which orders correctly across i128::MIN to
u128::MAX. Both float widths share domain::FLOAT: an f32 widens
exactly to f64, so it matches an f64 only when the numbers are equal
(f32 1.5 matches, f32 0.1 does not match f64 0.1). Float zero
signs and NaN payloads are folded. A timestamp in any unit is truncated
to microseconds. A decimal’s scale is normalized, so 1.50 and 1.5
are one term, as are -0.00 and 0. A null is domain::NULL and
the one byte 0x00; a typed null is walked as a plain one, so it is
the same term.
§Examples
use vitaminc_aead::Physical;
use vitaminc_normalize::{domain, normalize};
use vitaminc_protected::Controlled;
let null = normalize(None, Physical::Null)?;
assert_eq!(null.domain, domain::NULL);
assert_eq!(null.bytes.risky_ref(), &[0x00]);