Ejemplo n.º 1
0
Archivo: trig.go Proyecto: 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,
Ejemplo n.º 2
0
Archivo: sqrt.go Proyecto: 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)
}
Ejemplo n.º 3
0
Archivo: log.go Proyecto: 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,