Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Math Extensions proposal to Stage 1 TC39 0716 #227

Merged
merged 1 commit into from
Aug 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Changelog
##### Unreleased
- Added `Math.{clamp, deg-per-rad, degrees, fscale, rad-per-deg, radians, scale}`, [stage 1 proposal](https://github.com/rwaldron/proposal-math-extensions), [#226](https://github.com/zloirock/core-js/issues/226)

##### 2.4.1 - 2016.07.18
- fixed `script` tag for some parsers, [#204](https://github.com/zloirock/core-js/issues/204), [#216](https://github.com/zloirock/core-js/issues/216)
- removed some unused variables, [#217](https://github.com/zloirock/core-js/issues/217), [#218](https://github.com/zloirock/core-js/issues/218)
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,35 @@ new Observable(observer => {
}).forEach(it => console.log(it))
.then(_ => console.log('!'));
```
* `Math.{clamp, DEG_PER_RAD, degrees, fscale, rad-per-deg, radians, scale}`
[proposal](https://github.com/rwaldron/proposal-math-extensions) - modules
[`es7.math.clamp`](https://github.com/zloirock/core-js/blob/v2.X.X/modules/es7.math.clamp.js),
[`es7.math.DEG_PER_RAD`](https://github.com/zloirock/core-js/blob/v2.X.X/modules/es7.math.DEG_PER_RAD.js),
[`es7.math.degrees`](https://github.com/zloirock/core-js/blob/v2.X.X/modules/es7.math.degrees.js),
[`es7.math.fscale`](https://github.com/zloirock/core-js/blob/v2.X.X/modules/es7.math.fscale.js),
[`es7.math.RAD_PER_DEG`](https://github.com/zloirock/core-js/blob/v2.X.X/modules/es7.math.RAD_PER_DEG.js),
[`es7.math.radians`](https://github.com/zloirock/core-js/blob/v2.X.X/modules/es7.math.radians.js) and
[`es7.math.scale`](https://github.com/zloirock/core-js/blob/v2.X.X/modules/es7.math.scale.js)
```js
Math
.clamp(x, lower, upper) -> number
.DEG_PER_RAD -> number
.degrees(radians) -> number
.fscale(x, inLow, inHigh, outLow, outHigh) -> number
.RAD_PER_DEG -> number
.radians(degrees) -> number
.scale(x, inLow, inHigh, outLow, outHigh) -> number
```
[*CommonJS entry points:*](#commonjs)
```js
core-js(/library)/fn/math/clamp
core-js(/library)/fn/math/deg-per-rad
core-js(/library)/fn/math/degrees
core-js(/library)/fn/math/fscale
core-js(/library)/fn/math/rad-per-deg
core-js(/library)/fn/math/radians
core-js(/library)/fn/math/scale
```

#### Stage 0 proposals
[*CommonJS entry points:*](#commonjs)
Expand Down
7 changes: 7 additions & 0 deletions build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,16 @@ module.exports = {
'es7.set.to-json',
'es7.system.global',
'es7.error.is-error',
'es7.math.clamp',
'es7.math.deg-per-rad',
'es7.math.degrees',
'es7.math.fscale',
'es7.math.iaddh',
'es7.math.isubh',
'es7.math.imulh',
'es7.math.rad-per-deg',
'es7.math.radians',
'es7.math.scale',
'es7.math.umulh',
'es7.reflect.define-metadata',
'es7.reflect.delete-metadata',
Expand Down
7 changes: 7 additions & 0 deletions es7/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ require('../modules/es7.map.to-json');
require('../modules/es7.set.to-json');
require('../modules/es7.system.global');
require('../modules/es7.error.is-error');
require('../modules/es7.math.clamp');
require('../modules/es7.math.deg-per-rad');
require('../modules/es7.math.degrees');
require('../modules/es7.math.fscale');
require('../modules/es7.math.iaddh');
require('../modules/es7.math.isubh');
require('../modules/es7.math.imulh');
require('../modules/es7.math.rad-per-deg');
require('../modules/es7.math.radians');
require('../modules/es7.math.scale');
require('../modules/es7.math.umulh');
require('../modules/es7.reflect.define-metadata');
require('../modules/es7.reflect.delete-metadata');
Expand Down
7 changes: 7 additions & 0 deletions es7/math.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
require('../modules/es7.math.clamp');
require('../modules/es7.math.deg-per-rad');
require('../modules/es7.math.degrees');
require('../modules/es7.math.fscale');
require('../modules/es7.math.iaddh');
require('../modules/es7.math.isubh');
require('../modules/es7.math.imulh');
require('../modules/es7.math.rad-per-deg');
require('../modules/es7.math.radians');
require('../modules/es7.math.scale');
require('../modules/es7.math.umulh');
module.exports = require('../modules/_core').Math;
2 changes: 2 additions & 0 deletions fn/math/clamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.clamp');
module.exports = require('../../modules/_core').Math.clamp;
2 changes: 2 additions & 0 deletions fn/math/deg-per-rad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.deg-per-rad');
module.exports = Math.PI / 180;
2 changes: 2 additions & 0 deletions fn/math/degrees.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.degrees');
module.exports = require('../../modules/_core').Math.degrees;
2 changes: 2 additions & 0 deletions fn/math/fscale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.fscale');
module.exports = require('../../modules/_core').Math.fscale;
7 changes: 7 additions & 0 deletions fn/math/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ require('../../modules/es6.math.sign');
require('../../modules/es6.math.sinh');
require('../../modules/es6.math.tanh');
require('../../modules/es6.math.trunc');
require('../../modules/es7.math.clamp');
require('../../modules/es7.math.deg-per-rad');
require('../../modules/es7.math.degrees');
require('../../modules/es7.math.fscale');
require('../../modules/es7.math.iaddh');
require('../../modules/es7.math.isubh');
require('../../modules/es7.math.imulh');
require('../../modules/es7.math.rad-per-deg');
require('../../modules/es7.math.radians');
require('../../modules/es7.math.scale');
require('../../modules/es7.math.umulh');
module.exports = require('../../modules/_core').Math;
2 changes: 2 additions & 0 deletions fn/math/rad-per-deg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.rad-per-deg');
module.exports = 180 / Math.PI;
2 changes: 2 additions & 0 deletions fn/math/radians.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.radians');
module.exports = require('../../modules/_core').Math.radians;
2 changes: 2 additions & 0 deletions fn/math/scale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.scale');
module.exports = require('../../modules/_core').Math.scale;
7 changes: 7 additions & 0 deletions library/es7/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ require('../modules/es7.map.to-json');
require('../modules/es7.set.to-json');
require('../modules/es7.system.global');
require('../modules/es7.error.is-error');
require('../modules/es7.math.clamp');
require('../modules/es7.math.deg-per-rad');
require('../modules/es7.math.degrees');
require('../modules/es7.math.fscale');
require('../modules/es7.math.iaddh');
require('../modules/es7.math.isubh');
require('../modules/es7.math.imulh');
require('../modules/es7.math.rad-per-deg');
require('../modules/es7.math.radians');
require('../modules/es7.math.scale');
require('../modules/es7.math.umulh');
require('../modules/es7.reflect.define-metadata');
require('../modules/es7.reflect.delete-metadata');
Expand Down
7 changes: 7 additions & 0 deletions library/es7/math.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
require('../modules/es7.math.clamp');
require('../modules/es7.math.deg-per-rad');
require('../modules/es7.math.degrees');
require('../modules/es7.math.fscale');
require('../modules/es7.math.iaddh');
require('../modules/es7.math.isubh');
require('../modules/es7.math.imulh');
require('../modules/es7.math.rad-per-deg');
require('../modules/es7.math.radians');
require('../modules/es7.math.scale');
require('../modules/es7.math.umulh');
module.exports = require('../modules/_core').Math;
2 changes: 2 additions & 0 deletions library/fn/math/clamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.clamp');
module.exports = require('../../modules/_core').Math.clamp;
2 changes: 2 additions & 0 deletions library/fn/math/deg-per-rad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.deg-per-rad');
module.exports = Math.PI / 180;
2 changes: 2 additions & 0 deletions library/fn/math/degrees.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.degrees');
module.exports = require('../../modules/_core').Math.degrees;
2 changes: 2 additions & 0 deletions library/fn/math/fscale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.fscale');
module.exports = require('../../modules/_core').Math.fscale;
7 changes: 7 additions & 0 deletions library/fn/math/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ require('../../modules/es6.math.sign');
require('../../modules/es6.math.sinh');
require('../../modules/es6.math.tanh');
require('../../modules/es6.math.trunc');
require('../../modules/es7.math.clamp');
require('../../modules/es7.math.deg-per-rad');
require('../../modules/es7.math.degrees');
require('../../modules/es7.math.fscale');
require('../../modules/es7.math.iaddh');
require('../../modules/es7.math.isubh');
require('../../modules/es7.math.imulh');
require('../../modules/es7.math.rad-per-deg');
require('../../modules/es7.math.radians');
require('../../modules/es7.math.scale');
require('../../modules/es7.math.umulh');
module.exports = require('../../modules/_core').Math;
2 changes: 2 additions & 0 deletions library/fn/math/rad-per-deg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.rad-per-deg');
module.exports = 180 / Math.PI;
2 changes: 2 additions & 0 deletions library/fn/math/radians.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.radians');
module.exports = require('../../modules/_core').Math.radians;
2 changes: 2 additions & 0 deletions library/fn/math/scale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../../modules/es7.math.scale');
module.exports = require('../../modules/_core').Math.scale;
22 changes: 22 additions & 0 deletions library/modules/_math-fround.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 20.2.2.16 Math.fround(x)
var sign = require('./_math-sign')
, pow = Math.pow
, EPSILON = pow(2, -52)
, EPSILON32 = pow(2, -23)
, MAX32 = pow(2, 127) * (2 - EPSILON32)
, MIN32 = pow(2, -126);

var roundTiesToEven = function(n){
return n + 1 / EPSILON - 1 / EPSILON;
};

module.exports = Math.fround || function fround(x){
var $abs = Math.abs(x)
, $sign = sign(x)
, a, result;
if($abs < MIN32)return $sign * roundTiesToEven($abs / MIN32 / EPSILON32) * MIN32 * EPSILON32;
a = (1 + EPSILON32 / EPSILON) * $abs;
result = a - (a - $abs);
if(result > MAX32 || result != result)return $sign * Infinity;
return $sign * result;
};
24 changes: 24 additions & 0 deletions library/modules/_math-scale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// https://rwaldron.github.io/proposal-math-extensions/
var _isNaN = function(x) {x != x};

module.exports = Math.scale || function scale(x, inLow, inHigh, outLow, outHigh) {
if (arguments.length === 0) {
return NaN;
}

if (_isNaN(x) ||
_isNaN(inLow) ||
_isNaN(inHigh) ||
_isNaN(outLow) ||
_isNaN(outHigh)) {
return NaN;
}

if (x === Infinity ||
x === -Infinity) {
return x;
}

return (x - inLow) * (outHigh - outLow) /
(inHigh - inLow) + outLow;
};
27 changes: 3 additions & 24 deletions library/modules/es6.math.fround.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
// 20.2.2.16 Math.fround(x)
var $export = require('./_export')
, sign = require('./_math-sign')
, pow = Math.pow
, EPSILON = pow(2, -52)
, EPSILON32 = pow(2, -23)
, MAX32 = pow(2, 127) * (2 - EPSILON32)
, MIN32 = pow(2, -126);
var $export = require('./_export')
, fround = require('./_math-fround');

var roundTiesToEven = function(n){
return n + 1 / EPSILON - 1 / EPSILON;
};


$export($export.S, 'Math', {
fround: function fround(x){
var $abs = Math.abs(x)
, $sign = sign(x)
, a, result;
if($abs < MIN32)return $sign * roundTiesToEven($abs / MIN32 / EPSILON32) * MIN32 * EPSILON32;
a = (1 + EPSILON32 / EPSILON) * $abs;
result = a - (a - $abs);
if(result > MAX32 || result != result)return $sign * Infinity;
return $sign * result;
}
});
$export($export.S, 'Math', {fround: fround});
8 changes: 8 additions & 0 deletions library/modules/es7.math.clamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// https://rwaldron.github.io/proposal-math-extensions/
var $export = require('./_export');

$export($export.S, 'Math', {
clamp: function clamp(x, lower, upper) {
return Math.min(upper, Math.max(lower, x));
}
});
4 changes: 4 additions & 0 deletions library/modules/es7.math.deg-per-rad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// https://rwaldron.github.io/proposal-math-extensions/
var $export = require('./_export');

$export($export.S, 'Math', {DEG_PER_RAD: Math.PI / 180});
9 changes: 9 additions & 0 deletions library/modules/es7.math.degrees.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// https://rwaldron.github.io/proposal-math-extensions/
var $export = require('./_export')
, RAD_PER_DEG = 180 / Math.PI;

$export($export.S, 'Math', {
degrees: function degrees(radians) {
return radians * RAD_PER_DEG;
}
});
10 changes: 10 additions & 0 deletions library/modules/es7.math.fscale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// https://rwaldron.github.io/proposal-math-extensions/
var $export = require('./_export')
, scale = require('./_math-scale')
, fround = require('./_math-fround');

$export($export.S, 'Math', {
fscale: function fscale(x, inLow, inHigh, outLow, outHigh) {
return fround(scale(x, inLow, inHigh, outLow, outHigh));
}
});
4 changes: 4 additions & 0 deletions library/modules/es7.math.rad-per-deg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// https://rwaldron.github.io/proposal-math-extensions/
var $export = require('./_export');

$export($export.S, 'Math', {RAD_PER_DEG: 180 / Math.PI});
9 changes: 9 additions & 0 deletions library/modules/es7.math.radians.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// https://rwaldron.github.io/proposal-math-extensions/
var $export = require('./_export')
, DEG_PER_RAD = Math.PI / 180;

$export($export.S, 'Math', {
radians: function radians(degrees) {
return degrees * DEG_PER_RAD;
}
});
5 changes: 5 additions & 0 deletions library/modules/es7.math.scale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// https://rwaldron.github.io/proposal-math-extensions/
var $export = require('./_export')
, scale = require('./_math-scale');

$export($export.S, 'Math', {scale: scale});
7 changes: 7 additions & 0 deletions library/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,16 @@ require('./modules/es7.map.to-json');
require('./modules/es7.set.to-json');
require('./modules/es7.system.global');
require('./modules/es7.error.is-error');
require('./modules/es7.math.clamp');
require('./modules/es7.math.deg-per-rad');
require('./modules/es7.math.degrees');
require('./modules/es7.math.fscale');
require('./modules/es7.math.iaddh');
require('./modules/es7.math.isubh');
require('./modules/es7.math.imulh');
require('./modules/es7.math.rad-per-deg');
require('./modules/es7.math.radians');
require('./modules/es7.math.scale');
require('./modules/es7.math.umulh');
require('./modules/es7.reflect.define-metadata');
require('./modules/es7.reflect.delete-metadata');
Expand Down
7 changes: 7 additions & 0 deletions library/stage/1.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
require('../modules/es7.math.clamp');
require('../modules/es7.math.deg-per-rad');
require('../modules/es7.math.degrees');
require('../modules/es7.math.fscale');
require('../modules/es7.math.rad-per-deg');
require('../modules/es7.math.radians');
require('../modules/es7.math.scale');
require('../modules/es7.string.trim-left');
require('../modules/es7.string.trim-right');
require('../modules/es7.string.match-all');
Expand Down
22 changes: 22 additions & 0 deletions modules/_math-fround.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 20.2.2.16 Math.fround(x)
var sign = require('./_math-sign')
, pow = Math.pow
, EPSILON = pow(2, -52)
, EPSILON32 = pow(2, -23)
, MAX32 = pow(2, 127) * (2 - EPSILON32)
, MIN32 = pow(2, -126);

var roundTiesToEven = function(n){
return n + 1 / EPSILON - 1 / EPSILON;
};

module.exports = Math.fround || function fround(x){
var $abs = Math.abs(x)
, $sign = sign(x)
, a, result;
if($abs < MIN32)return $sign * roundTiesToEven($abs / MIN32 / EPSILON32) * MIN32 * EPSILON32;
a = (1 + EPSILON32 / EPSILON) * $abs;
result = a - (a - $abs);
if(result > MAX32 || result != result)return $sign * Infinity;
return $sign * result;
};
Loading