I've been working on a deterministic maths library for LuaJIT, and after research I am aware that multiplication, division, addition, subtraction, and square root are deterministic (as long as the same rounding mode is active) due to the IEEE 754 standard. However I also have a hunch that x^y where y is an integer may also be deterministic, as there is no error-- at least, no error when x is an integer-- when I try it, as if an algorithm like exponentiation by squaring was active. It would make sense if that were the case on all systems. I'm wondering if anyone in the know would have any idea if that's true.
By deterministic I mean giving the exact result on all systems.
No.
Consider a function
z = pow(x, y)wherex, yhave integer values (xis odd,y > 0). Whenzis close, yet less thanDBL_MAX, the math correct answer is perhaps a 1000 binary digits long. If code use exponentiation by squaring, there are many roundings that occur in the sub-steps. If code used extended math, the final result would sometimes certainly be better using the same algorithm, yet different than a limiteddoublemath approach. Of course other algorithms can generate different results.Languages rarely specified the exact computational approach for transcendental functions.
It is interesting OP is seeking the same result and not the best result. To find the best result can involve some heavy computation and then risks performance complaints. It is a trade-off that as advances occur, tend to go for the better answer - without too much excessive computation time.
Do you want consistency, or the best answer? Careful what you wish for - and this integer example.