Posted By

cryothic on 03/14/13


Tagged

numbers big mod Modulo overflow


Versions (?)

Modulo on big numbers


 / Published in: JavaScript
 

Max value for Javascript numbers is: 9007199254740992 This function performs a modulo on numbers bigger than that.

"aNumStr" is the number (as string) you want to devide. "aDiv" is the number you want to devide by.

  1. function modulo( aNumStr, aDiv)
  2. {
  3. var tmp = "";
  4. var i, r;
  5. for ( i=0; i<aNumStr.length ; i++)
  6. {
  7. tmp += aNumStr.charAt( i);
  8. r = tmp % aDiv;
  9. tmp = r.toString( 10);
  10. }
  11. return tmp / 1;
  12. }

Report this snippet  

You need to login to post a comment.