pow(x,y)
is computed as e^(y*log(x))
Generally math libraries compute log(x)
in quad precision (which is time consuming) in order to avoid loss of precision when computing y*log(x)
as precision errors will magnify in the computation of e^(y*log(x))
.
Now, in case I would want to compute pow(x,y)
in the following steps.
double pow(double x,double y) {
return exp(y*log(x)); // Without any quad precision multiplication
}
What would be the maximum ULP error of this function. I do know that IEEE-754 standard says that any floating point operation should have less than 0.5 ULP error i.e 0.5*2^(-52)
.
So if my operation y*log(x)
suffers from a 0.5 ULP error, how do I compute the largest possible ULP error for e^(y*log(x))
Agreed that the computation of pow(x,y)
is fairly complicated. Algorithms generally compute log(x)
in a higher precision and the multiplication between y
and log(x)
is not straightforward. Since the ULP error depends on y*log(x)
, the maximum error would be for the largest value of Y*log(x)
for which e^(y*log(x))
is not infinity. Right? How do I compute the number of ULP for such a case? What are the maximum number of bits of the mantissa in the double precision format that would vary form the actual value in case of the largest value of y*log(x)
?
Updated the question. Thanks for all the help!
So a 10 bit difference would result in how much ULP error? I calculated it as,
ULP = (actual - computed)/ 2^(e-(p-1))
where e is the exponent of the actual number, p=53 for double precision. I read that I ULP = 2^(e-(p-1)) Let's assume,
Actual = 1.79282279439444787915898270592 *10^308
Computed = 1.79282279439451553814547593293 * 10^308
error= actual - computed = 6.7659e+294
Now
1 ULP = 2^(e- (p-1))
e = 1023 (exponent of the actual number - bias)
1 ULP = 2^(1023 - (53-1)) = 2^971
ULP error = error/ 1 ULP = 339
Is this correct?
pow
depends on the value ofy log x
. - meowgoesthedogpow
are not generally true. Implementations ofpow
are fairly complicated and typically involve extra precision (to avoid loss of accuracy, not loss of precision), but the extra precision is often obtained by careful work with multiple floating-point or integer objects, not by “quad precision.” Additionally, the computation is not as simple as e^(y*•log(*x)). Aside from partitioning the problem into various cases, the exponent and significand of x are often separated. - Eric Postpischily*log(x)
are not limited to ½ ULP, as it consists of two operations—taking a logarithm and performing a multiplication. - Eric Postpischil