optimizations
Some checks failed
Build / build (push) Successful in 10m47s
Publish Image / publish (push) Failing after 33s
Test / build (push) Failing after 6m42s

This commit is contained in:
Chuck Smith
2024-04-02 14:54:08 -04:00
parent 88e3330856
commit f08b458325
9 changed files with 313 additions and 355 deletions

View File

@@ -35,6 +35,8 @@ func (i Integer) Add(other Object) (Object, error) {
switch obj := other.(type) {
case Integer:
return Integer{i.Value + obj.Value}, nil
case Float:
return Float{float64(i.Value) + obj.Value}, nil
default:
return nil, NewBinaryOpError(i, other, "+")
}
@@ -44,6 +46,8 @@ func (i Integer) Sub(other Object) (Object, error) {
switch obj := other.(type) {
case Integer:
return Integer{i.Value - obj.Value}, nil
case Float:
return Float{float64(i.Value) - obj.Value}, nil
default:
return nil, NewBinaryOpError(i, other, "-")
}
@@ -53,6 +57,8 @@ func (i Integer) Mul(other Object) (Object, error) {
switch obj := other.(type) {
case Integer:
return Integer{i.Value * obj.Value}, nil
case Float:
return Float{float64(i.Value) * obj.Value}, nil
case String:
return obj.Mul(i)
case *Array:
@@ -69,6 +75,11 @@ func (i Integer) Div(other Object) (Object, error) {
return nil, NewDivisionByZeroError(i)
}
return Integer{i.Value / obj.Value}, nil
case Float:
if obj.Value == 0.0 {
return nil, NewDivisionByZeroError(i)
}
return Float{float64(i.Value) / obj.Value}, nil
default:
return nil, NewBinaryOpError(i, other, "/")
}
@@ -78,6 +89,8 @@ func (i Integer) Mod(other Object) (Object, error) {
switch obj := other.(type) {
case Integer:
return Integer{i.Value % obj.Value}, nil
case Float:
return Float{float64(i.Value % int64(obj.Value))}, nil
default:
return nil, NewBinaryOpError(i, other, "%")
}