Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Expression Evaluator


Melon
 Share

Recommended Posts

Nearing the end of last year I was trying to make make an expression evaluator in C# & I can say I failed miserably, you can find it [here](http://indiehub.net/topic/314-c-maths-parser/#entry3866).

Last week I decided to retry doing the same thing, this time using [Go](http://golang.org) instead of C#.

Features:

* Nested Parentheses

* Operators:

> + - * / ^ ( )

* Functions:

> Floor Ceil Cbrt Sqrt Sin Cos Tan Asin Acos Atan Abs Ln

* Constants:

> E Pi Phi Sqrt2 SqrtE SqrtPi SqrtPhi

Example:

```
package main

import (
"fmt"
"gocalc"
)

func main() {
exp := gc.NewExpression("9^2+Tan[Pi-X]")
exp.AddVariable("X", 1.069)
answer := exp.Solve()
fmt.Println(answer)
}

```

The source can be found on Github [here](https://github.com/marcmak/gocalc).
Link to comment
Share on other sites

Update:

I added new functions: Cbrt (Cube Root), Abs (Absolute Value), Ceil, Floor.

I also added user defined variables, check the updated example on the first post to see how it works.

Any feedback or ideas on features i should add are welcome 

Thanks
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...