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

[question] Is it deterministic with respect to different hardware platforms? #5

Open
ip opened this issue May 24, 2018 · 5 comments
Open

Comments

@ip
Copy link

ip commented May 24, 2018

I'm particularly interested in using this library for deterministic calculations in a real-time online game. Maybe anyone had this use case?

I.e. I need a library which produces exactly the same results (think memcmp()) on x86 and ARM processors (to cover mobile and desktops).

@PetteriAimonen
Copy link
Owner

I think they should be deterministic, as only integers are used. But I'm not aware of anyone actually having tried that out.

@grimaldini
Copy link

using fix16_from_float is not quite deterministic right? as you are doing a floating point arithmetic operation in the function's definition, therefore if you have something like fix16_t a = fix16_from_float(-2.1f) you can expect the value of a to be different in different architectures, is that right, @PetteriAimonen ?

@PetteriAimonen
Copy link
Owner

PetteriAimonen commented May 4, 2020

Well, floats are also supposed to be deterministic except for rounding of intermediate products. As fix16_from_float() is calculated in compile time it has pretty good chances of always yielding the IEE754 standard result. But who knows, I haven't tried it.

And anyway, a difference could only occur if the resulting fix16 value is very close to the rounding boundary. -2.1f is 2.0999999046325684 or 2.1000003814697266 which both are close to -137625.6 and round to -137626, so no chance of it rounding wrong. But if it was -2.0999984741210787 it might round to either -137625 or -137626.

@grimaldini
Copy link

grimaldini commented May 4, 2020

so the only way around issues like this would be using fix16_t a = fix16_from_str("-2.1") anytime constants are defined, right? because the issue with -2.0999984741210787 might even happen when using FIXMATH_NO_ROUNDING if say we want to just truncate certain things and prefer consistency over accuracy.

@PetteriAimonen
Copy link
Owner

You can also do (fix16_one * 21 / 10) which would be all integer math and thus deterministic.

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

No branches or pull requests

3 participants