/
nv-lang
/
nova
Обзор
Документация
Войти
/
nv-lang
/
nova
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
std/src/runtime/numeric.nv
38 строк
2 KB
Evgeniy Golovin
style(225.1): вертикальный ритм — sweep классов a-e (std/src)
26 июл 2026, 02:46
26 июл 2026, 02:46
38ecf16
Код
Авторство
О чём код?
// std/runtime/numeric.nv — Plan 74: IEEE 754 primitive bit-cast // (`f64 ↔ u64`, `f32 ↔ u32` reinterpret-cast). // // [M-ptr-raw-access-contract-and-unaligned] item 3 (2026-07-08): NOT // auto-gen anymore. Was `extern "nova" fn ...` (C-side `nova_rt/numeric.h`, // memcpy-based wrappers); owner decision — `to_bits`/`from_bits` are now // PURE `.nv` bodies, built on `.read_unaligned()`/`.write_unaligned()` // (item 2's typed pointer methods, D141-contract memcpy-semantics) over a // reinterpreting pointer cast (item 4: `&ro-value as *T`). Same precedent // as `char_runtime()` retiring auto-gen for std/runtime/char.nv // ([M-compiler-nv-porting-wave] item A) — `numeric_runtime()` in // runtime_registry.rs now returns `vec![]`, this whole file is // hand-maintained. Single file, single source of truth. // #no_prelude — this module is imported by #no_prelude CUs (write_buffer.nv, // read_buffer.nv, same discipline). The bodies below need NOTHING from the // prelude — only builtin syntax (unsafe / & / as / pointer read_unaligned) — // so an implicit `std.prelude` edge from this leaf runtime module would be // pure import-graph noise (extra prelude↔runtime cycle pressure on the D29 // walk for every #no_prelude consumer). #no_prelude module runtime.numeric // ─── f64 ─── // IEEE 754 bit-pattern double как u64 (reinterpret-cast). export fn f64 @to_bits() -> u64 => unsafe { (&@ as *u64).read_unaligned() } // Восстановить f64 из IEEE 754 bit-pattern (reinterpret-cast). export fn f64.from_bits(bits u64) -> f64 => unsafe { (&bits as *f64).read_unaligned() } // ─── f32 ─── // IEEE 754 bit-pattern float как u32 (reinterpret-cast). export fn f32 @to_bits() -> u32 => unsafe { (&@ as *u32).read_unaligned() } // Восстановить f32 из IEEE 754 bit-pattern (reinterpret-cast). export fn f32.from_bits(bits u32) -> f32 => unsafe { (&bits as *f32).read_unaligned() }