calculator

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 6 Imported by: 7

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Calculate

func Calculate(expr string) (float64, error)

Calculate calculates expr

Types

This section is empty.

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL