Exemplo n.º 1
0
Arquivo: trig.go Projeto: 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,
Exemplo n.º 2
0
Arquivo: sqrt.go Projeto: 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)
}
Exemplo n.º 3
0
Arquivo: log.go Projeto: 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,