Skip to content

A scientific calculator CLI (Command Line Interface) tool and library written in Go

License

Notifications You must be signed in to change notification settings

mnogu/go-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d1712c8 · Oct 27, 2020

History

20 Commits
Oct 25, 2020
Oct 25, 2020
Oct 25, 2020
Oct 25, 2020
Oct 25, 2020
Oct 25, 2020
Oct 27, 2020
Oct 25, 2020
Oct 25, 2020
Oct 25, 2020
Oct 27, 2020
Oct 25, 2020

Repository files navigation

go-calculator

Requirements

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:

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

About

A scientific calculator CLI (Command Line Interface) tool and library written in Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages