TranscryptOrg / Transcrypt

Python 3.9 to JavaScript compiler - Lean, fast, open!
https://www.transcrypt.org
Apache License 2.0
2.86k stars 215 forks source link

% (modulus) operator returns a plus value when a minus operand is given #872

Closed chopin closed 5 months ago

chopin commented 5 months ago

I found that % operator returns a plus value when an operand is minus.

alpha= -2.18
angle= alpha%math.pi
print('angle:', angle)

angle:0.95

Modulus of a minus operand should return a minus value as following:

-2.18 % 3.14... = -2.18

I checked the javascript code. % operator was translated to mod() function.

var angle = __mod__ (alpha, math.pi);
chopin commented 5 months ago

I found that %(modulus) of Python returns a plus value given a minus operand while Javascript returns minus value.

So, it is not a bug. The current implementation of Transcrypt is correct.