Math.pow yields different result depending on java version

but was there a change in the java spec that causes the difference? No.* According to the Javadocs for Math.pow, a difference of up to one ULP (Unit in the Last Place) is permitted. If we take a look at your two values: System.out.printf(“%016x\n”, Double.doubleToLongBits(1.1567055833133086)); System.out.printf(“%016x\n”, Double.doubleToLongBits(1.1567055833133089)); we get: 3ff281ddb6b6e675 3ff281ddb6b6e676 which indeed differ by … Read more

How to: pow(real, real) in x86

Just compute it as 2^(y*log2(x)). There is a x86 instruction FYL2X to compute y*log2(x) and a x86 instruction F2XM1 to do exponentiation. F2XM1 requires an argument in [-1,1] range, so you’d have to add some code in between to extract the integer part and the remainder, exponentiate the remainder, use FSCALE to scale the result … Read more

Math.Pow vs multiply operator (performance)

I just reinstalled windows so visual studio is not installed and the code is ugly using System; using System.Diagnostics; public static class test{ public static void Main(string[] args){ MyTest(); PowTest(); } static void PowTest(){ var sw = Stopwatch.StartNew(); double res = 0; for (int i = 0; i < 333333333; i++){ res = Math.Pow(i,30); //pow(i,30) … Read more

Why is pow(int, int) so slow?

pow() works with real floating-point numbers and uses under the hood the formula pow(x,y) = e^(y log(x)) to calculate x^y. The int are converted to double before calling pow. (log is the natural logarithm, e-based) x^2 using pow() is therefore slower than x*x. Edit based on relevant comments Using pow even with integer exponents may … Read more

Why isn’t `int pow(int base, int exponent)` in the standard C++ libraries?

As of C++11, special cases were added to the suite of power functions (and others). C++11 [c.math] /11 states, after listing all the float/double/long double overloads (my emphasis, and paraphrased): Moreover, there shall be additional overloads sufficient to ensure that, if any argument corresponding to a double parameter has type double or an integer type, … Read more