mirror of https://github.com/prometheus/prometheus
Added hyperbolic trig functions
Signed-off-by: Levi Harrison <git@leviharrison.dev>pull/9239/head
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)).
|
- `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)).
|
- `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)).
|
- `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)).
|
- `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)).
|
- `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:
|
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)
|
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 ===
|
// === rad(Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcRad(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
func funcRad(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return simpleFunc(vals, enh, func(v float64) float64 {
|
return simpleFunc(vals, enh, func(v float64) float64 {
|
||||||
|
@ -996,6 +1011,7 @@ var FunctionCalls = map[string]FunctionCall{
|
||||||
"clamp_max": funcClampMax,
|
"clamp_max": funcClampMax,
|
||||||
"clamp_min": funcClampMin,
|
"clamp_min": funcClampMin,
|
||||||
"cos": funcCos,
|
"cos": funcCos,
|
||||||
|
"cosh": funcCosh,
|
||||||
"count_over_time": funcCountOverTime,
|
"count_over_time": funcCountOverTime,
|
||||||
"days_in_month": funcDaysInMonth,
|
"days_in_month": funcDaysInMonth,
|
||||||
"day_of_month": funcDayOfMonth,
|
"day_of_month": funcDayOfMonth,
|
||||||
|
@ -1032,6 +1048,7 @@ var FunctionCalls = map[string]FunctionCall{
|
||||||
"scalar": funcScalar,
|
"scalar": funcScalar,
|
||||||
"sgn": funcSgn,
|
"sgn": funcSgn,
|
||||||
"sin": funcSin,
|
"sin": funcSin,
|
||||||
|
"sinh": funcSinh,
|
||||||
"sort": funcSort,
|
"sort": funcSort,
|
||||||
"sort_desc": funcSortDesc,
|
"sort_desc": funcSortDesc,
|
||||||
"sqrt": funcSqrt,
|
"sqrt": funcSqrt,
|
||||||
|
@ -1039,6 +1056,7 @@ var FunctionCalls = map[string]FunctionCall{
|
||||||
"stdvar_over_time": funcStdvarOverTime,
|
"stdvar_over_time": funcStdvarOverTime,
|
||||||
"sum_over_time": funcSumOverTime,
|
"sum_over_time": funcSumOverTime,
|
||||||
"tan": funcTan,
|
"tan": funcTan,
|
||||||
|
"tanh": funcTanh,
|
||||||
"time": funcTime,
|
"time": funcTime,
|
||||||
"timestamp": funcTimestamp,
|
"timestamp": funcTimestamp,
|
||||||
"vector": funcVector,
|
"vector": funcVector,
|
||||||
|
|
|
@ -89,6 +89,11 @@ var Functions = map[string]*Function{
|
||||||
ArgTypes: []ValueType{ValueTypeVector},
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
|
"cosh": {
|
||||||
|
Name: "cosh",
|
||||||
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
"count_over_time": {
|
"count_over_time": {
|
||||||
Name: "count_over_time",
|
Name: "count_over_time",
|
||||||
ArgTypes: []ValueType{ValueTypeMatrix},
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
||||||
|
@ -277,6 +282,11 @@ var Functions = map[string]*Function{
|
||||||
ArgTypes: []ValueType{ValueTypeVector},
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
|
"sinh": {
|
||||||
|
Name: "sinh",
|
||||||
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
"sort": {
|
"sort": {
|
||||||
Name: "sort",
|
Name: "sort",
|
||||||
ArgTypes: []ValueType{ValueTypeVector},
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
@ -312,6 +322,11 @@ var Functions = map[string]*Function{
|
||||||
ArgTypes: []ValueType{ValueTypeVector},
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
|
"tanh": {
|
||||||
|
Name: "tanh",
|
||||||
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
"time": {
|
"time": {
|
||||||
Name: "time",
|
Name: "time",
|
||||||
ArgTypes: []ValueType{},
|
ArgTypes: []ValueType{},
|
||||||
|
|
|
@ -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
|
load 5m
|
||||||
trig{l="x"} 10
|
trig{l="x"} 10
|
||||||
|
@ -35,6 +35,21 @@ eval instant at 5m atan(trig)
|
||||||
{l="y"} 1.5208379310729538
|
{l="y"} 1.5208379310729538
|
||||||
{l="NaN"} NaN
|
{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)
|
eval instant at 5m rad(trig)
|
||||||
{l="x"} 0.17453292519943295
|
{l="x"} 0.17453292519943295
|
||||||
{l="y"} 0.3490658503988659
|
{l="y"} 0.3490658503988659
|
||||||
|
@ -68,4 +83,4 @@ eval instant at 5m deg(trig - 20)
|
||||||
clear
|
clear
|
||||||
|
|
||||||
eval instant at 0s pi()
|
eval instant at 0s pi()
|
||||||
{} 3.141592653589793
|
3.141592653589793
|
||||||
|
|
Loading…
Reference in New Issue