Message-Id: <
200106051158.MAA04605@crypt.compulink.co.uk>
p4raw-id: //depot/perl@10445
NV
S_mulexp10(NV value, I32 exponent)
{
- NV result = value;
+ NV result = 1.0;
NV power = 10.0;
+ bool negative = 0;
I32 bit;
- if (exponent > 0) {
- for (bit = 1; exponent; bit <<= 1) {
- if (exponent & bit) {
- exponent ^= bit;
- result *= power;
- }
- power *= power;
- }
- }
+ if (exponent == 0)
+ return value;
else if (exponent < 0) {
+ negative = 1;
exponent = -exponent;
- for (bit = 1; exponent; bit <<= 1) {
- if (exponent & bit) {
- exponent ^= bit;
- result /= power;
- }
- power *= power;
+ }
+ for (bit = 1; exponent; bit <<= 1) {
+ if (exponent & bit) {
+ exponent ^= bit;
+ result *= power;
}
+ power *= power;
}
- return result;
+ return negative ? value / result : value * result;
}
char*