ccxvii / mujs

An embeddable Javascript interpreter in C.
http://mujs.com/
ISC License
812 stars 98 forks source link

Negative numbers converted to positive integers #124

Closed gardhr closed 4 years ago

gardhr commented 4 years ago

Example:

var val = -1 print("val:", val)

Output:

val: 4294967295

The fact that it returns 2^32 - 1 makes me wonder because I've redefined jsInstruction to long. Maybe that's the problem?

isRyven commented 4 years ago

Yeah wrong instruction type usually leads to the problem, i had same issue when i defined it as unsigned int, but setting it to just int did the trick.

gardhr commented 4 years ago

Looks like it just needs to be a signed number. Changed it from "unsigned long" to "long" and everything works just fine now.