main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
603 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var clamp = require('./clamp');
|
---|
4 |
|
---|
5 | var ToNumber = require('./ToNumber');
|
---|
6 | var floor = require('./floor');
|
---|
7 |
|
---|
8 | var $isNaN = require('../helpers/isNaN');
|
---|
9 |
|
---|
10 | // https://262.ecma-international.org/15.0/#sec-touint8clamp
|
---|
11 |
|
---|
12 | module.exports = function ToUint8Clamp(argument) {
|
---|
13 | var number = ToNumber(argument); // step 1
|
---|
14 |
|
---|
15 | if ($isNaN(number)) { return 0; } // step 2
|
---|
16 |
|
---|
17 | var clamped = clamp(number, 0, 255); // step 4
|
---|
18 |
|
---|
19 | var f = floor(clamped); // step 5
|
---|
20 |
|
---|
21 | if (clamped < (f + 0.5)) { return f; } // step 6
|
---|
22 |
|
---|
23 | if (clamped > (f + 0.5)) { return f + 1; } // step 7
|
---|
24 |
|
---|
25 | return f % 2 === 0 ? f : f + 1; // step 8
|
---|
26 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.