Make modulo arithmetic conform to lua rules for negative values.
This commit is contained in:
@@ -39,7 +39,8 @@ public class LDouble extends LNumber {
|
|||||||
case Lua.OP_SUB: return new LDouble( lhs - rhs );
|
case Lua.OP_SUB: return new LDouble( lhs - rhs );
|
||||||
case Lua.OP_MUL: return new LDouble( lhs * rhs );
|
case Lua.OP_MUL: return new LDouble( lhs * rhs );
|
||||||
case Lua.OP_DIV: return new LDouble( lhs / rhs );
|
case Lua.OP_DIV: return new LDouble( lhs / rhs );
|
||||||
case Lua.OP_MOD: return new LDouble( lhs % rhs );
|
case Lua.OP_MOD: return new LDouble( lhs - Math.floor(lhs/rhs) * rhs );
|
||||||
|
|
||||||
// case Lua.OP_POW: return new LDouble( Math.pow(lhs, rhs) );
|
// case Lua.OP_POW: return new LDouble( Math.pow(lhs, rhs) );
|
||||||
}
|
}
|
||||||
return luaUnsupportedOperation();
|
return luaUnsupportedOperation();
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class LInteger extends LNumber {
|
|||||||
case Lua.OP_SUB: return new LInteger( m_value - rhs );
|
case Lua.OP_SUB: return new LInteger( m_value - rhs );
|
||||||
case Lua.OP_MUL: return new LInteger( m_value * rhs );
|
case Lua.OP_MUL: return new LInteger( m_value * rhs );
|
||||||
case Lua.OP_DIV: return new LInteger( m_value / rhs );
|
case Lua.OP_DIV: return new LInteger( m_value / rhs );
|
||||||
case Lua.OP_MOD: return new LInteger( m_value % rhs );
|
case Lua.OP_MOD: return new LInteger( m_value - ((int) Math.floor(m_value/(double)rhs)) * rhs );
|
||||||
// case Lua.OP_POW: return new LInteger( (int) Math.pow(m_value, rhs) );
|
// case Lua.OP_POW: return new LInteger( (int) Math.pow(m_value, rhs) );
|
||||||
}
|
}
|
||||||
return luaUnsupportedOperation();
|
return luaUnsupportedOperation();
|
||||||
|
|||||||
Reference in New Issue
Block a user