pxt-common-packages 12.0.3 → 12.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/libs/base/core.cpp +21 -2
- package/package.json +1 -1
package/libs/base/core.cpp
CHANGED
|
@@ -1338,8 +1338,27 @@ namespace Math_ {
|
|
|
1338
1338
|
//%
|
|
1339
1339
|
TNumber pow(TNumber x, TNumber y) {
|
|
1340
1340
|
#ifdef PXT_POWI
|
|
1341
|
-
// regular pow() from math.h is 4k of code
|
|
1342
|
-
|
|
1341
|
+
// regular pow() from math.h is 4k of code, but it can
|
|
1342
|
+
// also be expressed as exp(y * log(x)) which is less
|
|
1343
|
+
// performant than pow() but doesn't increase code size
|
|
1344
|
+
double dx = toDouble(x);
|
|
1345
|
+
double dy = toDouble(y);
|
|
1346
|
+
|
|
1347
|
+
// shortcut to integer pow if y is an integer
|
|
1348
|
+
if (::floor(dy) == dy) {
|
|
1349
|
+
return fromDouble(__builtin_powi(dx, dy));
|
|
1350
|
+
}
|
|
1351
|
+
if (dx > 0) {
|
|
1352
|
+
return fromDouble(::exp(dy * ::log(dx)));
|
|
1353
|
+
}
|
|
1354
|
+
if (dx == 0) {
|
|
1355
|
+
if (dy < 0) {
|
|
1356
|
+
// positive infinity
|
|
1357
|
+
return fromDouble(HUGE_VAL);
|
|
1358
|
+
}
|
|
1359
|
+
return x;
|
|
1360
|
+
}
|
|
1361
|
+
return fromDouble(::log(dx));
|
|
1343
1362
|
#else
|
|
1344
1363
|
return fromDouble(::pow(toDouble(x), toDouble(y)));
|
|
1345
1364
|
#endif
|