« Bugzilla Issues Index
#2870 — 7.1.11 ToUint8Clamp: rounding condition is backwards
- bug_id:
2870
- creation_ts:
2014-05-15 09:16:00 -0700
- short_desc:
7.1.11 ToUint8Clamp: rounding condition is backwards
- delta_ts:
2014-06-16 16:28:30 -0700
- product:
Draft for 6th Edition
- component:
technical issue
- version:
Rev 23: April 5, 2014 Draft
- rep_platform:
All
- op_sys:
All
- bug_status:
RESOLVED
- resolution:
FIXED
- see_also:
https://bugs.ecmascript.org/show_bug.cgi?id=2604
- priority:
Normal
- bug_severity:
enhancement
- everconfirmed:
true
- reporter:
Jason Orendorff
- assigned_to:
Allen Wirfs-Brock
- commentid:
8494
- comment_count:
0
- who:
Jason Orendorff
- bug_when:
2014-05-15 09:16:51 -0700
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
- commentid:
8506
- comment_count:
1
- who:
Allen Wirfs-Brock
- bug_when:
2014-05-15 12:35:06 -0700
Actually, it's worse that backwards. It needs to do "round half to even" tie-breaking.
fixed in rev25 editor's draft
- commentid:
9028
- comment_count:
2
- who:
Allen Wirfs-Brock
- bug_when:
2014-06-16 16:28:30 -0700
fixed in rev25 editor's draft