https://github.com/mnogu/go-calculator
A scientific calculator CLI (Command Line Interface) tool and library written in Go
https://github.com/mnogu/go-calculator
ast calculator cli golang recursive-descent-parser scientific-calculator
Last synced: 6 months ago
JSON representation
A scientific calculator CLI (Command Line Interface) tool and library written in Go
- Host: GitHub
- URL: https://github.com/mnogu/go-calculator
- Owner: mnogu
- License: mit
- Created: 2020-10-25T02:05:24.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-12-23T16:09:51.000Z (almost 4 years ago)
- Last Synced: 2025-04-22T15:09:02.527Z (6 months ago)
- Topics: ast, calculator, cli, golang, recursive-descent-parser, scientific-calculator
- Language: Go
- Homepage:
- Size: 23.4 KB
- Stars: 30
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-calculator
## Requirements
* Go 1.14+
* for [`math.FMA()`](https://golang.org/pkg/math/#FMA)## Usage
```
$ go run cmd/calculator/main.go
calculator> (2.5 - 1.35) * 2.0
2.3
calculator> -sin((-1+2.5)*pi)
1
calculator> 180*atan2(log(e), log10(10))/pi
45
calculator> exit
```You can also use `calculator.Calculate()` in your application:
```go
package mainimport (
"fmt"
"log""github.com/mnogu/go-calculator"
)func main() {
val, err := calculator.Calculate("(2.5 - 1.35) * 2.0")
if err != nil {
log.Fatal(err)
}
fmt.Println(val) // 2.3val, err = calculator.Calculate("-sin((-1+2.5)*pi)")
if err != nil {
log.Fatal(err)
}
fmt.Println(val) // 1val, err = calculator.Calculate("180*atan2(log(e), log10(10))/pi")
if err != nil {
log.Fatal(err)
}
fmt.Println(val) // 45
}
```## References
* [chibicc](https://github.com/rui314/chibicc): A small C compiler