-
Notifications
You must be signed in to change notification settings - Fork 352
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
[WIP] Implement cbrt and hypot function calls #763
Conversation
Closing and re-opening to hopefully deconfuse Travis. |
Hm dang. Seems like Travis just does not test "Draft" PRs, but AppVeyor does? This is silly. |
I marked it as ready for review, let's see if that helps. |
b2b4261
to
95912a0
Compare
It does, and shows a legit failure:
That's why I don't like floating point stuff. ;) |
tests/run-pass/cmath.rs
Outdated
} | ||
|
||
fn main() { | ||
assert_eq!(cbrt(4.3), 1.6261333316791686); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you can round both values or use one of the "almost eq" crates for float assertions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, not really the crates, but inlining that shouldn't be too hard, even without fabs
.
fn almost_eq(x: f64, y: f64) -> bool {
const EPSILON: f64 = 1e-20;
let diff = x-y;
diff < EPSILON && diff > -EPSILON
}
Also, this "non-determinism" (not really but almost) makes me wonder if we should require a flag? This will mean that e.g. a "cross-Miri" running Linux code on macOS will not behave the same than when "native Miri" runs Linux code on Linux. But I also don't want 200 flags. So I am inclined to just accept this kind of divergence here. Once we have a "communication with the host OS" flag, we could use that. |
Well... the clean solution would be to add these functions to |
Sure, that would be best. |
Would I add the functions to librustc_apfloat/lib.rs? |
I don't know but @eddyb would. :) |
oh, eh, implementing those may be very hard. I have no clue what's needed to implement them properly. There may be standards to read for edge cases and stuff. |
FWIW, this is actually not the first Miri "intrinsic" that uses host floats; we have sin/cos/pow/... already implemented and they all use host floats right now (for lack of a softfloat implementation). |
Wasn't meant to block this PR. My original suggestion to just round in the test still stands. |
Actually we even already have the macro for that in |
95912a0
to
a8f66ef
Compare
Okay I moved my test cases to the pre-existing intrinsics-math.rs and modified to use the assert_approx_eq macro. Edit: Looks like the windows builds aren't happy. |
src/fn_call.rs
Outdated
let n = f.cbrt(); | ||
this.write_scalar(Scalar::from_f64(n), dest)?; | ||
} | ||
"hypot" => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is called _hypot
on Windows, so maybe just add that as an alternative case here?
a8f66ef
to
0a42d0b
Compare
As announced before, this ran into the recent floating point changes, so now it does not build any more. I'm afraid I'll have to ask you to rebase. Also see rust-lang/rust#61673 and #764. |
Okay no worries. I've done the rebase, now I need some guidance on what to do next. |
Right, so please copy-paste what |
Okay I see, thanks! |
Forgot to add a link to that code, here it is. |
Should I move the cbrt and hypot match arms from |
No, "intrinsics.rs" is for intrinsics and "fn_call" is for emulating C functions. |
Okay I see. |
233a28d
to
7c29de1
Compare
Test cases are added to `tests/run-pass/intrinsics-math.rs`
7c29de1
to
535914e
Compare
Yes this looks good. :) Let's see what CI says. |
CI is happy. :D Thanks a lot! |
Implements missing cbrt/hypot function calls as per #667.
Note that this PR is in progress -- I still need to determine what other function calls are missing.