extensibleweb / webidl.js

An implementation of WebIDL in ECMAScript
55 stars 14 forks source link

implement short type #6

Closed marcoscaceres closed 11 years ago

marcoscaceres commented 11 years ago

http://www.w3.org/TR/WebIDL/#idl-short

marcoscaceres commented 11 years ago

The spec says:

"Round x to the nearest integer, choosing the even integer if it lies halfway between two."

Do you guys think that mean that Math.round() can't be used here?

I'm reading the above as:

//check if it's in the middle? yes, floor it, otherwise, round it up. 
(Math.abs(x - Math.round(x)) === .5 ) ? Math.floor(x) : Math.round(x);
marcoscaceres commented 11 years ago

oh, no, wait...

marcoscaceres commented 11 years ago
is it half way? 
No: round it. 
Yes: is an even number? 
   yes: round it
   no: floor it.  
Math.abs(x - Math.round(x)) === 0.5 ? (((Math.round(x) % 2 ) === 0) ? Math.round(x) : Math.floor(x)) : Math.round(x);
marcoscaceres commented 11 years ago

Implemented but untested. Waiting in pull request queue.

marcoscaceres commented 11 years ago

Blocked by: https://github.com/extensibleweb/webidl.js/issues/44

marcoscaceres commented 11 years ago

No longer blocked. Tests have been integrated. Just needs a review (only 34 lines): https://github.com/extensibleweb/webidl.js/blob/master/lib/types/Boolean.js