Open croyzor opened 1 month ago
The issue here is that fptoui
(floating-point-to-unsigned-int) and fptosi
(floating-point-to-signed-int) return poison when their (floating point) argument "does not fit"(quoting lang ref) in the return type.
our logic is at present:
fn tunc_u(f: f64) -> Option<u64> {
if (0u64 as f64) <= f && f <= (u64::MAX as f64) { Some(f as f64) } else { None }
}
If I change the <=
s to <
then the test behaves sensibly. I conclude that u64::MAX as f64
is too large to fit in a u64
because rounding, and the strange results we are seeing are poison.
The lower-bound check should surely be less-than-equal for the unsigned case,unclear for the signed case. A bit more investigation needed to pin this down exactly.
We have a test case for int -> float -> int roundtrips which displays some confusing behaviour. See comment in code highlighted here.
_Originally posted by @mark-koch in https://github.com/CQCL/hugr-llvm/pull/94#discussion_r1750525367_