#include "CxxUtils/checker_macros.h"
#include "gtest/gtest.h"
#include "../ap_fixed.h"
#include <sstream>
#include <cmath>
Go to the source code of this file.
|
constexpr int | pow (int base, int exp) noexcept |
|
template<int W, int P> |
constexpr double | min () |
|
template<int W, int P> |
constexpr double | max () |
|
| TEST (ap_fixedTester, minmax) |
|
| TEST (ap_fixedTester, stablity) |
|
| TEST (ap_fixedTester, specialValue) |
|
| TEST (ap_fixedTester, overflow_h) |
|
| TEST (ap_fixedTester, overflow_l) |
|
| TEST (ap_fixedTester, addition) |
|
| TEST (ap_fixedTester, addition1) |
|
| TEST (ap_fixedTester, subtraction) |
|
| TEST (ap_fixedTester, subtraction1) |
|
| TEST (ap_fixedTester, multiplication) |
|
| TEST (ap_fixedTester, multiplication1) |
|
| TEST (ap_fixedTester, division) |
|
| TEST (ap_fixedTester, division1) |
|
| TEST (ap_fixedTester, negation) |
|
| TEST (ap_fixedTester, doubleMult) |
|
◆ max()
Definition at line 33 of file ap_fixedTest.cxx.
34 static_assert(
W >=
P);
35 static_assert(
P >= 0);
36 return static_cast<double>(
pow(2,
W-1)-1)/
static_cast<double>(
pow(2,
P));
◆ min()
◆ pow()
constexpr int pow |
( |
int |
base, |
|
|
int |
exp |
|
) |
| |
|
constexprnoexcept |
◆ TEST() [1/15]
TEST |
( |
ap_fixedTester |
, |
|
|
addition |
|
|
) |
| |
Definition at line 114 of file ap_fixedTest.cxx.
116 constexpr
int width{10};
117 constexpr
int prec{5};
121 ap ap_sum =
ap(1) +
ap(2);
122 auto val =
static_cast<double>(ap_sum);
126 EXPECT_LT (
diff, eps);
128 ap_sum =
ap(1.5) +
ap(2.5);
129 val =
static_cast<double>(ap_sum);
133 EXPECT_LT (
diff, eps);
◆ TEST() [2/15]
TEST |
( |
ap_fixedTester |
, |
|
|
addition1 |
|
|
) |
| |
Definition at line 136 of file ap_fixedTest.cxx.
138 constexpr
int width{10};
139 constexpr
int prec{5};
143 ap ap_sum =
ap(2) += 1;
144 auto val =
static_cast<double>(ap_sum);
148 EXPECT_LT (
diff, eps);
150 ap_sum =
ap(1.5) += 2.5;
151 val =
static_cast<double>(ap_sum);
155 EXPECT_LT (
diff, eps);
◆ TEST() [3/15]
TEST |
( |
ap_fixedTester |
, |
|
|
division |
|
|
) |
| |
Definition at line 249 of file ap_fixedTest.cxx.
251 constexpr
int width{10};
252 constexpr
int prec{5};
257 auto val =
static_cast<double>(ap_div);
258 auto diff = std::abs(
val - 0.5);
260 EXPECT_EQ (0.5,
val);
261 EXPECT_LT (
diff, eps);
263 ap_div =
ap(-1.5)/
ap(2);
264 val =
static_cast<double>(ap_div);
267 EXPECT_EQ (-0.75,
val);
268 EXPECT_LT (
diff, eps);
◆ TEST() [4/15]
TEST |
( |
ap_fixedTester |
, |
|
|
division1 |
|
|
) |
| |
Definition at line 272 of file ap_fixedTest.cxx.
274 constexpr
int width{10};
275 constexpr
int prec{5};
280 auto val =
static_cast<double>(ap_div);
281 auto diff = std::abs(
val - 0.5);
283 EXPECT_EQ (0.5,
val);
284 EXPECT_LT (
diff, eps);
286 ap_div =
ap(-1.5)/
ap(2);
287 val =
static_cast<double>(ap_div);
290 EXPECT_EQ (-0.75,
val);
291 EXPECT_LT (
diff, eps);
◆ TEST() [5/15]
TEST |
( |
ap_fixedTester |
, |
|
|
doubleMult |
|
|
) |
| |
Definition at line 314 of file ap_fixedTest.cxx.
316 constexpr
int width{10};
317 constexpr
int prec{5};
320 ap ap_mul = 9.99 *
ap(1);
322 EXPECT_EQ (10,
static_cast<double>(ap_mul));
◆ TEST() [6/15]
TEST |
( |
ap_fixedTester |
, |
|
|
minmax |
|
|
) |
| |
Definition at line 39 of file ap_fixedTest.cxx.
41 auto min_v = min<10, 5>();
42 auto max_v = max<10, 5>();
43 EXPECT_EQ(-16, min_v);
44 EXPECT_EQ(15.96875, max_v);
◆ TEST() [7/15]
TEST |
( |
ap_fixedTester |
, |
|
|
multiplication |
|
|
) |
| |
Definition at line 205 of file ap_fixedTest.cxx.
207 constexpr
int width{10};
208 constexpr
int prec{5};
212 ap ap_prod =
ap(1) *
ap(2);
213 auto val =
static_cast<double>(ap_prod);
217 EXPECT_LT (
diff, eps);
219 ap_prod =
ap(-1.5)*
ap(2);
220 val =
static_cast<double>(ap_prod);
224 EXPECT_LT (
diff, eps);
◆ TEST() [8/15]
TEST |
( |
ap_fixedTester |
, |
|
|
multiplication1 |
|
|
) |
| |
Definition at line 227 of file ap_fixedTest.cxx.
228 constexpr
int width{10};
229 constexpr
int prec{5};
233 ap ap_prod =
ap(1) *=
ap(2);
234 auto val =
static_cast<double>(ap_prod);
238 EXPECT_LT (
diff, eps);
240 ap_prod =
ap(-1.5) *=
ap(2.);
241 val =
static_cast<double>(ap_prod);
245 EXPECT_LT (
diff, eps);
◆ TEST() [9/15]
TEST |
( |
ap_fixedTester |
, |
|
|
negation |
|
|
) |
| |
Definition at line 295 of file ap_fixedTest.cxx.
297 constexpr
int width{10};
298 constexpr
int prec{5};
306 auto val_p =
static_cast<double>(ap_p);
307 auto val_n =
static_cast<double>(ap_n);
308 auto val_pp =
static_cast<double>(ap_pp);
310 EXPECT_EQ (val_p, -
val_n);
311 EXPECT_EQ (val_p, val_pp);
◆ TEST() [10/15]
TEST |
( |
ap_fixedTester |
, |
|
|
overflow_h |
|
|
) |
| |
EXPECT does not take templates, provide a new typename
Definition at line 90 of file ap_fixedTest.cxx.
91 constexpr
int width{10};
92 constexpr
int prec{5};
97 double outOfRange = max<width, prec>() +
pow(2, -
prec-1);
99 EXPECT_THROW ((
ap(outOfRange)), std::out_of_range);
◆ TEST() [11/15]
TEST |
( |
ap_fixedTester |
, |
|
|
overflow_l |
|
|
) |
| |
Definition at line 102 of file ap_fixedTest.cxx.
103 constexpr
int width{10};
104 constexpr
int prec{5};
107 double outOfRange = min<width, prec>() -
pow(2, -
prec-1);
110 EXPECT_THROW ((
ap(outOfRange)), std::out_of_range);
◆ TEST() [12/15]
TEST |
( |
ap_fixedTester |
, |
|
|
specialValue |
|
|
) |
| |
Definition at line 78 of file ap_fixedTest.cxx.
82 EXPECT_EQ (-0.3125,
static_cast<double>(apf));
84 ss << std::hex << apf.m_value;
85 EXPECT_EQ (
"fff6",
ss.str());
◆ TEST() [13/15]
TEST |
( |
ap_fixedTester |
, |
|
|
stablity |
|
|
) |
| |
Definition at line 47 of file ap_fixedTest.cxx.
50 constexpr
int width{10};
51 constexpr
int prec{5};
54 double val = min<width, prec>();
55 double max_val = max<width, prec>();
60 while (cval <= max_val) {
63 double d0 =
static_cast<double>(ap_gs0);
65 double d1 =
static_cast<double>(ap_gs1);
67 double d2 =
static_cast<double>(ap_gs2);
70 EXPECT_EQ (ap_gs0.m_value, ap_gs2.m_value);
71 EXPECT_LT (std::abs(
d0 -cval), 1./(2*2*2*2*2));
74 cval = -
val + ((++
i) * delta);
◆ TEST() [14/15]
TEST |
( |
ap_fixedTester |
, |
|
|
subtraction |
|
|
) |
| |
Definition at line 159 of file ap_fixedTest.cxx.
161 constexpr
int width{10};
162 constexpr
int prec{5};
166 ap ap_diff =
ap(1) -
ap(2);
167 auto val =
static_cast<double>(ap_diff);
171 EXPECT_LT (
diff, eps);
173 ap_diff =
ap(1.5) -
ap(2.5);
174 val =
static_cast<double>(ap_diff);
178 EXPECT_LT (
diff, eps);
◆ TEST() [15/15]
TEST |
( |
ap_fixedTester |
, |
|
|
subtraction1 |
|
|
) |
| |
Definition at line 181 of file ap_fixedTest.cxx.
183 constexpr
int width{10};
184 constexpr
int prec{5};
188 ap ap_diff =
ap(1) -= 2;
189 auto val =
static_cast<double>(ap_diff);
193 EXPECT_LT (
diff, eps);
195 ap_diff =
ap(1.5) -= 2.5;
196 val =
static_cast<double>(ap_diff);
200 EXPECT_LT (
diff, eps);
◆ ATLAS_NO_CHECK_FILE_THREAD_SAFETY
ATLAS_NO_CHECK_FILE_THREAD_SAFETY |