Checkout base/math.jl When the exponent is a float, the c library function is used. When the exponent is an integer, it uses a llvm function. The implementation for integer exponent used to use an intelligent algorithm that does what your second example does but in a smart way, reducing the number of operations.
This kind of "error" is unavoidable when using floating point arithmetic On Tuesday, December 15, 2015 at 6:38:03 PM UTC-2, Christopher Alexander wrote: > > Just as a follow up, I just tested with the exponent being an Integer vs a > Float (i.e. 6 vs 6.0), and I now see the same result as I do with Python > and C++ using both. > > Chris > > On Tuesday, December 15, 2015 at 3:35:35 PM UTC-5, Christopher Alexander > wrote: >> >> Hello all, >> >> I have noted an inaccuracy when using the "^" symbol. Please see below: >> >> *julia> **1.052500000000004 ^ 6.0* >> >> >> *1.3593541801778923* >> *julia> * >> *1.052500000000004 * 1.052500000000004 * 1.052500000000004 * >> 1.052500000000004 * 1.052500000000004 * 1.052500000000004* >> *1.3593541801778926* >> >> This yields a difference of: >> >> *2.220446049250313e-16* >> >> >> >> This might not seem like much of a difference, but it is having an >> adverse effect on a project I am working on. To compare, in Python, I >> don't see any difference: >> >> In[8]: 1.052500000000004 ** 6.0 >> Out[8]: 1.3593541801778926 >> >> In[9]: 1.052500000000004 * 1.052500000000004 * 1.052500000000004 * >> 1.052500000000004 * 1.052500000000004 * 1.052500000000004 >> Out[9]: 1.3593541801778926 >> >> I also see no difference in C++ >> >> >> Any idea why this might be? Just an issue with floating point math? Is >> Julia actually being more accurate here? >> >> Thanks! >> >> Chris >> >
