Skip to content

Commit

Permalink
[New] ES5+: add abs, floor; use modulo consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed May 24, 2020
1 parent 4a02931 commit d253fe0
Show file tree
Hide file tree
Showing 117 changed files with 464 additions and 461 deletions.
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
2015/ToUint32.js spackled linguist-generated=true
2015/WeekDay.js spackled linguist-generated=true
2015/YearFromTime.js spackled linguist-generated=true
2015/abs.js spackled linguist-generated=true
2015/floor.js spackled linguist-generated=true
2015/modulo.js spackled linguist-generated=true
2015/msFromTime.js spackled linguist-generated=true
2016/AbstractEqualityComparison.js spackled linguist-generated=true
Expand Down Expand Up @@ -131,6 +133,8 @@
2016/ValidateAndApplyPropertyDescriptor.js spackled linguist-generated=true
2016/WeekDay.js spackled linguist-generated=true
2016/YearFromTime.js spackled linguist-generated=true
2016/abs.js spackled linguist-generated=true
2016/floor.js spackled linguist-generated=true
2016/modulo.js spackled linguist-generated=true
2016/msFromTime.js spackled linguist-generated=true
2016/thisBooleanValue.js spackled linguist-generated=true
Expand Down Expand Up @@ -243,6 +247,8 @@
2017/ValidateAndApplyPropertyDescriptor.js spackled linguist-generated=true
2017/WeekDay.js spackled linguist-generated=true
2017/YearFromTime.js spackled linguist-generated=true
2017/abs.js spackled linguist-generated=true
2017/floor.js spackled linguist-generated=true
2017/modulo.js spackled linguist-generated=true
2017/msFromTime.js spackled linguist-generated=true
2017/thisBooleanValue.js spackled linguist-generated=true
Expand Down Expand Up @@ -355,6 +361,8 @@
2018/ValidateAndApplyPropertyDescriptor.js spackled linguist-generated=true
2018/WeekDay.js spackled linguist-generated=true
2018/YearFromTime.js spackled linguist-generated=true
2018/abs.js spackled linguist-generated=true
2018/floor.js spackled linguist-generated=true
2018/modulo.js spackled linguist-generated=true
2018/msFromTime.js spackled linguist-generated=true
2018/thisBooleanValue.js spackled linguist-generated=true
Expand Down Expand Up @@ -477,6 +485,8 @@
2019/ValidateAndApplyPropertyDescriptor.js spackled linguist-generated=true
2019/WeekDay.js spackled linguist-generated=true
2019/YearFromTime.js spackled linguist-generated=true
2019/abs.js spackled linguist-generated=true
2019/floor.js spackled linguist-generated=true
2019/modulo.js spackled linguist-generated=true
2019/msFromTime.js spackled linguist-generated=true
2019/thisBooleanValue.js spackled linguist-generated=true
Expand Down
6 changes: 2 additions & 4 deletions 2015/Day.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions 2015/DayFromYear.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions 2015/DaysInYear.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions 2015/HourFromTime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions 2015/IsInteger.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict';

var GetIntrinsic = require('../GetIntrinsic');

var $Math = GetIntrinsic('%Math%');

var $floor = $Math.floor;
var $abs = $Math.abs;
var abs = require('./abs');
var floor = require('./floor');

var $isNaN = require('../helpers/isNaN');
var $isFinite = require('../helpers/isFinite');
Expand All @@ -16,6 +12,6 @@ module.exports = function IsInteger(argument) {
if (typeof argument !== 'number' || $isNaN(argument) || !$isFinite(argument)) {
return false;
}
var abs = $abs(argument);
return $floor(abs) === abs;
var absValue = abs(argument);
return floor(absValue) === absValue;
};
8 changes: 4 additions & 4 deletions 2015/MakeDay.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions 2015/MinFromTime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions 2015/SecFromTime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions 2015/TimeClip.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions 2015/TimeWithinDay.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions 2015/ToUint16.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions 2015/ToUint8.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
'use strict';

var GetIntrinsic = require('../GetIntrinsic');

var $Math = GetIntrinsic('%Math%');

var ToNumber = require('./ToNumber');

var $isNaN = require('../helpers/isNaN');
var $isFinite = require('../helpers/isFinite');
var $sign = require('../helpers/sign');
var $mod = require('../helpers/mod');

var $floor = $Math.floor;
var $abs = $Math.abs;
var abs = require('./abs');
var floor = require('./floor');
var modulo = require('./modulo');

// https://ecma-international.org/ecma-262/6.0/#sec-touint8

module.exports = function ToUint8(argument) {
var number = ToNumber(argument);
if ($isNaN(number) || number === 0 || !$isFinite(number)) { return 0; }
var posInt = $sign(number) * $floor($abs(number));
return $mod(posInt, 0x100);
var posInt = $sign(number) * floor(abs(number));
return modulo(posInt, 0x100);
};
9 changes: 2 additions & 7 deletions 2015/ToUint8Clamp.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
'use strict';

var GetIntrinsic = require('../GetIntrinsic');

var $Math = GetIntrinsic('%Math%');

var ToNumber = require('./ToNumber');
var floor = require('./floor');

var $isNaN = require('../helpers/isNaN');

var $floor = $Math.floor;

// https://www.ecma-international.org/ecma-262/6.0/#sec-touint8clamp

module.exports = function ToUint8Clamp(argument) {
var number = ToNumber(argument);
if ($isNaN(number) || number <= 0) { return 0; }
if (number >= 0xFF) { return 0xFF; }
var f = $floor(argument);
var f = floor(argument);
if (f + 0.5 < number) { return f + 1; }
if (number < f + 0.5) { return f; }
if (f % 2 !== 0) { return f + 1; }
Expand Down
5 changes: 2 additions & 3 deletions 2015/WeekDay.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions 2015/abs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions 2015/floor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions 2015/msFromTime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions 2016/Day.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d253fe0

Please sign in to comment.