-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
f32 division/multiplication and .tan() platform behavior #75786
Comments
This is similar to #73420 -- your Windows result looks like it has computed via I tried this on the playground (Linux): fn main() {
let floaty: f32 = 1.222222; // 6 decimal points
println!("{:.32}", floaty);
println!("{:.32}", floaty / 2.0);
println!("{:.32}", (floaty / 2.0).tan());
println!("{:.32}", ((floaty / 2.0) as f64).tan() as f32);
}
|
Ah yea i see what you mean. |
Adding some more stuff i just found. let floaty: f32 = 1.22222; // 5 decimal points
println!("{:.32}", floaty);
println!("{:.32}", floaty * 2.0);
println!("{:.32}", (floaty * 2.0).tan());
let floaty: f32 = 1.222222; // 6 decimal points
println!("{:.32}", floaty);
println!("{:.32}", floaty * 2.0);
println!("{:.32}", (floaty * 2.0).tan());
|
This is probably just because of the If you throw that last example into float toy, you'll see
A difference of 1ULP, as expected. There are plenty of resources about floating point determinism related to real-time strategy games, see for example the things referenced in https://gamedev.stackexchange.com/a/174374 So I think there isn't actually anything to fix here, as unfortunate as that is. This is just why games tend to use their own trig approximations for anything that needs to be portable, rather than the platform ones. |
@scottmcm Thanks for the explanation! And thank you for the links. I was told that dimforge rapier is gonna have cross platform determinism so i was wondering. If you say this is expected behavior then feel free to close it. I don't have enough knowledge on the subject to be able to chime in. Edit: |
Indeed, multiplication and division should be consistent across platforms. Can you confirm that this is the case here? If yes, we should remove their mention from the issue title.
|
Sorry for not keeping this up to date. Sleep has not been agreeing with me lately. Will try and update this without the division/multiplication here soon when i have time |
Closing this for now as it doesn't focus on the actual problem without division/multiplication. |
I know floats aren't exactly known for their precision and i might be missing something.
But i'm seeing some odd platform dependent behavior when i combine a
f32
float division with .tan()This code run on mac, linux and windows
Gives the following printout
All the outputs are the same as i guess is expected.
Now i add one more decimal
Which outputs
Now windows suddenly shows a different output on the last line.
I have testet this on my windows 10 pc, linux laptop (mint) and a github actions matrix of ubuntu, windows, mac, nightly, beta and stable.
Is this a bug or am i missing something?
The text was updated successfully, but these errors were encountered: