fix relative comparisons of float
All checks were successful
/ test (push) Successful in 49s

This commit is contained in:
Neemek 2026-07-11 10:18:32 +02:00
parent bc58da6d49
commit 2c354c4a96
Signed by: neemek
GPG key ID: 84FFE4D7D40AB25E

View file

@ -648,6 +648,11 @@ func (c *Compiler) compileBinary(binary *BinaryNode) error {
return err return err
} }
inType, err := c.deduceSignature(binary.Left) // type(left) == type(right) because res is valid
if err != nil {
return err
}
switch binary.BinaryOperation { switch binary.BinaryOperation {
case BinaryAddition: case BinaryAddition:
if res.Type() == TypeString { if res.Type() == TypeString {
@ -685,25 +690,25 @@ func (c *Compiler) compileBinary(binary *BinaryNode) error {
c.add(InstructionNotEqual) c.add(InstructionNotEqual)
case BinaryLess: case BinaryLess:
if res.Type() == TypeFloat { if inType.Type() == TypeFloat {
c.add(InstructionLessFloat) c.add(InstructionLessFloat)
} else { } else {
c.add(InstructionLessInt) c.add(InstructionLessInt)
} }
case BinaryGreater: case BinaryGreater:
if res.Type() == TypeFloat { if inType.Type() == TypeFloat {
c.add(InstructionGreaterFloat) c.add(InstructionGreaterFloat)
} else { } else {
c.add(InstructionGreaterInt) c.add(InstructionGreaterInt)
} }
case BinaryLessEqual: case BinaryLessEqual:
if res.Type() == TypeFloat { if inType.Type() == TypeFloat {
c.add(InstructionLessOrEqualFloat) c.add(InstructionLessOrEqualFloat)
} else { } else {
c.add(InstructionLessOrEqualInt) c.add(InstructionLessOrEqualInt)
} }
case BinaryGreaterEqual: case BinaryGreaterEqual:
if res.Type() == TypeFloat { if inType.Type() == TypeFloat {
c.add(InstructionGreaterOrEqualFloat) c.add(InstructionGreaterOrEqualFloat)
} else { } else {
c.add(InstructionGreaterOrEqualInt) c.add(InstructionGreaterOrEqualInt)