Skip to content

Commit

Permalink
Make modulo operator convert arguments to numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Demian Ferreiro committed Jan 24, 2014
1 parent 2b4421f commit 1288786
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,7 @@ UTILITIES =
"

modulo: -> """
function(a, b) { return (a % b + b) % b; }
function(a, b) { return (a % b + +b) % b; }
"""

# Shortcuts to speed up the lookup time for native functions.
Expand Down
5 changes: 5 additions & 0 deletions test/operators.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,8 @@ test "modulo operator compound assignment", ->
a = -2
a %%= 5
eq 3, a

test "modulo operator converts arguments to numbers", ->
eq 1, 1 %% '42'
eq 1, '1' %% 42
eq 1, '1' %% '42'

0 comments on commit 1288786

Please sign in to comment.