Coverage Report

Created: 2023-09-25 06:27

/src/abseil-cpp/absl/numeric/internal/representation.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2021 The Abseil Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef ABSL_NUMERIC_INTERNAL_REPRESENTATION_H_
16
#define ABSL_NUMERIC_INTERNAL_REPRESENTATION_H_
17
18
#include <limits>
19
20
#include "absl/base/config.h"
21
22
namespace absl {
23
ABSL_NAMESPACE_BEGIN
24
namespace numeric_internal {
25
26
// Returns true iff long double is represented as a pair of doubles added
27
// together.
28
0
inline constexpr bool IsDoubleDouble() {
29
0
  // A double-double value always has exactly twice the precision of a double
30
0
  // value--one double carries the high digits and one double carries the low
31
0
  // digits. This property is not shared with any other common floating-point
32
0
  // representation, so this test won't trigger false positives. For reference,
33
0
  // this table gives the number of bits of precision of each common
34
0
  // floating-point representation:
35
0
  //
36
0
  //                type     precision
37
0
  //         IEEE single          24 b
38
0
  //         IEEE double          53
39
0
  //     x86 long double          64
40
0
  //       double-double         106
41
0
  //      IEEE quadruple         113
42
0
  //
43
0
  // Note in particular that a quadruple-precision float has greater precision
44
0
  // than a double-double float despite taking up the same amount of memory; the
45
0
  // quad has more of its bits allocated to the mantissa than the double-double
46
0
  // has.
47
0
  return std::numeric_limits<long double>::digits ==
48
0
         2 * std::numeric_limits<double>::digits;
49
0
}
50
51
}  // namespace numeric_internal
52
ABSL_NAMESPACE_END
53
}  // namespace absl
54
55
#endif  // ABSL_NUMERIC_INTERNAL_REPRESENTATION_H_