mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 06:17:27 -08:00
Added hyperbolic trig functions
Signed-off-by: Levi Harrison <git@leviharrison.dev>
This commit is contained in:
parent
a8ad569db8
commit
53d88fd147
|
@ -443,8 +443,11 @@ The trigonometric functions work in radians:
|
|||
- `asin(v instant-vector)`: calculates the arcsine of all elements in `v` ([special cases](https://pkg.go.dev/math#Asin)).
|
||||
- `atan(v instant-vector)`: calculates the arctangent of all elements in `v` ([special cases](https://pkg.go.dev/math#Atan)).
|
||||
- `cos(v instant-vector)`: calculates the cosine of all elements in `v` ([special cases](https://pkg.go.dev/math#Cos)).
|
||||
- `cosh(v instant-vector)`: calculates the hyperbolic cosine of all elements in `v` ([special cases](https://pkg.go.dev/math#Cosh)).
|
||||
- `sin(v instant-vector)`: calculates the sine of all elements in `v` ([special cases](https://pkg.go.dev/math#Sin)).
|
||||
- `sinh(v instant-vector)`: calculates the hyperbolic sine of all elements in `v` ([special cases](https://pkg.go.dev/math#Sinh)).
|
||||
- `tan(v instant-vector)`: calculates the tangent of all elements in `v` ([special cases](https://pkg.go.dev/math#Tan)).
|
||||
- `tanh(v instant-vector)`: calculates the hyperbolic tangent of all elements in `v` ([special cases](https://pkg.go.dev/math#Tanh)).
|
||||
|
||||
The following are useful for converting between degrees and radians:
|
||||
|
||||
|
|
|
@ -600,6 +600,21 @@ func funcAtan(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper)
|
|||
return simpleFunc(vals, enh, math.Atan)
|
||||
}
|
||||
|
||||
// == sinh(Vector parser.ValueTypeVector) Vector ===
|
||||
func funcSinh(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||
return simpleFunc(vals, enh, math.Sinh)
|
||||
}
|
||||
|
||||
// == cosh(Vector parser.ValueTypeVector) Vector ===
|
||||
func funcCosh(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||
return simpleFunc(vals, enh, math.Cosh)
|
||||
}
|
||||
|
||||
// == tanh(Vector parser.ValueTypeVector) Vector ===
|
||||
func funcTanh(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||
return simpleFunc(vals, enh, math.Tanh)
|
||||
}
|
||||
|
||||
// === rad(Vector parser.ValueTypeVector) Vector ===
|
||||
func funcRad(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||
return simpleFunc(vals, enh, func(v float64) float64 {
|
||||
|
@ -996,6 +1011,7 @@ var FunctionCalls = map[string]FunctionCall{
|
|||
"clamp_max": funcClampMax,
|
||||
"clamp_min": funcClampMin,
|
||||
"cos": funcCos,
|
||||
"cosh": funcCosh,
|
||||
"count_over_time": funcCountOverTime,
|
||||
"days_in_month": funcDaysInMonth,
|
||||
"day_of_month": funcDayOfMonth,
|
||||
|
@ -1032,6 +1048,7 @@ var FunctionCalls = map[string]FunctionCall{
|
|||
"scalar": funcScalar,
|
||||
"sgn": funcSgn,
|
||||
"sin": funcSin,
|
||||
"sinh": funcSinh,
|
||||
"sort": funcSort,
|
||||
"sort_desc": funcSortDesc,
|
||||
"sqrt": funcSqrt,
|
||||
|
@ -1039,6 +1056,7 @@ var FunctionCalls = map[string]FunctionCall{
|
|||
"stdvar_over_time": funcStdvarOverTime,
|
||||
"sum_over_time": funcSumOverTime,
|
||||
"tan": funcTan,
|
||||
"tanh": funcTanh,
|
||||
"time": funcTime,
|
||||
"timestamp": funcTimestamp,
|
||||
"vector": funcVector,
|
||||
|
|
|
@ -89,6 +89,11 @@ var Functions = map[string]*Function{
|
|||
ArgTypes: []ValueType{ValueTypeVector},
|
||||
ReturnType: ValueTypeVector,
|
||||
},
|
||||
"cosh": {
|
||||
Name: "cosh",
|
||||
ArgTypes: []ValueType{ValueTypeVector},
|
||||
ReturnType: ValueTypeVector,
|
||||
},
|
||||
"count_over_time": {
|
||||
Name: "count_over_time",
|
||||
ArgTypes: []ValueType{ValueTypeMatrix},
|
||||
|
@ -277,6 +282,11 @@ var Functions = map[string]*Function{
|
|||
ArgTypes: []ValueType{ValueTypeVector},
|
||||
ReturnType: ValueTypeVector,
|
||||
},
|
||||
"sinh": {
|
||||
Name: "sinh",
|
||||
ArgTypes: []ValueType{ValueTypeVector},
|
||||
ReturnType: ValueTypeVector,
|
||||
},
|
||||
"sort": {
|
||||
Name: "sort",
|
||||
ArgTypes: []ValueType{ValueTypeVector},
|
||||
|
@ -312,6 +322,11 @@ var Functions = map[string]*Function{
|
|||
ArgTypes: []ValueType{ValueTypeVector},
|
||||
ReturnType: ValueTypeVector,
|
||||
},
|
||||
"tanh": {
|
||||
Name: "tanh",
|
||||
ArgTypes: []ValueType{ValueTypeVector},
|
||||
ReturnType: ValueTypeVector,
|
||||
},
|
||||
"time": {
|
||||
Name: "time",
|
||||
ArgTypes: []ValueType{},
|
||||
|
|
19
promql/testdata/trig_functions.test
vendored
19
promql/testdata/trig_functions.test
vendored
|
@ -1,4 +1,4 @@
|
|||
# Testing sin() cos() tan() asin() acos() atan() rad() deg() pi().
|
||||
# Testing sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() rad() deg() pi().
|
||||
|
||||
load 5m
|
||||
trig{l="x"} 10
|
||||
|
@ -35,6 +35,21 @@ eval instant at 5m atan(trig)
|
|||
{l="y"} 1.5208379310729538
|
||||
{l="NaN"} NaN
|
||||
|
||||
eval instant at 5m sinh(trig)
|
||||
{l="x"} 11013.232920103324
|
||||
{l="y"} 2.4258259770489514e+08
|
||||
{l="NaN"} NaN
|
||||
|
||||
eval instant at 5m cosh(trig)
|
||||
{l="x"} 11013.232920103324
|
||||
{l="y"} 2.4258259770489514e+08
|
||||
{l="NaN"} NaN
|
||||
|
||||
eval instant at 5m tanh(trig)
|
||||
{l="x"} 0.9999999958776927
|
||||
{l="y"} 1
|
||||
{l="NaN"} NaN
|
||||
|
||||
eval instant at 5m rad(trig)
|
||||
{l="x"} 0.17453292519943295
|
||||
{l="y"} 0.3490658503988659
|
||||
|
@ -68,4 +83,4 @@ eval instant at 5m deg(trig - 20)
|
|||
clear
|
||||
|
||||
eval instant at 0s pi()
|
||||
{} 3.141592653589793
|
||||
3.141592653589793
|
||||
|
|
Loading…
Reference in a new issue