main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
461 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var floor = require('./floor');
|
---|
| 4 |
|
---|
| 5 | var $TypeError = require('es-errors/type');
|
---|
| 6 |
|
---|
| 7 | // https://262.ecma-international.org/14.0/#eqn-truncate
|
---|
| 8 |
|
---|
| 9 | module.exports = function truncate(x) {
|
---|
| 10 | if (typeof x !== 'number' && typeof x !== 'bigint') {
|
---|
| 11 | throw new $TypeError('argument must be a Number or a BigInt');
|
---|
| 12 | }
|
---|
| 13 | var result = x < 0 ? -floor(-x) : floor(x);
|
---|
| 14 | return result === 0 ? 0 : result; // in the spec, these are math values, so we filter out -0 here
|
---|
| 15 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.