예제 #1
0
파일: trig.go 프로젝트: gpahal/calc
	"github.com/gpahal/calc/operators"

	"github.com/shopspring/decimal"
)

var (
	one = decimal.New(1, 0)

	sin = &operators.Operator{
		Name:          "sin",
		Precedence:    0,
		Associativity: operators.L,
		Args:          1,
		Operation: func(args []decimal.Decimal) decimal.Decimal {
			return operators.ConvertToDecimalUnary(math.Sin, args[0])
		},
	}
	cos = &operators.Operator{
		Name:          "cos",
		Precedence:    0,
		Associativity: operators.L,
		Args:          1,
		Operation: func(args []decimal.Decimal) decimal.Decimal {
			return operators.ConvertToDecimalUnary(math.Cos, args[0])
		},
	}
	tan = &operators.Operator{
		Name:          "tan",
		Precedence:    0,
		Associativity: operators.L,
예제 #2
0
파일: sqrt.go 프로젝트: gpahal/calc
package functions

import (
	"math"

	"github.com/gpahal/calc/operators"

	"github.com/shopspring/decimal"
)

var (
	sqrt = &operators.Operator{
		Name:          "sqrt",
		Precedence:    0,
		Associativity: operators.L,
		Args:          1,
		Operation: func(args []decimal.Decimal) decimal.Decimal {
			return operators.ConvertToDecimalUnary(math.Sqrt, args[0])
		},
	}
)

func init() {
	Register(sqrt)
}
예제 #3
0
파일: log.go 프로젝트: gpahal/calc
import (
	"math"

	"github.com/gpahal/calc/operators"

	"github.com/shopspring/decimal"
)

var (
	log = &operators.Operator{
		Name:          "log",
		Precedence:    0,
		Associativity: operators.L,
		Args:          1,
		Operation: func(args []decimal.Decimal) decimal.Decimal {
			return operators.ConvertToDecimalUnary(math.Log10, args[0])
		},
	}
	ln = &operators.Operator{
		Name:          "ln",
		Precedence:    0,
		Associativity: operators.L,
		Args:          1,
		Operation: func(args []decimal.Decimal) decimal.Decimal {
			return operators.ConvertToDecimalUnary(math.Log, args[0])
		},
	}
	lg = &operators.Operator{
		Name:          "lg",
		Precedence:    0,
		Associativity: operators.L,