archives

« Bugzilla Issues Index

#2870 — 7.1.11 ToUint8Clamp: rounding condition is backwards


http://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint8clamp

The last few steps of ToUint8Clamp read like this:
> 6. Let f be floor(number).
> 7. If f+0.5 > number, then return f+1.
> 8. Return f.

The logic is reversed; we want to return f+1 if number is above floor(number)+0.5, right? As it stands:

function clamp(number) {
let f = Math.floor(number);
if (f+0.5 > number) return f+1;
return f;
}
clamp(0.4) // ==> 1
clamp(0.6) // ==> 0


Actually, it's worse that backwards. It needs to do "round half to even" tie-breaking.

fixed in rev25 editor's draft


fixed in rev25 editor's draft