-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move
Math.f16round
and `DataView.prototype.{ getFloat16, setFloat16…
… }` to stable ES
- Loading branch information
Showing
29 changed files
with
221 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/modules/es.data-view.get-float16.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/modules/es.data-view.set-float16.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
'use strict'; | ||
var parent = require('../../stable/data-view/get-float16'); | ||
require('../../modules/esnext.data-view.get-float16'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
'use strict'; | ||
var parent = require('../../stable/data-view/set-float16'); | ||
require('../../modules/esnext.data-view.set-float16'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use strict'; | ||
var parent = require('../../stable/math/f16round'); | ||
require('../../modules/esnext.math.f16round'); | ||
var path = require('../../internals/path'); | ||
|
||
module.exports = path.Math.f16round; | ||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
'use strict'; | ||
require('../../modules/es.data-view.get-float16'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
'use strict'; | ||
require('../../modules/es.data-view.set-float16'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
require('../../modules/es.math.f16round'); | ||
var path = require('../../internals/path'); | ||
|
||
module.exports = path.Math.f16round; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
|
||
var pow = Math.pow; | ||
|
||
var EXP_MASK16 = 31; // 2 ** 5 - 1 | ||
var SIGNIFICAND_MASK16 = 1023; // 2 ** 10 - 1 | ||
var MIN_SUBNORMAL16 = pow(2, -24); // 2 ** -10 * 2 ** -14 | ||
var SIGNIFICAND_DENOM16 = 0.0009765625; // 2 ** -10 | ||
|
||
var unpackFloat16 = function (bytes) { | ||
var sign = bytes >>> 15; | ||
var exponent = bytes >>> 10 & EXP_MASK16; | ||
var significand = bytes & SIGNIFICAND_MASK16; | ||
if (exponent === EXP_MASK16) return significand === 0 ? (sign === 0 ? Infinity : -Infinity) : NaN; | ||
if (exponent === 0) return significand * (sign === 0 ? MIN_SUBNORMAL16 : -MIN_SUBNORMAL16); | ||
return pow(2, exponent - 15) * (sign === 0 ? 1 + significand * SIGNIFICAND_DENOM16 : -1 - significand * SIGNIFICAND_DENOM16); | ||
}; | ||
|
||
// eslint-disable-next-line es/no-typed-arrays -- safe | ||
var getUint16 = uncurryThis(DataView.prototype.getUint16); | ||
|
||
// `DataView.prototype.getFloat16` method | ||
// https://github.com/tc39/proposal-float16array | ||
$({ target: 'DataView', proto: true }, { | ||
getFloat16: function getFloat16(byteOffset /* , littleEndian */) { | ||
var uint16 = getUint16(this, byteOffset, arguments.length > 1 ? arguments[1] : false); | ||
return unpackFloat16(uint16); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var aDataView = require('../internals/a-data-view'); | ||
var toIndex = require('../internals/to-index'); | ||
// TODO: Replace with module dependency in `core-js@4` | ||
var log2 = require('../internals/math-log2'); | ||
var roundTiesToEven = require('../internals/math-round-ties-to-even'); | ||
|
||
var pow = Math.pow; | ||
|
||
var MIN_INFINITY16 = 65520; // (2 - 2 ** -11) * 2 ** 15 | ||
var MIN_NORMAL16 = 0.000061005353927612305; // (1 - 2 ** -11) * 2 ** -14 | ||
var REC_MIN_SUBNORMAL16 = 16777216; // 2 ** 10 * 2 ** 14 | ||
var REC_SIGNIFICAND_DENOM16 = 1024; // 2 ** 10; | ||
|
||
var packFloat16 = function (value) { | ||
// eslint-disable-next-line no-self-compare -- NaN check | ||
if (value !== value) return 0x7E00; // NaN | ||
if (value === 0) return (1 / value === -Infinity) << 15; // +0 or -0 | ||
|
||
var neg = value < 0; | ||
if (neg) value = -value; | ||
if (value >= MIN_INFINITY16) return neg << 15 | 0x7C00; // Infinity | ||
if (value < MIN_NORMAL16) return neg << 15 | roundTiesToEven(value * REC_MIN_SUBNORMAL16); // subnormal | ||
|
||
// normal | ||
var exponent = log2(value) | 0; | ||
if (exponent === -15) { | ||
// we round from a value between 2 ** -15 * (1 + 1022/1024) (the largest subnormal) and 2 ** -14 * (1 + 0/1024) (the smallest normal) | ||
// to the latter (former impossible because of the subnormal check above) | ||
return neg << 15 | REC_SIGNIFICAND_DENOM16; | ||
} | ||
var significand = roundTiesToEven((value * pow(2, -exponent) - 1) * REC_SIGNIFICAND_DENOM16); | ||
if (significand === REC_SIGNIFICAND_DENOM16) { | ||
// we round from a value between 2 ** n * (1 + 1023/1024) and 2 ** (n + 1) * (1 + 0/1024) to the latter | ||
return neg << 15 | exponent + 16 << 10; | ||
} | ||
return neg << 15 | exponent + 15 << 10 | significand; | ||
}; | ||
|
||
// eslint-disable-next-line es/no-typed-arrays -- safe | ||
var setUint16 = uncurryThis(DataView.prototype.setUint16); | ||
|
||
// `DataView.prototype.setFloat16` method | ||
// https://github.com/tc39/proposal-float16array | ||
$({ target: 'DataView', proto: true }, { | ||
setFloat16: function setFloat16(byteOffset, value /* , littleEndian */) { | ||
aDataView(this); | ||
var offset = toIndex(byteOffset); | ||
var bytes = packFloat16(+value); | ||
return setUint16(this, offset, bytes, arguments.length > 2 ? arguments[2] : false); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var floatRound = require('../internals/math-float-round'); | ||
|
||
var FLOAT16_EPSILON = 0.0009765625; | ||
var FLOAT16_MAX_VALUE = 65504; | ||
var FLOAT16_MIN_VALUE = 6.103515625e-05; | ||
|
||
// `Math.f16round` method | ||
// https://github.com/tc39/proposal-float16array | ||
$({ target: 'Math', stat: true }, { | ||
f16round: function f16round(x) { | ||
return floatRound(x, FLOAT16_EPSILON, FLOAT16_MAX_VALUE, FLOAT16_MIN_VALUE); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,3 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
|
||
var pow = Math.pow; | ||
|
||
var EXP_MASK16 = 31; // 2 ** 5 - 1 | ||
var SIGNIFICAND_MASK16 = 1023; // 2 ** 10 - 1 | ||
var MIN_SUBNORMAL16 = pow(2, -24); // 2 ** -10 * 2 ** -14 | ||
var SIGNIFICAND_DENOM16 = 0.0009765625; // 2 ** -10 | ||
|
||
var unpackFloat16 = function (bytes) { | ||
var sign = bytes >>> 15; | ||
var exponent = bytes >>> 10 & EXP_MASK16; | ||
var significand = bytes & SIGNIFICAND_MASK16; | ||
if (exponent === EXP_MASK16) return significand === 0 ? (sign === 0 ? Infinity : -Infinity) : NaN; | ||
if (exponent === 0) return significand * (sign === 0 ? MIN_SUBNORMAL16 : -MIN_SUBNORMAL16); | ||
return pow(2, exponent - 15) * (sign === 0 ? 1 + significand * SIGNIFICAND_DENOM16 : -1 - significand * SIGNIFICAND_DENOM16); | ||
}; | ||
|
||
// eslint-disable-next-line es/no-typed-arrays -- safe | ||
var getUint16 = uncurryThis(DataView.prototype.getUint16); | ||
|
||
// `DataView.prototype.getFloat16` method | ||
// https://github.com/tc39/proposal-float16array | ||
$({ target: 'DataView', proto: true }, { | ||
getFloat16: function getFloat16(byteOffset /* , littleEndian */) { | ||
var uint16 = getUint16(this, byteOffset, arguments.length > 1 ? arguments[1] : false); | ||
return unpackFloat16(uint16); | ||
} | ||
}); | ||
// TODO: Remove from `core-js@4` | ||
require('../modules/es.data-view.get-float16'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,3 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var aDataView = require('../internals/a-data-view'); | ||
var toIndex = require('../internals/to-index'); | ||
// TODO: Replace with module dependency in `core-js@4` | ||
var log2 = require('../internals/math-log2'); | ||
var roundTiesToEven = require('../internals/math-round-ties-to-even'); | ||
|
||
var pow = Math.pow; | ||
|
||
var MIN_INFINITY16 = 65520; // (2 - 2 ** -11) * 2 ** 15 | ||
var MIN_NORMAL16 = 0.000061005353927612305; // (1 - 2 ** -11) * 2 ** -14 | ||
var REC_MIN_SUBNORMAL16 = 16777216; // 2 ** 10 * 2 ** 14 | ||
var REC_SIGNIFICAND_DENOM16 = 1024; // 2 ** 10; | ||
|
||
var packFloat16 = function (value) { | ||
// eslint-disable-next-line no-self-compare -- NaN check | ||
if (value !== value) return 0x7E00; // NaN | ||
if (value === 0) return (1 / value === -Infinity) << 15; // +0 or -0 | ||
|
||
var neg = value < 0; | ||
if (neg) value = -value; | ||
if (value >= MIN_INFINITY16) return neg << 15 | 0x7C00; // Infinity | ||
if (value < MIN_NORMAL16) return neg << 15 | roundTiesToEven(value * REC_MIN_SUBNORMAL16); // subnormal | ||
|
||
// normal | ||
var exponent = log2(value) | 0; | ||
if (exponent === -15) { | ||
// we round from a value between 2 ** -15 * (1 + 1022/1024) (the largest subnormal) and 2 ** -14 * (1 + 0/1024) (the smallest normal) | ||
// to the latter (former impossible because of the subnormal check above) | ||
return neg << 15 | REC_SIGNIFICAND_DENOM16; | ||
} | ||
var significand = roundTiesToEven((value * pow(2, -exponent) - 1) * REC_SIGNIFICAND_DENOM16); | ||
if (significand === REC_SIGNIFICAND_DENOM16) { | ||
// we round from a value between 2 ** n * (1 + 1023/1024) and 2 ** (n + 1) * (1 + 0/1024) to the latter | ||
return neg << 15 | exponent + 16 << 10; | ||
} | ||
return neg << 15 | exponent + 15 << 10 | significand; | ||
}; | ||
|
||
// eslint-disable-next-line es/no-typed-arrays -- safe | ||
var setUint16 = uncurryThis(DataView.prototype.setUint16); | ||
|
||
// `DataView.prototype.setFloat16` method | ||
// https://github.com/tc39/proposal-float16array | ||
$({ target: 'DataView', proto: true }, { | ||
setFloat16: function setFloat16(byteOffset, value /* , littleEndian */) { | ||
aDataView(this); | ||
var offset = toIndex(byteOffset); | ||
var bytes = packFloat16(+value); | ||
return setUint16(this, offset, bytes, arguments.length > 2 ? arguments[2] : false); | ||
} | ||
}); | ||
// TODO: Remove from `core-js@4` | ||
require('../modules/es.data-view.set-float16'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var floatRound = require('../internals/math-float-round'); | ||
|
||
var FLOAT16_EPSILON = 0.0009765625; | ||
var FLOAT16_MAX_VALUE = 65504; | ||
var FLOAT16_MIN_VALUE = 6.103515625e-05; | ||
|
||
// `Math.f16round` method | ||
// https://github.com/tc39/proposal-float16array | ||
$({ target: 'Math', stat: true }, { | ||
f16round: function f16round(x) { | ||
return floatRound(x, FLOAT16_EPSILON, FLOAT16_MAX_VALUE, FLOAT16_MIN_VALUE); | ||
} | ||
}); | ||
// TODO: Remove from `core-js@4` | ||
require('../modules/es.math.f16round'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
var parent = require('../../es/data-view/get-float16'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
var parent = require('../../es/data-view/set-float16'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
var parent = require('../../es/math/f16round'); | ||
|
||
module.exports = parent; |
Oops, something went wrong.