An open API service indexing awesome lists of open source software.

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

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 main

import (
"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.3

val, err = calculator.Calculate("-sin((-1+2.5)*pi)")
if err != nil {
log.Fatal(err)
}
fmt.Println(val) // 1

val, 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