Skip to content

Commit

Permalink
fix arguments conversion in Math.scale
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Oct 16, 2021
1 parent 06c2775 commit 9f8af38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
## Changelog
##### Unreleased
- Fixed normalization of `message` `AggregateError` argument
- Fixed order of arguments conversion in `Math.scale`, [a spec draft bug](https://github.com/rwaldron/proposal-math-extensions/issues/24)
- Updated Electron 16.0 compat data mapping

##### 3.18.3 - 2021.10.13
Expand Down
21 changes: 9 additions & 12 deletions packages/core-js/internals/math-scale.js
@@ -1,16 +1,13 @@
// `Math.scale` method implementation
// https://rwaldron.github.io/proposal-math-extensions/
module.exports = Math.scale || function scale(x, inLow, inHigh, outLow, outHigh) {
if (
arguments.length == 0
/* eslint-disable no-self-compare -- NaN check */
|| x != x
|| inLow != inLow
|| inHigh != inHigh
|| outLow != outLow
|| outHigh != outHigh
/* eslint-enable no-self-compare -- NaN check */
) return NaN;
if (x === Infinity || x === -Infinity) return x;
return (x - inLow) * (outHigh - outLow) / (inHigh - inLow) + outLow;
var nx = +x;
var nInLow = +inLow;
var nInHigh = +inHigh;
var nOutLow = +outLow;
var nOutHigh = +outHigh;
// eslint-disable-next-line no-self-compare -- NaN check
if (nx != nx || nInLow != nInLow || nInHigh != nInHigh || nOutLow != nOutLow || nOutHigh != nOutHigh) return NaN;
if (nx === Infinity || nx === -Infinity) return nx;
return (nx - nInLow) * (nOutHigh - nOutLow) / (nInHigh - nInLow) + nOutLow;
};

0 comments on commit 9f8af38

Please sign in to comment.