Skip to content

Commit

Permalink
Add MathUtil::ipow which is depended by Json.cpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed Nov 1, 2024
1 parent 78e1435 commit 5c94b34
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
11 changes: 6 additions & 5 deletions native/cocos/editor-support/spine/Json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ THE SOFTWARE.
#include <spine/Extension.h>
#include <spine/Json.h>
#include <spine/SpineString.h>
#include <spine/MathUtil.h>

#include <assert.h>
#include <math.h>
Expand Down Expand Up @@ -393,15 +394,15 @@ 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) {
result = -result;
}

if (*ptr == 'e' || *ptr == 'E') {
double exponent = 0;
uint32_t exponent = 0;
int expNegative = 0;
int n = 0;
++ptr;
Expand All @@ -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);
}
}

Expand Down
14 changes: 14 additions & 0 deletions native/cocos/editor-support/spine/MathUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions native/cocos/editor-support/spine/MathUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5c94b34

Please sign in to comment.