opal/opal — pull request #362 by jgaskins (2013-09-12 03:16:38+00:00)
Title: Allow Numeric#to s to use radices

Currently, `Numeric#to_s` just delegates to JS's `toString()` function, which stringifies a number without doing anything with the radix. This PR allows it to work just as it does in Ruby. The algorithm was borrowed from the same method in [Rubinius](https://github.com/rubinius/rubinius/blob/b2952297495c74d651f9d7d53e4d7d71fb41d4c7/vm/builtin/fixnum.cpp#L433-L467), which was in turn borrowed from MRI. I just Rubified it and swapped out single-letter variable names with more descriptive ones.

This functionality required the `Numeric#divmod` method, so I added that, too. While I was in there, I noticed that JS's modulo function doesn't work the same as in Ruby (negative numbers weren't being converted properly), so I updated `Numeric#%` to work like Ruby's.