Пример #1
0
	"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
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,