value.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2016 The Prometheus Authors
  2. // Licensed under the Apache License, Version 2.0 (the "License");
  3. // you may not use this file except in compliance with the License.
  4. // You may obtain a copy of the License at
  5. //
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. package value
  14. import (
  15. "math"
  16. )
  17. const (
  18. // NormalNaN is a quiet NaN. This is also math.NaN().
  19. NormalNaN uint64 = 0x7ff8000000000001
  20. // StaleNaN is a signaling NaN, due to the MSB of the mantissa being 0.
  21. // This value is chosen with many leading 0s, so we have scope to store more
  22. // complicated values in the future. It is 2 rather than 1 to make
  23. // it easier to distinguish from the NormalNaN by a human when debugging.
  24. StaleNaN uint64 = 0x7ff0000000000002
  25. )
  26. // IsStaleNaN returns true when the provided NaN value is a stale marker.
  27. func IsStaleNaN(v float64) bool {
  28. return math.Float64bits(v) == StaleNaN
  29. }