Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate weird int -> float conversions #103

Closed
croyzor opened this issue Sep 12, 2024 · 1 comment · Fixed by #131
Closed

Investigate weird int -> float conversions #103

croyzor opened this issue Sep 12, 2024 · 1 comment · Fixed by #131
Assignees

Comments

@croyzor
Copy link
Contributor

croyzor commented Sep 12, 2024

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 #94 (comment)

@doug-q
Copy link
Collaborator

doug-q commented Oct 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants