diff --git a/docs/querying/functions.md b/docs/querying/functions.md index 45a559b7e..33740ac4a 100644 --- a/docs/querying/functions.md +++ b/docs/querying/functions.md @@ -440,8 +440,11 @@ aggregation even if the values are not equally spaced throughout the interval. The trigonometric functions work in radians: - `acos(v instant-vector)`: calculates the arccosine of all elements in `v` ([special cases](https://pkg.go.dev/math#Acos)). +- `acosh(v instant-vector)`: calculates the inverse hyperbolic cosine of all elements in `v` ([special cases](https://pkg.go.dev/math#Acosh)). - `asin(v instant-vector)`: calculates the arcsine of all elements in `v` ([special cases](https://pkg.go.dev/math#Asin)). +- `asinh(v instant-vector)`: calculates the inverse hyperbolic sine of all elements in `v` ([special cases](https://pkg.go.dev/math#Asinh)). - `atan(v instant-vector)`: calculates the arctangent of all elements in `v` ([special cases](https://pkg.go.dev/math#Atan)). +- `atanh(v instant-vector)`: calculates the inverse hyperbolic tangent of all elements in `v` ([special cases](https://pkg.go.dev/math#Atanh)). - `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)). diff --git a/promql/functions.go b/promql/functions.go index a093640c1..7d1db327d 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -615,6 +615,21 @@ func funcTanh(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) return simpleFunc(vals, enh, math.Tanh) } +// == asinh(Vector parser.ValueTypeVector) Vector === +func funcAsinh(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector { + return simpleFunc(vals, enh, math.Asinh) +} + +// == acosh(Vector parser.ValueTypeVector) Vector === +func funcAcosh(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector { + return simpleFunc(vals, enh, math.Acosh) +} + +// == atanh(Vector parser.ValueTypeVector) Vector === +func funcAtanh(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector { + return simpleFunc(vals, enh, math.Atanh) +} + // === rad(Vector parser.ValueTypeVector) Vector === func funcRad(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector { return simpleFunc(vals, enh, func(v float64) float64 { @@ -1002,8 +1017,11 @@ var FunctionCalls = map[string]FunctionCall{ "absent": funcAbsent, "absent_over_time": funcAbsentOverTime, "acos": funcAcos, + "acosh": funcAcosh, "asin": funcAsin, + "asinh": funcAsinh, "atan": funcAtan, + "atanh": funcAtanh, "avg_over_time": funcAvgOverTime, "ceil": funcCeil, "changes": funcChanges, diff --git a/promql/parser/functions.go b/promql/parser/functions.go index 3c281ec3d..c4bc5ddb8 100644 --- a/promql/parser/functions.go +++ b/promql/parser/functions.go @@ -44,16 +44,31 @@ var Functions = map[string]*Function{ ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, + "acosh": { + Name: "acosh", + ArgTypes: []ValueType{ValueTypeVector}, + ReturnType: ValueTypeVector, + }, "asin": { Name: "asin", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, + "asinh": { + Name: "asinh", + ArgTypes: []ValueType{ValueTypeVector}, + ReturnType: ValueTypeVector, + }, "atan": { Name: "atan", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, + "atanh": { + Name: "atanh", + ArgTypes: []ValueType{ValueTypeVector}, + ReturnType: ValueTypeVector, + }, "avg_over_time": { Name: "avg_over_time", ArgTypes: []ValueType{ValueTypeMatrix}, diff --git a/promql/testdata/trig_functions.test b/promql/testdata/trig_functions.test index 56f480b4e..fa5f94651 100644 --- a/promql/testdata/trig_functions.test +++ b/promql/testdata/trig_functions.test @@ -50,6 +50,21 @@ eval instant at 5m tanh(trig) {l="y"} 1 {l="NaN"} NaN +eval instant at 5m asinh(trig) + {l="x"} 2.99822295029797 + {l="y"} 3.6895038689889055 + {l="NaN"} NaN + +eval instant at 5m acosh(trig) + {l="x"} 2.993222846126381 + {l="y"} 3.6882538673612966 + {l="NaN"} NaN + +eval instant at 5m atanh(trig - 10.1) + {l="x"} -0.10033534773107522 + {l="y"} NaN + {l="NaN"} NaN + eval instant at 5m rad(trig) {l="x"} 0.17453292519943295 {l="y"} 0.3490658503988659