1. Home
  2. Computing & Technology
  3. JavaScript
photo of Stephen Chapman
Stephen's JavaScript Blog

By Stephen Chapman, About.com Guide to JavaScript since 2004

The JavaScript Modulo Bug

Tuesday July 7, 2009
JavaScript doesn't get everything right.

One of the things that JavaScript gets wrong is modulo arithmatic where for any positive modulo number the possible values should be between zero and one less than the number (and between zero and one greater than the number for negative modulos). Unfortunately JavaScript returns negative numbers outside the valid range where we take a positive modulo of a negative number (and positive numbers outside the range where we take a negative modulo of a positive number). Here's how to fix it.

The JavaScript Modulo Bug
Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.