main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[79a0317] | 1 | 'use strict';
|
---|
| 2 | var $ = require('../internals/export');
|
---|
| 3 | var uncurryThis = require('../internals/function-uncurry-this');
|
---|
| 4 |
|
---|
| 5 | var pow = Math.pow;
|
---|
| 6 |
|
---|
| 7 | var EXP_MASK16 = 31; // 2 ** 5 - 1
|
---|
| 8 | var SIGNIFICAND_MASK16 = 1023; // 2 ** 10 - 1
|
---|
| 9 | var MIN_SUBNORMAL16 = pow(2, -24); // 2 ** -10 * 2 ** -14
|
---|
| 10 | var SIGNIFICAND_DENOM16 = 0.0009765625; // 2 ** -10
|
---|
| 11 |
|
---|
| 12 | var unpackFloat16 = function (bytes) {
|
---|
| 13 | var sign = bytes >>> 15;
|
---|
| 14 | var exponent = bytes >>> 10 & EXP_MASK16;
|
---|
| 15 | var significand = bytes & SIGNIFICAND_MASK16;
|
---|
| 16 | if (exponent === EXP_MASK16) return significand === 0 ? (sign === 0 ? Infinity : -Infinity) : NaN;
|
---|
| 17 | if (exponent === 0) return significand * (sign === 0 ? MIN_SUBNORMAL16 : -MIN_SUBNORMAL16);
|
---|
| 18 | return pow(2, exponent - 15) * (sign === 0 ? 1 + significand * SIGNIFICAND_DENOM16 : -1 - significand * SIGNIFICAND_DENOM16);
|
---|
| 19 | };
|
---|
| 20 |
|
---|
| 21 | // eslint-disable-next-line es/no-typed-arrays -- safe
|
---|
| 22 | var getUint16 = uncurryThis(DataView.prototype.getUint16);
|
---|
| 23 |
|
---|
| 24 | // `DataView.prototype.getFloat16` method
|
---|
| 25 | // https://github.com/tc39/proposal-float16array
|
---|
| 26 | $({ target: 'DataView', proto: true }, {
|
---|
| 27 | getFloat16: function getFloat16(byteOffset /* , littleEndian */) {
|
---|
| 28 | var uint16 = getUint16(this, byteOffset, arguments.length > 1 ? arguments[1] : false);
|
---|
| 29 | return unpackFloat16(uint16);
|
---|
| 30 | }
|
---|
| 31 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.