3 ms·
Java's Math.pow accepts non-integer exponents so your example doesn't handle all cases.
by tveita 11y ago
Java's Math.pow accepts non-integer exponents so your example doesn't handle all cases.
- SapphireSun 11y agoRight, it only works on positive integers, but my original example using exp and ln works in nearly all cases (though you probably want to do some rounding in the case of an integer input). That's actually another point in its favor. It's constant time and handles the odd cases.