Implement native GDSII reading and writing with Arrow interchange, hierarchy scans and selective cell loading. Validate numeric packing and array pitches, and preserve normalized REAL8 encodings exactly within the supported range. Add standalone dump, structural diff, hierarchy, layer-name annotation and Git diff commands. Provide scoped text and JSON reports, deterministic comparison, and record-preserving metadata edits. Package the shared library and optional Python Arrow readers as pheon using CFFI ABI mode and Python-independent platform wheels. Include locked source builds, native API checks, cross-platform artifact workflows, documentation and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer. Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14, and 71 installed companion integration tests pass. Full, scanned and selected Arrow layouts match the previous schemas.
75 lines
2.3 KiB
Rust
75 lines
2.3 KiB
Rust
use pheon::basic::{decode_real8, encode_real8, pack_real8};
|
|
|
|
#[test]
|
|
fn normalized_real8_has_known_encodings_and_exact_values() {
|
|
for (value, expected) in [
|
|
(0.0, 0),
|
|
(-0.0, 0),
|
|
(1.0, 0x4110_0000_0000_0000),
|
|
(-2.0, 0xc120_0000_0000_0000),
|
|
(0.5, 0x4080_0000_0000_0000),
|
|
(0.001, 0x3e41_8937_4bc6_a7f0),
|
|
(1e-9, 0x3944_b82f_a09b_5a54),
|
|
(2_f64.powi(-260), 0x0010_0000_0000_0000),
|
|
] {
|
|
let bits = encode_real8(value).unwrap();
|
|
assert_eq!(bits, expected, "{value:e}");
|
|
assert_eq!(decode_real8(bits), value);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn real8_round_trips_each_supported_binary_exponent_and_mantissa_boundary() {
|
|
for exponent in -260..=251_i32 {
|
|
for mantissa in [
|
|
0,
|
|
1,
|
|
0x0008_0000_0000_0000,
|
|
0x000f_ffff_ffff_fffe,
|
|
0x000f_ffff_ffff_ffff,
|
|
] {
|
|
for sign in [0, 1_u64 << 63] {
|
|
let ieee = sign | (((exponent + 1023) as u64) << 52) | mantissa;
|
|
let value = f64::from_bits(ieee);
|
|
let encoded = encode_real8(value).unwrap();
|
|
assert_ne!(encoded & 0x00f0_0000_0000_0000, 0, "{value:e}");
|
|
assert_eq!(decode_real8(encoded).to_bits(), ieee, "{value:e}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn real8_underflow_is_canonical_and_overflow_is_an_error() {
|
|
let minimum = 2_f64.powi(-260);
|
|
let maximum_exclusive = 2_f64.powi(252);
|
|
for magnitude in [
|
|
0.0,
|
|
f64::from_bits(1),
|
|
f64::MIN_POSITIVE,
|
|
1e-90,
|
|
1e-80,
|
|
f64::from_bits(minimum.to_bits() - 1),
|
|
] {
|
|
for value in [magnitude, -magnitude] {
|
|
assert_eq!(encode_real8(value).unwrap(), 0, "{value:e}");
|
|
}
|
|
}
|
|
let largest = f64::from_bits(maximum_exclusive.to_bits() - 1);
|
|
assert_eq!(encode_real8(largest).unwrap(), 0x7fff_ffff_ffff_fff8);
|
|
assert_eq!(decode_real8(encode_real8(largest).unwrap()), largest);
|
|
for value in [
|
|
maximum_exclusive,
|
|
-maximum_exclusive,
|
|
f64::MAX,
|
|
-f64::MAX,
|
|
f64::INFINITY,
|
|
f64::NEG_INFINITY,
|
|
f64::NAN,
|
|
] {
|
|
assert!(encode_real8(value).is_err(), "{value}");
|
|
let mut buffer = [0x55; 8];
|
|
assert!(pack_real8(&mut buffer, value).is_err());
|
|
assert_eq!(buffer, [0x55; 8]);
|
|
}
|
|
}
|