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.
Files changed (2) hide show
  1. package/libs/base/core.cpp +21 -2
  2. package/package.json +1 -1
@@ -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
- return fromDouble(__builtin_powi(toDouble(x), toInt(y)));
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pxt-common-packages",
3
- "version": "12.0.3",
3
+ "version": "12.0.4",
4
4
  "description": "Microsoft MakeCode (PXT) common packages",
5
5
  "keywords": [
6
6
  "MakeCode",