Uint8ClampedArray rounding behaviour?

# Qantas 94 Heavy (11 years ago)

Currently, the ES6 spec uses ToUint8Clamp to convert the set value into a number in a Uint8ClampedArray. From what I read of the spec, ToUint8Clamp rounds ties away from zero (rev 22, 7.1.11):

  1. Let f be floor(number).
  2. If f+0.5 ≤ number, then return f+1.

However, in the WebIDL spec (4.2.5, step 3), it's specified to round to the nearest even integer:

  1. Round x to the nearest integer, choosing the even integer if it lies

halfway between two.

  1. Set x to min(max(x, 0), 2^8 − 1).
  2. Return the IDL octet value that represents the same numeric value as x.

Currently, both Firefox and Chrome round ties to even, not away from zero. Am I reading this completely wrong, or is there a discrepancy in the behaviour between the ES6 version and what's currently implemented in browsers?

# Boris Zbarsky (11 years ago)

On 4/5/14 9:44 PM, Qantas 94 Heavy wrote:

Am I reading this completely wrong, or is there a discrepancy in the behaviour between the ES6 version and what's currently implemented in browsers?

You're reading correctly. The ES6 version is wrong and should be fixed.

# Allen Wirfs-Brock (11 years ago)

Bug report? What's the the correct behavior?

# Allen Wirfs-Brock (11 years ago)

Err oops, sorry I missed the top post