diff --git a/docs/querying/functions.md b/docs/querying/functions.md index 8583ce3ec6..4822d331d1 100644 --- a/docs/querying/functions.md +++ b/docs/querying/functions.md @@ -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: diff --git a/promql/functions.go b/promql/functions.go index 31f359ce3c..690550592f 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -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, diff --git a/promql/parser/functions.go b/promql/parser/functions.go index a12865a30a..3c281ec3dc 100644 --- a/promql/parser/functions.go +++ b/promql/parser/functions.go @@ -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{}, diff --git a/promql/testdata/trig_functions.test b/promql/testdata/trig_functions.test index 2db4e5deb6..56f480b4e2 100644 --- a/promql/testdata/trig_functions.test +++ b/promql/testdata/trig_functions.test @@ -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