Skip to content

Commit

Permalink
gcsl numbers (genshinsim#2239)
Browse files Browse the repository at this point in the history
* fix arithmetic operations for float and int. fix parsing of "1-1" expression

* fix lint

* revert "1-1" fixing
  • Loading branch information
imring authored Nov 2, 2024
1 parent cd0557a commit 259b0f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions pkg/gcs/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,27 @@ func neq(l, r *number) *number {
}

func add(l, r *number) *number {
return &number{
ival: l.ival + r.ival,
fval: l.fval + r.fval,
n := &number{
isFloat: l.isFloat || r.isFloat,
}
if n.isFloat {
n.fval = ntof(l) + ntof(r)
} else {
n.ival = l.ival + r.ival
}
return n
}

func mul(l, r *number) *number {
return &number{
ival: l.ival * r.ival,
fval: l.fval * r.fval,
n := &number{
isFloat: l.isFloat || r.isFloat,
}
if n.isFloat {
n.fval = ntof(l) * ntof(r)
} else {
n.ival = l.ival * r.ival
}
return n
}

func div(l, r *number) *number {
Expand All @@ -99,9 +107,13 @@ func div(l, r *number) *number {
}

func sub(l, r *number) *number {
return &number{
ival: l.ival - r.ival,
fval: l.fval - r.fval,
n := &number{
isFloat: l.isFloat || r.isFloat,
}
if n.isFloat {
n.fval = ntof(l) - ntof(r)
} else {
n.ival = l.ival - r.ival
}
return n
}
2 changes: 1 addition & 1 deletion pkg/gcs/sysfunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ func (e *Eval) executeAction(c *ast.CallExpr, env *Env) (Obj, error) {
if v.Typ() != typNum {
return nil, fmt.Errorf("map params should evaluate to a number, got %v", v.Inspect())
}
params[k] = int(v.(*number).ival)
params[k] = int(ntof(v.(*number)))
}

charKey := keys.Char(char.ival)
Expand Down

0 comments on commit 259b0f1

Please sign in to comment.