diff --git a/CHANGELOG.md b/CHANGELOG.md index b597d55d6e09..fa62e491d407 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index ba3ff28b2cd9..aa18c50b82f7 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/build/config.js b/build/config.js index f8b9d35bac91..cd6c9b1f8514 100644 --- a/build/config.js +++ b/build/config.js @@ -157,9 +157,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', diff --git a/es7/index.js b/es7/index.js index b8c90b86e7f0..3e34f56e8cb3 100644 --- a/es7/index.js +++ b/es7/index.js @@ -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'); diff --git a/es7/math.js b/es7/math.js index bdb8a81c3c4d..17469fa364cc 100644 --- a/es7/math.js +++ b/es7/math.js @@ -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; diff --git a/fn/math/clamp.js b/fn/math/clamp.js new file mode 100644 index 000000000000..f227cbae8ecf --- /dev/null +++ b/fn/math/clamp.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.clamp'); +module.exports = require('../../modules/_core').Math.clamp; \ No newline at end of file diff --git a/fn/math/deg-per-rad.js b/fn/math/deg-per-rad.js new file mode 100644 index 000000000000..a555de0706a2 --- /dev/null +++ b/fn/math/deg-per-rad.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.deg-per-rad'); +module.exports = Math.PI / 180; diff --git a/fn/math/degrees.js b/fn/math/degrees.js new file mode 100644 index 000000000000..f7fc4cd34e7b --- /dev/null +++ b/fn/math/degrees.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.degrees'); +module.exports = require('../../modules/_core').Math.degrees; \ No newline at end of file diff --git a/fn/math/fscale.js b/fn/math/fscale.js new file mode 100644 index 000000000000..177a43de9df3 --- /dev/null +++ b/fn/math/fscale.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.fscale'); +module.exports = require('../../modules/_core').Math.fscale; \ No newline at end of file diff --git a/fn/math/index.js b/fn/math/index.js index 8a2664b18d56..71b4fb31af9c 100644 --- a/fn/math/index.js +++ b/fn/math/index.js @@ -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; \ No newline at end of file diff --git a/fn/math/rad-per-deg.js b/fn/math/rad-per-deg.js new file mode 100644 index 000000000000..e8ef0242f163 --- /dev/null +++ b/fn/math/rad-per-deg.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.rad-per-deg'); +module.exports = 180 / Math.PI; diff --git a/fn/math/radians.js b/fn/math/radians.js new file mode 100644 index 000000000000..017c6751e7fa --- /dev/null +++ b/fn/math/radians.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.radians'); +module.exports = require('../../modules/_core').Math.radians; \ No newline at end of file diff --git a/fn/math/scale.js b/fn/math/scale.js new file mode 100644 index 000000000000..c3ba0cb8562b --- /dev/null +++ b/fn/math/scale.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.scale'); +module.exports = require('../../modules/_core').Math.scale; \ No newline at end of file diff --git a/library/es7/index.js b/library/es7/index.js index b8c90b86e7f0..3e34f56e8cb3 100644 --- a/library/es7/index.js +++ b/library/es7/index.js @@ -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'); diff --git a/library/es7/math.js b/library/es7/math.js index bdb8a81c3c4d..17469fa364cc 100644 --- a/library/es7/math.js +++ b/library/es7/math.js @@ -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; diff --git a/library/fn/math/clamp.js b/library/fn/math/clamp.js new file mode 100644 index 000000000000..f227cbae8ecf --- /dev/null +++ b/library/fn/math/clamp.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.clamp'); +module.exports = require('../../modules/_core').Math.clamp; \ No newline at end of file diff --git a/library/fn/math/deg-per-rad.js b/library/fn/math/deg-per-rad.js new file mode 100644 index 000000000000..a555de0706a2 --- /dev/null +++ b/library/fn/math/deg-per-rad.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.deg-per-rad'); +module.exports = Math.PI / 180; diff --git a/library/fn/math/degrees.js b/library/fn/math/degrees.js new file mode 100644 index 000000000000..f7fc4cd34e7b --- /dev/null +++ b/library/fn/math/degrees.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.degrees'); +module.exports = require('../../modules/_core').Math.degrees; \ No newline at end of file diff --git a/library/fn/math/fscale.js b/library/fn/math/fscale.js new file mode 100644 index 000000000000..177a43de9df3 --- /dev/null +++ b/library/fn/math/fscale.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.fscale'); +module.exports = require('../../modules/_core').Math.fscale; \ No newline at end of file diff --git a/library/fn/math/index.js b/library/fn/math/index.js index 8a2664b18d56..71b4fb31af9c 100644 --- a/library/fn/math/index.js +++ b/library/fn/math/index.js @@ -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; \ No newline at end of file diff --git a/library/fn/math/rad-per-deg.js b/library/fn/math/rad-per-deg.js new file mode 100644 index 000000000000..e8ef0242f163 --- /dev/null +++ b/library/fn/math/rad-per-deg.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.rad-per-deg'); +module.exports = 180 / Math.PI; diff --git a/library/fn/math/radians.js b/library/fn/math/radians.js new file mode 100644 index 000000000000..017c6751e7fa --- /dev/null +++ b/library/fn/math/radians.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.radians'); +module.exports = require('../../modules/_core').Math.radians; \ No newline at end of file diff --git a/library/fn/math/scale.js b/library/fn/math/scale.js new file mode 100644 index 000000000000..cde3e31210d8 --- /dev/null +++ b/library/fn/math/scale.js @@ -0,0 +1,2 @@ +require('../../modules/es7.math.scale'); +module.exports = require('../../modules/_core').Math.scale; diff --git a/library/modules/_math-fround.js b/library/modules/_math-fround.js new file mode 100644 index 000000000000..61c9d0426b6f --- /dev/null +++ b/library/modules/_math-fround.js @@ -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; +}; diff --git a/library/modules/_math-scale.js b/library/modules/_math-scale.js new file mode 100644 index 000000000000..288f90967da9 --- /dev/null +++ b/library/modules/_math-scale.js @@ -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; +}; diff --git a/library/modules/es6.math.fround.js b/library/modules/es6.math.fround.js index 01a88862efc7..0e8f9247cb5a 100644 --- a/library/modules/es6.math.fround.js +++ b/library/modules/es6.math.fround.js @@ -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; - } -}); \ No newline at end of file +$export($export.S, 'Math', {fround: fround}); diff --git a/library/modules/es7.math.clamp.js b/library/modules/es7.math.clamp.js new file mode 100644 index 000000000000..319cda60997c --- /dev/null +++ b/library/modules/es7.math.clamp.js @@ -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)); + } +}); diff --git a/library/modules/es7.math.deg-per-rad.js b/library/modules/es7.math.deg-per-rad.js new file mode 100644 index 000000000000..30d312b9d8a6 --- /dev/null +++ b/library/modules/es7.math.deg-per-rad.js @@ -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}); diff --git a/library/modules/es7.math.degrees.js b/library/modules/es7.math.degrees.js new file mode 100644 index 000000000000..298ab24b48b8 --- /dev/null +++ b/library/modules/es7.math.degrees.js @@ -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; + } +}); diff --git a/library/modules/es7.math.fscale.js b/library/modules/es7.math.fscale.js new file mode 100644 index 000000000000..5942e6004d3a --- /dev/null +++ b/library/modules/es7.math.fscale.js @@ -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)); + } +}); diff --git a/library/modules/es7.math.rad-per-deg.js b/library/modules/es7.math.rad-per-deg.js new file mode 100644 index 000000000000..7ef99158ee87 --- /dev/null +++ b/library/modules/es7.math.rad-per-deg.js @@ -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}); diff --git a/library/modules/es7.math.radians.js b/library/modules/es7.math.radians.js new file mode 100644 index 000000000000..130f0b2b041f --- /dev/null +++ b/library/modules/es7.math.radians.js @@ -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; + } +}); diff --git a/library/modules/es7.math.scale.js b/library/modules/es7.math.scale.js new file mode 100644 index 000000000000..3eaa7ecdf388 --- /dev/null +++ b/library/modules/es7.math.scale.js @@ -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}); diff --git a/library/shim.js b/library/shim.js index 6db125683ce9..5fb825ab52d8 100644 --- a/library/shim.js +++ b/library/shim.js @@ -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'); diff --git a/library/stage/1.js b/library/stage/1.js index 230fe13adad2..7864e823601b 100644 --- a/library/stage/1.js +++ b/library/stage/1.js @@ -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'); diff --git a/modules/_math-fround.js b/modules/_math-fround.js new file mode 100644 index 000000000000..61c9d0426b6f --- /dev/null +++ b/modules/_math-fround.js @@ -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; +}; diff --git a/modules/_math-scale.js b/modules/_math-scale.js new file mode 100644 index 000000000000..288f90967da9 --- /dev/null +++ b/modules/_math-scale.js @@ -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; +}; diff --git a/modules/es6.math.fround.js b/modules/es6.math.fround.js index 01a88862efc7..0e8f9247cb5a 100644 --- a/modules/es6.math.fround.js +++ b/modules/es6.math.fround.js @@ -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; - } -}); \ No newline at end of file +$export($export.S, 'Math', {fround: fround}); diff --git a/modules/es7.math.clamp.js b/modules/es7.math.clamp.js new file mode 100644 index 000000000000..319cda60997c --- /dev/null +++ b/modules/es7.math.clamp.js @@ -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)); + } +}); diff --git a/modules/es7.math.deg-per-rad.js b/modules/es7.math.deg-per-rad.js new file mode 100644 index 000000000000..30d312b9d8a6 --- /dev/null +++ b/modules/es7.math.deg-per-rad.js @@ -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}); diff --git a/modules/es7.math.degrees.js b/modules/es7.math.degrees.js new file mode 100644 index 000000000000..298ab24b48b8 --- /dev/null +++ b/modules/es7.math.degrees.js @@ -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; + } +}); diff --git a/modules/es7.math.fscale.js b/modules/es7.math.fscale.js new file mode 100644 index 000000000000..5942e6004d3a --- /dev/null +++ b/modules/es7.math.fscale.js @@ -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)); + } +}); diff --git a/modules/es7.math.rad-per-deg.js b/modules/es7.math.rad-per-deg.js new file mode 100644 index 000000000000..7ef99158ee87 --- /dev/null +++ b/modules/es7.math.rad-per-deg.js @@ -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}); diff --git a/modules/es7.math.radians.js b/modules/es7.math.radians.js new file mode 100644 index 000000000000..130f0b2b041f --- /dev/null +++ b/modules/es7.math.radians.js @@ -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; + } +}); diff --git a/modules/es7.math.scale.js b/modules/es7.math.scale.js new file mode 100644 index 000000000000..3eaa7ecdf388 --- /dev/null +++ b/modules/es7.math.scale.js @@ -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}); diff --git a/shim.js b/shim.js index 6db125683ce9..5fb825ab52d8 100644 --- a/shim.js +++ b/shim.js @@ -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'); diff --git a/stage/1.js b/stage/1.js index 230fe13adad2..7864e823601b 100644 --- a/stage/1.js +++ b/stage/1.js @@ -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'); diff --git a/tests/commonjs.ls b/tests/commonjs.ls index 82bcd5d6d91e..cea6ffe0107e 100644 --- a/tests/commonjs.ls +++ b/tests/commonjs.ls @@ -111,9 +111,16 @@ for P in <[.. ../library]> ok require("#P/fn/math/sinh")(-0) is -0 ok require("#P/fn/math/tanh")(Infinity) is 1 ok require("#P/fn/math/trunc")(1.5) is 1 + ok require("#P/fn/math/clamp")(6 2 4) is 4 + ok require("#P/fn/math/deg-per-rad") is Math.PI / 180 + ok require("#P/fn/math/degrees")(Math.PI) is 180 + ok require("#P/fn/math/fscale")(3 1 2 1 2) is 3 ok require("#P/fn/math/iaddh")(3 2 0xffffffff 4) is 7 ok require("#P/fn/math/isubh")(3 4 0xffffffff 2) is 1 ok require("#P/fn/math/imulh")(0xffffffff 7) is -1 + ok require("#P/fn/math/rad-per-deg") is 180 / Math.PI + ok require("#P/fn/math/radians")(180) is Math.PI + ok require("#P/fn/math/scale")(3 1 2 1 2) is 3 ok require("#P/fn/math/umulh")(0xffffffff 7) is 6 ok require("#P/fn/number/constructor")(\5) is 5 ok require("#P/fn/number/epsilon") is Math.pow 2 -52 diff --git a/tests/es.js b/tests/es.js index 7de710d0fceb..41d80eed0a0f 100644 --- a/tests/es.js +++ b/tests/es.js @@ -10147,6 +10147,80 @@ }); }).call(this); +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.clamp', function(assert){ + var clamp; + clamp = Math.clamp; + assert.isFunction(clamp); + assert.name(clamp, 'clamp'); + assert.arity(clamp, 3); + assert.looksNative(clamp); + assert.nonEnumerable(Math, 'clamp'); + assert.same(clamp(2, 4, 6), 4); + assert.same(clamp(4, 2, 6), 4); + assert.same(clamp(6, 2, 4), 4); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES6'); + test('Math.DEG_PER_RAD', function(assert){ + var DEG_PER_RAD; + DEG_PER_RAD = Math.DEG_PER_RAD; + assert.ok('DEG_PER_RAD' in Math, 'DEG_PER_RAD in Math'); + assert.nonEnumerable(Math, 'DEG_PER_RAD'); + assert.strictEqual(DEG_PER_RAD, Math.PI / 180, 'Is Math.PI / 180'); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.degrees', function(assert){ + var degrees; + degrees = Math.degrees; + assert.isFunction(degrees); + assert.name(degrees, 'degrees'); + assert.arity(degrees, 1); + assert.looksNative(degrees); + assert.nonEnumerable(Math, 'degrees'); + assert.same(degrees(0), 0); + assert.same(degrees(Math.PI / 2), 90); + assert.same(degrees(Math.PI), 180); + assert.same(degrees(3 * Math.PI / 2), 270); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.fscale', function(assert){ + var fscale, fround, PI; + fscale = Math.fscale, fround = Math.fround, PI = Math.PI; + assert.isFunction(fscale); + assert.name(fscale, 'fscale'); + assert.arity(fscale, 5); + assert.looksNative(fscale); + assert.nonEnumerable(Math, 'fscale'); + assert.same(fscale(3, 1, 2, 1, 2), 3); + assert.same(fscale(0, 3, 5, 8, 10), 5); + assert.same(fscale(1, 1, 1, 1, 1), NaN); + assert.same(fscale(-1, -1, -1, -1, -1), NaN); + assert.strictEqual(fscale(3, 1, 2, 1, PI), fround((3 - 1) * (PI - 1) / (2 - 1) + 1)); + }); +}).call(this); + // Generated by LiveScript 1.4.0 (function(){ var module, test; @@ -10209,6 +10283,60 @@ }); }).call(this); +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES6'); + test('Math.RAD_PER_DEG', function(assert){ + var RAD_PER_DEG; + RAD_PER_DEG = Math.RAD_PER_DEG; + assert.ok('RAD_PER_DEG' in Math, 'RAD_PER_DEG in Math'); + assert.nonEnumerable(Math, 'RAD_PER_DEG'); + assert.strictEqual(RAD_PER_DEG, 180 / Math.PI, 'Is 180 / Math.PI'); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.radians', function(assert){ + var radians; + radians = Math.radians; + assert.isFunction(radians); + assert.name(radians, 'radians'); + assert.arity(radians, 1); + assert.looksNative(radians); + assert.nonEnumerable(Math, 'radians'); + assert.same(radians(0), 0); + assert.same(radians(90), Math.PI / 2); + assert.same(radians(180), Math.PI); + assert.same(radians(270), 3 * Math.PI / 2); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.scale', function(assert){ + var scale; + scale = Math.scale; + assert.isFunction(scale); + assert.name(scale, 'scale'); + assert.arity(scale, 5); + assert.looksNative(scale); + assert.nonEnumerable(Math, 'scale'); + assert.same(scale(3, 1, 2, 1, 2), 3); + assert.same(scale(0, 3, 5, 8, 10), 5); + assert.same(scale(1, 1, 1, 1, 1), NaN); + assert.same(scale(-1, -1, -1, -1, -1), NaN); + }); +}).call(this); + // Generated by LiveScript 1.4.0 (function(){ var module, test; diff --git a/tests/library.js b/tests/library.js index d87289ecae94..dcfccf4c072a 100644 --- a/tests/library.js +++ b/tests/library.js @@ -7180,6 +7180,69 @@ }); }).call(this); +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.clamp', function(assert){ + var clamp; + clamp = core.Math.clamp; + assert.isFunction(clamp); + assert.arity(clamp, 3); + assert.same(clamp(2, 4, 6), 4); + assert.same(clamp(4, 2, 6), 4); + assert.same(clamp(6, 2, 4), 4); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES6'); + test('Math.DEG_PER_RAD', function(assert){ + var DEG_PER_RAD; + DEG_PER_RAD = core.Math.DEG_PER_RAD; + assert.ok('DEG_PER_RAD' in core.Math, 'DEG_PER_RAD in Math'); + assert.strictEqual(DEG_PER_RAD, Math.PI / 180, 'Is Math.PI / 180'); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.degrees', function(assert){ + var degrees; + degrees = core.Math.degrees; + assert.isFunction(degrees); + assert.arity(degrees, 1); + assert.same(degrees(0), 0); + assert.same(degrees(Math.PI / 2), 90); + assert.same(degrees(Math.PI), 180); + assert.same(degrees(3 * Math.PI / 2), 270); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.fscale', function(assert){ + var fscale; + fscale = core.Math.fscale; + assert.isFunction(fscale); + assert.arity(fscale, 5); + assert.same(fscale(3, 1, 2, 1, 2), 3); + assert.same(fscale(0, 3, 5, 8, 10), 5); + assert.same(fscale(1, 1, 1, 1, 1), NaN); + assert.same(fscale(-1, -1, -1, -1, -1), NaN); + }); +}).call(this); + // Generated by LiveScript 1.4.0 (function(){ var module, test; @@ -7233,6 +7296,53 @@ }); }).call(this); +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES6'); + test('Math.RAD_PER_DEG', function(assert){ + var RAD_PER_DEG; + RAD_PER_DEG = core.Math.RAD_PER_DEG; + assert.ok('RAD_PER_DEG' in core.Math, 'RAD_PER_DEG in Math'); + assert.strictEqual(RAD_PER_DEG, 180 / Math.PI, 'Is 180 / Math.PI'); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.radians', function(assert){ + var radians; + radians = core.Math.radians; + assert.isFunction(radians); + assert.arity(radians, 1); + assert.same(radians(0), 0); + assert.same(radians(90), Math.PI / 2); + assert.same(radians(180), Math.PI); + assert.same(radians(270), 3 * Math.PI / 2); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.scale', function(assert){ + var scale; + scale = core.Math.scale; + assert.isFunction(scale); + assert.arity(scale, 5); + assert.same(scale(3, 1, 2, 1, 2), 3); + assert.same(scale(0, 3, 5, 8, 10), 5); + assert.same(scale(1, 1, 1, 1, 1), NaN); + assert.same(scale(-1, -1, -1, -1, -1), NaN); + }); +}).call(this); + // Generated by LiveScript 1.4.0 (function(){ var module, test; diff --git a/tests/library/es7.math.clamp.ls b/tests/library/es7.math.clamp.ls new file mode 100644 index 000000000000..b370748f513d --- /dev/null +++ b/tests/library/es7.math.clamp.ls @@ -0,0 +1,10 @@ +{module, test} = QUnit +module \ES7 + +test 'Math.clamp' (assert)!-> + {clamp} = core.Math + assert.isFunction clamp + assert.arity clamp, 3 + assert.same clamp(2, 4, 6), 4 + assert.same clamp(4, 2, 6), 4 + assert.same clamp(6, 2, 4), 4 diff --git a/tests/library/es7.math.deg-per-rad.ls b/tests/library/es7.math.deg-per-rad.ls new file mode 100644 index 000000000000..03ced40e8df2 --- /dev/null +++ b/tests/library/es7.math.deg-per-rad.ls @@ -0,0 +1,7 @@ +{module, test} = QUnit +module \ES6 + +test 'Math.DEG_PER_RAD' (assert)!-> + {DEG_PER_RAD} = core.Math + assert.ok \DEG_PER_RAD of core.Math, 'DEG_PER_RAD in Math' + assert.strictEqual DEG_PER_RAD, Math.PI / 180, 'Is Math.PI / 180' \ No newline at end of file diff --git a/tests/library/es7.math.degrees.ls b/tests/library/es7.math.degrees.ls new file mode 100644 index 000000000000..736a65939ee0 --- /dev/null +++ b/tests/library/es7.math.degrees.ls @@ -0,0 +1,11 @@ +{module, test} = QUnit +module \ES7 + +test 'Math.degrees' (assert)!-> + {degrees} = core.Math + assert.isFunction degrees + assert.arity degrees, 1 + assert.same degrees(0), 0 + assert.same degrees(Math.PI / 2), 90 + assert.same degrees(Math.PI), 180 + assert.same degrees(3 * Math.PI / 2), 270 diff --git a/tests/library/es7.math.fscale.ls b/tests/library/es7.math.fscale.ls new file mode 100644 index 000000000000..bf562df3340a --- /dev/null +++ b/tests/library/es7.math.fscale.ls @@ -0,0 +1,11 @@ +{module, test} = QUnit +module \ES7 + +test 'Math.fscale' (assert)!-> + {fscale} = core.Math + assert.isFunction fscale + assert.arity fscale, 5 + assert.same fscale(3 1 2 1 2), 3 + assert.same fscale(0 3 5 8 10), 5 + assert.same fscale(1 1 1 1 1), NaN + assert.same fscale(-1 -1 -1 -1 -1 ), NaN \ No newline at end of file diff --git a/tests/library/es7.math.rad-per-deg.ls b/tests/library/es7.math.rad-per-deg.ls new file mode 100644 index 000000000000..f94e3a954cd7 --- /dev/null +++ b/tests/library/es7.math.rad-per-deg.ls @@ -0,0 +1,7 @@ +{module, test} = QUnit +module \ES6 + +test 'Math.RAD_PER_DEG' (assert)!-> + {RAD_PER_DEG} = core.Math + assert.ok \RAD_PER_DEG of core.Math, 'RAD_PER_DEG in Math' + assert.strictEqual RAD_PER_DEG, 180 / Math.PI, 'Is 180 / Math.PI' \ No newline at end of file diff --git a/tests/library/es7.math.radians.ls b/tests/library/es7.math.radians.ls new file mode 100644 index 000000000000..7896b5d79db2 --- /dev/null +++ b/tests/library/es7.math.radians.ls @@ -0,0 +1,11 @@ +{module, test} = QUnit +module \ES7 + +test 'Math.radians' (assert)!-> + {radians} = core.Math + assert.isFunction radians + assert.arity radians, 1 + assert.same radians(0), 0 + assert.same radians(90), Math.PI / 2 + assert.same radians(180), Math.PI + assert.same radians(270), 3 * Math.PI / 2 diff --git a/tests/library/es7.math.scale.ls b/tests/library/es7.math.scale.ls new file mode 100644 index 000000000000..db32c7ffca75 --- /dev/null +++ b/tests/library/es7.math.scale.ls @@ -0,0 +1,11 @@ +{module, test} = QUnit +module \ES7 + +test 'Math.scale' (assert)!-> + {scale} = core.Math + assert.isFunction scale + assert.arity scale, 5 + assert.same scale(3 1 2 1 2), 3 + assert.same scale(0 3 5 8 10), 5 + assert.same scale(1 1 1 1 1), NaN + assert.same scale(-1 -1 -1 -1 -1 ), NaN \ No newline at end of file diff --git a/tests/tests.js b/tests/tests.js index 91e134fb0e50..4948d4db3d04 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -10958,6 +10958,80 @@ }); }).call(this); +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.clamp', function(assert){ + var clamp; + clamp = Math.clamp; + assert.isFunction(clamp); + assert.name(clamp, 'clamp'); + assert.arity(clamp, 3); + assert.looksNative(clamp); + assert.nonEnumerable(Math, 'clamp'); + assert.same(clamp(2, 4, 6), 4); + assert.same(clamp(4, 2, 6), 4); + assert.same(clamp(6, 2, 4), 4); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES6'); + test('Math.DEG_PER_RAD', function(assert){ + var DEG_PER_RAD; + DEG_PER_RAD = Math.DEG_PER_RAD; + assert.ok('DEG_PER_RAD' in Math, 'DEG_PER_RAD in Math'); + assert.nonEnumerable(Math, 'DEG_PER_RAD'); + assert.strictEqual(DEG_PER_RAD, Math.PI / 180, 'Is Math.PI / 180'); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.degrees', function(assert){ + var degrees; + degrees = Math.degrees; + assert.isFunction(degrees); + assert.name(degrees, 'degrees'); + assert.arity(degrees, 1); + assert.looksNative(degrees); + assert.nonEnumerable(Math, 'degrees'); + assert.same(degrees(0), 0); + assert.same(degrees(Math.PI / 2), 90); + assert.same(degrees(Math.PI), 180); + assert.same(degrees(3 * Math.PI / 2), 270); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.fscale', function(assert){ + var fscale, fround, PI; + fscale = Math.fscale, fround = Math.fround, PI = Math.PI; + assert.isFunction(fscale); + assert.name(fscale, 'fscale'); + assert.arity(fscale, 5); + assert.looksNative(fscale); + assert.nonEnumerable(Math, 'fscale'); + assert.same(fscale(3, 1, 2, 1, 2), 3); + assert.same(fscale(0, 3, 5, 8, 10), 5); + assert.same(fscale(1, 1, 1, 1, 1), NaN); + assert.same(fscale(-1, -1, -1, -1, -1), NaN); + assert.strictEqual(fscale(3, 1, 2, 1, PI), fround((3 - 1) * (PI - 1) / (2 - 1) + 1)); + }); +}).call(this); + // Generated by LiveScript 1.4.0 (function(){ var module, test; @@ -11020,6 +11094,60 @@ }); }).call(this); +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES6'); + test('Math.RAD_PER_DEG', function(assert){ + var RAD_PER_DEG; + RAD_PER_DEG = Math.RAD_PER_DEG; + assert.ok('RAD_PER_DEG' in Math, 'RAD_PER_DEG in Math'); + assert.nonEnumerable(Math, 'RAD_PER_DEG'); + assert.strictEqual(RAD_PER_DEG, 180 / Math.PI, 'Is 180 / Math.PI'); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.radians', function(assert){ + var radians; + radians = Math.radians; + assert.isFunction(radians); + assert.name(radians, 'radians'); + assert.arity(radians, 1); + assert.looksNative(radians); + assert.nonEnumerable(Math, 'radians'); + assert.same(radians(0), 0); + assert.same(radians(90), Math.PI / 2); + assert.same(radians(180), Math.PI); + assert.same(radians(270), 3 * Math.PI / 2); + }); +}).call(this); + +// Generated by LiveScript 1.4.0 +(function(){ + var module, test; + module = QUnit.module, test = QUnit.test; + module('ES7'); + test('Math.scale', function(assert){ + var scale; + scale = Math.scale; + assert.isFunction(scale); + assert.name(scale, 'scale'); + assert.arity(scale, 5); + assert.looksNative(scale); + assert.nonEnumerable(Math, 'scale'); + assert.same(scale(3, 1, 2, 1, 2), 3); + assert.same(scale(0, 3, 5, 8, 10), 5); + assert.same(scale(1, 1, 1, 1, 1), NaN); + assert.same(scale(-1, -1, -1, -1, -1), NaN); + }); +}).call(this); + // Generated by LiveScript 1.4.0 (function(){ var module, test; diff --git a/tests/tests/es7.math.clamp.ls b/tests/tests/es7.math.clamp.ls new file mode 100644 index 000000000000..3598023a2c93 --- /dev/null +++ b/tests/tests/es7.math.clamp.ls @@ -0,0 +1,13 @@ +{module, test} = QUnit +module \ES7 + +test 'Math.clamp' (assert)!-> + {clamp} = Math + assert.isFunction clamp + assert.name clamp, \clamp + assert.arity clamp, 3 + assert.looksNative clamp + assert.nonEnumerable Math, \clamp + assert.same clamp(2, 4, 6), 4 + assert.same clamp(4, 2, 6), 4 + assert.same clamp(6, 2, 4), 4 diff --git a/tests/tests/es7.math.deg-per-rad.ls b/tests/tests/es7.math.deg-per-rad.ls new file mode 100644 index 000000000000..c13645e755a6 --- /dev/null +++ b/tests/tests/es7.math.deg-per-rad.ls @@ -0,0 +1,7 @@ +{module, test} = QUnit +module \ES6 +test 'Math.DEG_PER_RAD' (assert)!-> + {DEG_PER_RAD} = Math + assert.ok \DEG_PER_RAD of Math, 'DEG_PER_RAD in Math' + assert.nonEnumerable Math, \DEG_PER_RAD + assert.strictEqual DEG_PER_RAD, Math.PI / 180, 'Is Math.PI / 180' \ No newline at end of file diff --git a/tests/tests/es7.math.degrees.ls b/tests/tests/es7.math.degrees.ls new file mode 100644 index 000000000000..fc8d50af6a3f --- /dev/null +++ b/tests/tests/es7.math.degrees.ls @@ -0,0 +1,14 @@ +{module, test} = QUnit +module \ES7 + +test 'Math.degrees' (assert)!-> + {degrees} = Math + assert.isFunction degrees + assert.name degrees, \degrees + assert.arity degrees, 1 + assert.looksNative degrees + assert.nonEnumerable Math, \degrees + assert.same degrees(0), 0 + assert.same degrees(Math.PI / 2), 90 + assert.same degrees(Math.PI), 180 + assert.same degrees(3 * Math.PI / 2), 270 diff --git a/tests/tests/es7.math.fscale.ls b/tests/tests/es7.math.fscale.ls new file mode 100644 index 000000000000..9b2a9c734434 --- /dev/null +++ b/tests/tests/es7.math.fscale.ls @@ -0,0 +1,15 @@ +{module, test} = QUnit +module \ES7 + +test 'Math.fscale' (assert)!-> + {fscale, fround, PI} = Math + assert.isFunction fscale + assert.name fscale, \fscale + assert.arity fscale, 5 + assert.looksNative fscale + assert.nonEnumerable Math, \fscale + assert.same fscale(3 1 2 1 2), 3 + assert.same fscale(0 3 5 8 10), 5 + assert.same fscale(1 1 1 1 1), NaN + assert.same fscale(-1 -1 -1 -1 -1 ), NaN + assert.strictEqual fscale(3 1 2 1 PI), fround((3 - 1) * (PI - 1) / (2 - 1) + 1) \ No newline at end of file diff --git a/tests/tests/es7.math.rad-per-deg.ls b/tests/tests/es7.math.rad-per-deg.ls new file mode 100644 index 000000000000..c066b2667df6 --- /dev/null +++ b/tests/tests/es7.math.rad-per-deg.ls @@ -0,0 +1,7 @@ +{module, test} = QUnit +module \ES6 +test 'Math.RAD_PER_DEG' (assert)!-> + {RAD_PER_DEG} = Math + assert.ok \RAD_PER_DEG of Math, 'RAD_PER_DEG in Math' + assert.nonEnumerable Math, \RAD_PER_DEG + assert.strictEqual RAD_PER_DEG, 180 / Math.PI, 'Is 180 / Math.PI' \ No newline at end of file diff --git a/tests/tests/es7.math.radians.ls b/tests/tests/es7.math.radians.ls new file mode 100644 index 000000000000..d2e3c75cd39e --- /dev/null +++ b/tests/tests/es7.math.radians.ls @@ -0,0 +1,14 @@ +{module, test} = QUnit +module \ES7 + +test 'Math.radians' (assert)!-> + {radians} = Math + assert.isFunction radians + assert.name radians, \radians + assert.arity radians, 1 + assert.looksNative radians + assert.nonEnumerable Math, \radians + assert.same radians(0), 0 + assert.same radians(90), Math.PI / 2 + assert.same radians(180), Math.PI + assert.same radians(270), 3 * Math.PI / 2 diff --git a/tests/tests/es7.math.scale.ls b/tests/tests/es7.math.scale.ls new file mode 100644 index 000000000000..6a191c4b2690 --- /dev/null +++ b/tests/tests/es7.math.scale.ls @@ -0,0 +1,15 @@ +{module, test} = QUnit +module \ES7 + +test 'Math.scale' (assert)!-> + {scale} = Math + assert.isFunction scale + assert.name scale, \scale + assert.arity scale, 5 + assert.looksNative scale + assert.nonEnumerable Math, \scale + assert.same scale(3 1 2 1 2), 3 + assert.same scale(0 3 5 8 10), 5 + assert.same scale(1 1 1 1 1), NaN + assert.same scale(-1 -1 -1 -1 -1 ), NaN + \ No newline at end of file