Esempio n. 1
0
File: trig.go Progetto: 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,
Esempio n. 2
0
File: sqrt.go Progetto: 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)
}
Esempio n. 3
0
File: log.go Progetto: 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,