Skip to content

Commit

Permalink
implement sign function
Browse files Browse the repository at this point in the history
  • Loading branch information
viktordanov committed Jul 30, 2021
1 parent fe03205 commit d13e684
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions abacus_visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,22 @@ func (a *AbacusVisitor) VisitExpFunction(c *parser.ExpFunctionContext) interface
return NewResult(v)
}

func (a *AbacusVisitor) VisitSignFunction(c *parser.SignFunctionContext) interface{} {
valRes := c.Expression().Accept(a).(*Result)
if hasErrors(valRes) {
return valRes
}

val, ok := valRes.Value.(Number)
if !ok {
panic("unable to cast val to Number")
}

v := newNumber(0)
v = newNumber(float64(val.Decimal.Cmp(v.Decimal)))
return NewResult(v)
}

func (a *AbacusVisitor) VisitAbsFunction(c *parser.AbsFunctionContext) interface{} {
valRes := c.Expression().Accept(a).(*Result)
if hasErrors(valRes) {
Expand Down

0 comments on commit d13e684

Please sign in to comment.