Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static double pow(final double a, final double b) {
- // exponentiation by squaring
- double r = 1.0;
- int exp = (int) b;
- double base = a;
- while (exp != 0) {
- if ((exp & 1) != 0) {
- r *= base;
- }
- base *= base;
- exp >>= 1;
- }
- // use the IEEE 754 trick for the fraction of the exponent
- final double b_faction = b - (int)b;
- final long tmp = Double.doubleToLongBits(a);
- final long tmp2 = (long) (b_faction * (tmp - 4606921280493453312L)) + 4606921280493453312L;
- return r * Double.longBitsToDouble(tmp2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement