Skip to content

Commit

Permalink
Merge pull request #1373 from zloirock/math-sum-stage-3
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock authored Oct 9, 2024
2 parents 2d8c842 + 488de3d commit a51fc0d
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
- `Iterator.prototype[@@toStringTag]`
- Moved to stable ES, [October 2024 TC39 meeting](https://github.com/tc39/proposal-iterator-helpers/issues/284#event-14549961807)
- Added `es.` namespace modules, `/es/` and `/stable/` namespaces entries
- [`Math.sumPrecise` proposal](https://github.com/tc39/proposal-math-sum/):
- Built-ins:
- `Math.sumPrecise`
- Moved to stage 3, [October 2024 TC39 meeting](https://x.com/robpalmer2/status/1843829675036160179)
- Added `/actual/` namespace entries, unconditional forced replacement changed to feature detection
- Fixed `core-js-pure/actual|full/promise/try` entries for the callback arguments support
- Compat data improvements:
- [`JSON.parse` source text access proposal](https://github.com/tc39/proposal-json-parse-with-source) features marked as [supported from FF132](https://bugzilla.mozilla.org/show_bug.cgi?id=1913085)
Expand Down
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
- [Explicit resource management](#explicit-resource-management)
- [`Promise.try`](#promisetry)
- [`RegExp` escaping](#regexp-escaping)
- [`Math.sumPrecise`](#mathsumprecise)
- [`Symbol.metadata` for decorators metadata proposal](#symbolmetadata-for-decorators-metadata-proposal)
- [Stage 2.7 proposals](#stage-27-proposals)
- [`Math.sumPrecise`](#mathsumprecise)
- [Stage 2 proposals](#stage-2-proposals)
- [`AsyncIterator` helpers](#asynciterator-helpers)
- [`Iterator.range`](#iteratorrange)
Expand Down Expand Up @@ -2603,6 +2603,24 @@ console.log(RegExp.escape('💩')); // => '💩'
console.log(RegExp.escape('\uD83D')); // => '\\ud83d'
```

##### [`Math.sumPrecise`](https://github.com/tc39/proposal-math-sum)
Module [`esnext.math.sum-precise`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.math.sum-precise.js)
```ts
class Math {
static sumPrecise(items: Iterable<number>): Number;
}
```
[*CommonJS entry points:*](#commonjs-api)
```
core-js/proposals/math-sum
core-js(-pure)/full|actual/math/sum-precise
```
[*Examples*](https://tinyurl.com/2bd3nako):
```js
1e20 + 0.1 + -1e20; // => 0
Math.sumPrecise([1e20, 0.1, -1e20]); // => 0.1
```

##### [`Symbol.metadata` for decorators metadata proposal](https://github.com/tc39/proposal-decorator-metadata)[](#index)
Modules [`esnext.symbol.metadata`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.metadata.js) and [`esnext.function.metadata`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.function.metadata.js).
```ts
Expand All @@ -2627,23 +2645,7 @@ core-js(-pure)/actual|full/function/metadata
core-js(-pure)/stage/2.7
```

##### [`Math.sumPrecise`](https://github.com/tc39/proposal-math-sum)
Module [`esnext.math.sum-precise`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.math.sum-precise.js)
```ts
class Math {
static sumPrecise(items: Iterable<number>): Number;
}
```
[*CommonJS entry points:*](#commonjs-api)
```
core-js/proposals/math-sum
core-js(-pure)/full/math/sum-precise
```
[*Examples*](https://tinyurl.com/2bd3nako):
```js
1e20 + 0.1 + -1e20; // => 0
Math.sumPrecise([1e20, 0.1, -1e20]); // => 0.1
```
Nothing.

#### Stage 2 proposals[](#index)
[*CommonJS entry points:*](#commonjs-api)
Expand Down
2 changes: 2 additions & 0 deletions packages/core-js/actual/math/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';
var parent = require('../../stable/math');
require('../../modules/es.array.iterator');
require('../../modules/esnext.math.f16round');
require('../../modules/esnext.math.sum-precise');

module.exports = parent;
6 changes: 6 additions & 0 deletions packages/core-js/actual/math/sum-precise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';
require('../../modules/es.array.iterator');
require('../../modules/esnext.math.sum-precise');
var path = require('../../internals/path');

module.exports = path.Math.sumPrecise;
2 changes: 0 additions & 2 deletions packages/core-js/full/math/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
var parent = require('../../actual/math');
require('../../modules/es.array.iterator');
require('../../modules/esnext.math.clamp');
require('../../modules/esnext.math.deg-per-rad');
require('../../modules/esnext.math.degrees');
Expand All @@ -10,7 +9,6 @@ require('../../modules/esnext.math.radians');
require('../../modules/esnext.math.scale');
require('../../modules/esnext.math.seeded-prng');
require('../../modules/esnext.math.signbit');
require('../../modules/esnext.math.sum-precise');
// TODO: Remove from `core-js@4`
require('../../modules/esnext.math.iaddh');
require('../../modules/esnext.math.isubh');
Expand Down
6 changes: 2 additions & 4 deletions packages/core-js/full/math/sum-precise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';
require('../../modules/es.array.iterator');
require('../../modules/esnext.math.sum-precise');
var path = require('../../internals/path');
var parent = require('../../actual/math/sum-precise');

module.exports = path.Math.sumPrecise;
module.exports = parent;
2 changes: 1 addition & 1 deletion packages/core-js/modules/esnext.math.sum-precise.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var twosum = function (x, y) {

// `Math.sumPrecise` method
// https://github.com/tc39/proposal-math-sum
$({ target: 'Math', stat: true, forced: true }, {
$({ target: 'Math', stat: true }, {
// eslint-disable-next-line max-statements -- ok
sumPrecise: function sumPrecise(items) {
var numbers = [];
Expand Down
2 changes: 0 additions & 2 deletions packages/core-js/stage/2.7.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';
var parent = require('./3');

require('../proposals/math-sum');

module.exports = parent;
1 change: 1 addition & 0 deletions packages/core-js/stage/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require('../proposals/decorator-metadata-v2');
require('../proposals/explicit-resource-management');
require('../proposals/float16');
require('../proposals/json-parse-with-source');
require('../proposals/math-sum');
require('../proposals/promise-try');
require('../proposals/regexp-escaping');
// TODO: Obsolete versions, remove from `core-js@4`
Expand Down
2 changes: 1 addition & 1 deletion tests/entries/unit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
ok(load(NS, 'json/parse')('[42]', (key, value, { source }) => typeof value == 'number' ? source + source : value)[0] === '4242');
ok(typeof load(NS, 'json/raw-json')(42) == 'object');
ok(load(NS, 'math/f16round')(1.337) === 1.3369140625);
ok(load(NS, 'math/sum-precise')([1, 2, 3]) === 6);
ok(load(NS, 'promise/try')(() => 42) instanceof load(NS, 'promise'));
ok(load(NS, 'regexp/escape')('10$') === '\\x310\\$');
ok(load(NS, 'symbol/dispose'));
Expand Down Expand Up @@ -798,7 +799,6 @@ for (PATH of ['core-js-pure', 'core-js']) {
ok(load(NS, 'math/scale')(3, 1, 2, 1, 2) === 3);
ok(typeof load(NS, 'math/seeded-prng')({ seed: 42 }).next().value === 'number');
ok(load(NS, 'math/signbit')(-2) === true);
ok(load(NS, 'math/sum-precise')([1, 2, 3]) === 6);
ok(load(NS, 'math/umulh')(0xFFFFFFFF, 7) === 6);
ok(load(NS, 'map/of')([1, 2], [3, 4]) instanceof Map);
ok(load(NS, 'map/reduce')(new Map([[1, 2], [2, 3], [3, 4]]), (a, b) => a + b) === 9);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-pure/esnext.math.sum-precise.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a51fc0d

Please sign in to comment.