phetsims / dot

A math library with a focus on mutable and immutable linear algebra for 2D and 3D applications.
MIT License
13 stars 6 forks source link

address concerns about possible floating point error in isInteger #20

Closed pixelzoom closed 10 years ago

pixelzoom commented 10 years ago

@samreid brought up concerns about isInteger in phetsims/graphing-lines#11 and https://github.com/phetsims/phetcommon/issues/19. It's a general issue with dot, so creating this issue.

The original implementation was:

function isInteger(n) { return Math.floor( number ) === number; }

After discussion, it was changed to this implementation, as identified in Stackoverflow:

function isInteger(n) { return n % 1 === 0; }

samreid commented 10 years ago

I think dot.Util.isInteger is fine. The problem in phetsims/phetcommon#19 is about floating point error that happens before dot.Util.isInteger is called. Reassigning to @pixelzoom for discussion. Close if there are no further issues here.