mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-13 09:04:06 -08:00
Merge pull request #598 from prometheus/binop-special-float-values
Fix special value handling in division and modulo.
This commit is contained in:
commit
60c7748a17
|
@ -637,15 +637,12 @@ func evalScalarBinop(opType BinOpType,
|
||||||
case Mul:
|
case Mul:
|
||||||
return lhs * rhs
|
return lhs * rhs
|
||||||
case Div:
|
case Div:
|
||||||
if rhs != 0 {
|
return lhs / rhs
|
||||||
return lhs / rhs
|
|
||||||
}
|
|
||||||
return clientmodel.SampleValue(math.Inf(int(rhs)))
|
|
||||||
case Mod:
|
case Mod:
|
||||||
if rhs != 0 {
|
if rhs != 0 {
|
||||||
return clientmodel.SampleValue(int(lhs) % int(rhs))
|
return clientmodel.SampleValue(int(lhs) % int(rhs))
|
||||||
}
|
}
|
||||||
return clientmodel.SampleValue(math.Inf(int(rhs)))
|
return clientmodel.SampleValue(math.NaN())
|
||||||
case EQ:
|
case EQ:
|
||||||
if lhs == rhs {
|
if lhs == rhs {
|
||||||
return 1
|
return 1
|
||||||
|
@ -691,15 +688,12 @@ func evalVectorBinop(opType BinOpType,
|
||||||
case Mul:
|
case Mul:
|
||||||
return lhs * rhs, true
|
return lhs * rhs, true
|
||||||
case Div:
|
case Div:
|
||||||
if rhs != 0 {
|
return lhs / rhs, true
|
||||||
return lhs / rhs, true
|
|
||||||
}
|
|
||||||
return clientmodel.SampleValue(math.Inf(int(rhs))), true
|
|
||||||
case Mod:
|
case Mod:
|
||||||
if rhs != 0 {
|
if rhs != 0 {
|
||||||
return clientmodel.SampleValue(int(lhs) % int(rhs)), true
|
return clientmodel.SampleValue(int(lhs) % int(rhs)), true
|
||||||
}
|
}
|
||||||
return clientmodel.SampleValue(math.Inf(int(rhs))), true
|
return clientmodel.SampleValue(math.NaN()), true
|
||||||
case EQ:
|
case EQ:
|
||||||
if lhs == rhs {
|
if lhs == rhs {
|
||||||
return lhs, true
|
return lhs, true
|
||||||
|
|
|
@ -1157,6 +1157,46 @@ func TestExpressions(t *testing.T) {
|
||||||
expr: `999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`,
|
expr: `999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`,
|
||||||
output: []string{`scalar: +Inf @[%v]`},
|
output: []string{`scalar: +Inf @[%v]`},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
expr: `1 / 0`,
|
||||||
|
output: []string{`scalar: +Inf @[%v]`},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `-1 / 0`,
|
||||||
|
output: []string{`scalar: -Inf @[%v]`},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `0 / 0`,
|
||||||
|
output: []string{`scalar: NaN @[%v]`},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `1 % 0`,
|
||||||
|
output: []string{`scalar: NaN @[%v]`},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `http_requests{group="canary", instance="0", job="api-server"} / 0`,
|
||||||
|
output: []string{
|
||||||
|
`{group="canary", instance="0", job="api-server"} => +Inf @[%v]`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `-1 * http_requests{group="canary", instance="0", job="api-server"} / 0`,
|
||||||
|
output: []string{
|
||||||
|
`{group="canary", instance="0", job="api-server"} => -Inf @[%v]`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `0 * http_requests{group="canary", instance="0", job="api-server"} / 0`,
|
||||||
|
output: []string{
|
||||||
|
`{group="canary", instance="0", job="api-server"} => NaN @[%v]`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `0 * http_requests{group="canary", instance="0", job="api-server"} % 0`,
|
||||||
|
output: []string{
|
||||||
|
`{group="canary", instance="0", job="api-server"} => NaN @[%v]`,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
storage, closer := newTestStorage(t)
|
storage, closer := newTestStorage(t)
|
||||||
|
|
Loading…
Reference in a new issue