diff --git a/README.md b/README.md index b50d5b7..6897575 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ calc supports all the standard stuff, and I'm definitely adding more later (also `+`, `-`, `*`, `/`, `^`, `%` ##### Functions -`sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `sqrt`, `log`, `lg`, `ln`, `abs` +`sin`, `cos`, `tan`, `cot`, `sec`, `csc`, `asin`, `acos`, `atan`, `acot`, `asec`, `acsc`, `sqrt`, `log`, `lg`, `ln`, `abs` ##### Constants `e`, `pi`, `π` diff --git a/operators/functions/trig.go b/operators/functions/trig.go index 26bbf06..e8daa54 100644 --- a/operators/functions/trig.go +++ b/operators/functions/trig.go @@ -36,6 +36,33 @@ var ( return math.Tan(args[0]) }, } + cot = &operators.Operator{ + Name: "cot", + Precedence: 0, + Associativity: operators.L, + Args: 1, + Operation: func(args []float64) float64 { + return 1 / math.Tan(args[0]) + }, + } + sec = &operators.Operator{ + Name: "sec", + Precedence: 0, + Associativity: operators.L, + Args: 1, + Operation: func(args []float64) float64 { + return 1 / math.Cos(args[0]) + }, + } + csc = &operators.Operator{ + Name: "csc", + Precedence: 0, + Associativity: operators.L, + Args: 1, + Operation: func(args []float64) float64 { + return 1 / math.Sin(args[0]) + }, + } asin = &operators.Operator{ Name: "asin", Precedence: 0, @@ -63,13 +90,46 @@ var ( return math.Atan(args[0]) }, } + acot = &operators.Operator{ + Name: "acot", + Precedence: 0, + Associativity: operators.L, + Args: 1, + Operation: func(args []float64) float64 { + return (-90 * ((math.Pi * math.Atan(args[0]) / 90) - math.Pi)) / math.Pi + }, + } + asec = &operators.Operator{ + Name: "asec", + Precedence: 0, + Associativity: operators.L, + Args: 1, + Operation: func(args []float64) float64 { + return math.Acos(1 / args[0]) + }, + } + acsc = &operators.Operator{ + Name: "acsc", + Precedence: 0, + Associativity: operators.L, + Args: 1, + Operation: func(args []float64) float64 { + return math.Asin(1 / args[0]) + }, + } ) func init() { Register(sin) Register(cos) Register(tan) + Register(cot) + Register(sec) + Register(csc) Register(asin) Register(acos) Register(atan) + Register(acot) + Register(asec) + Register(acsc) }