Skip to content

Commit 6f990e2

Browse files
author
Victor Ripplinger
committed
Fix parsing double with negative exponent
1 parent 7fb5056 commit 6f990e2

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

experimental/tinyobj_loader_opt.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -605,19 +605,9 @@ static bool tryParseDouble(const char *s, const char *s_end, double *result) {
605605
}
606606

607607
assemble :
608-
609-
{
610-
// = pow(5.0, exponent);
611-
double a = 1.0;
612-
for (int i = 0; i < exponent; i++) {
613-
a = a * 5.0;
614-
}
615-
*result =
616-
//(sign == '+' ? 1 : -1) * ldexp(mantissa * pow(5.0, exponent), exponent);
617-
(sign == '+' ? 1 : -1) * (mantissa * a) *
618-
static_cast<double>(1ULL << exponent); // 5.0^exponent * 2^exponent
619-
}
620-
608+
*result = (sign == '+' ? 1 : -1) *
609+
(exponent ? std::ldexp(mantissa * std::pow(5.0, exponent), exponent)
610+
: mantissa);
621611
return true;
622612
fail:
623613
return false;

0 commit comments

Comments
 (0)