diff --git a/native/cocos/editor-support/spine/Json.cpp b/native/cocos/editor-support/spine/Json.cpp index 752c3888321..0eb3ad41d8c 100644 --- a/native/cocos/editor-support/spine/Json.cpp +++ b/native/cocos/editor-support/spine/Json.cpp @@ -41,6 +41,7 @@ THE SOFTWARE. #include #include #include +#include #include #include @@ -393,7 +394,7 @@ const char *Json::parseNumber(Json *item, const char *num) { ++ptr; ++n; } - result += fraction / pow(10.0, n); + result += fraction / MathUtil::ipow(10, n); } if (negative) { @@ -401,7 +402,7 @@ const char *Json::parseNumber(Json *item, const char *num) { } if (*ptr == 'e' || *ptr == 'E') { - double exponent = 0; + uint32_t exponent = 0; int expNegative = 0; int n = 0; ++ptr; @@ -414,15 +415,15 @@ const char *Json::parseNumber(Json *item, const char *num) { } while (*ptr >= '0' && *ptr <= '9') { - exponent = (exponent * 10.0) + (*ptr - '0'); + exponent = (exponent * 10) + (*ptr - '0'); ++ptr; ++n; } if (expNegative) { - result = result / pow(10, exponent); + result = result / MathUtil::ipow(10, exponent); } else { - result = result * pow(10, exponent); + result = result * MathUtil::ipow(10, exponent); } } diff --git a/native/cocos/editor-support/spine/MathUtil.cpp b/native/cocos/editor-support/spine/MathUtil.cpp index 25c2a9d94e7..6fb1b39604d 100644 --- a/native/cocos/editor-support/spine/MathUtil.cpp +++ b/native/cocos/editor-support/spine/MathUtil.cpp @@ -71,3 +71,17 @@ float MathUtil::randomTriangular(float min, float max, float mode) { if (u <= (mode - min) / d) return min + sqrt(u * d * (mode - min)); return max - sqrt((1 - u) * d * (max - mode)); } + +uint64_t MathUtil::ipow(uint64_t base, uint32_t exp) { + uint64_t result = 1; + + while (exp) { + if (exp & 1) { + result *= base; + } + exp >>= 1; + base *= base; + } + + return result; +} \ No newline at end of file diff --git a/native/cocos/editor-support/spine/MathUtil.h b/native/cocos/editor-support/spine/MathUtil.h index 8526d859fb6..2f32c23f349 100644 --- a/native/cocos/editor-support/spine/MathUtil.h +++ b/native/cocos/editor-support/spine/MathUtil.h @@ -113,6 +113,8 @@ class SP_API MathUtil { static inline float pow(float a, float b) { return (float)::pow(a, b); } + + static uint64_t ipow(uint64_t base, uint32_t exp); }; struct SP_API Interpolation {