Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Added Trig Functions
Browse files Browse the repository at this point in the history
Adds cot, sec, csc, and their inverse functions.
  • Loading branch information
Chris Dickerman committed Feb 18, 2015
1 parent 3d39065 commit 75a253d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`, `π`
Expand Down
60 changes: 60 additions & 0 deletions operators/functions/trig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

0 comments on commit 75a253d

Please sign in to comment.