missing representation-preserving scalar bitcast
Status
Scenario
Hashing f64 requires obtaining the IEEE-754 representation as u64 without
a numeric conversion of the value.
An ordinary cast:
lowers to f2i/LLVM fptoui. This is a numeric conversion, not a bitcast. It
loses the representation and is incorrect for negative values, NaN, and large
exponent values.
Expected behavior
The core language should have an explicit operation with a same-byte-size
check:
or a standard intrinsic bitcast_f64_u64(f64) -> u64. Lowering should
generate a representation-preserving IR/LLVM bitcast.
Actual limitation
TCastExpr supports numeric casts and pointer casts. There is no public AST
node for a scalar bitcast. Core syntax also does not allow explicitly taking
the address of a local scalar and reading it through a pointer of another
type.
Workaround
register a narrow external primitive f64_bits(f64) -> u64, implemented via std::bit_cast
missing representation-preserving scalar bitcast
Status
externals/qumir/test/regtest/cases/corelang.Scenario
Hashing
f64requires obtaining the IEEE-754 representation asu64withouta numeric conversion of the value.
An ordinary cast:
lowers to
f2i/LLVMfptoui. This is a numeric conversion, not a bitcast. Itloses the representation and is incorrect for negative values, NaN, and large
exponent values.
Expected behavior
The core language should have an explicit operation with a same-byte-size
check:
or a standard intrinsic
bitcast_f64_u64(f64) -> u64. Lowering shouldgenerate a representation-preserving IR/LLVM bitcast.
Actual limitation
TCastExprsupports numeric casts and pointer casts. There is no public ASTnode for a scalar bitcast. Core syntax also does not allow explicitly taking
the address of a local scalar and reading it through a pointer of another
type.
Workaround
register a narrow external primitive
f64_bits(f64) -> u64, implemented viastd::bit_cast