1 | #include <stdint.h>
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <iostream>
|
---|
4 | #include <cmath>
|
---|
5 | #include <boost/multiprecision/cpp_bin_float.hpp>
|
---|
6 |
|
---|
7 | typedef boost::multiprecision::number<boost::multiprecision::cpp_bin_float<128, boost::multiprecision::backends::digit_base_2> > boost_float128_t;
|
---|
8 |
|
---|
9 | // static bool mine_is_better(const extfloat128_t a[2], const extfloat128_t& ra)
|
---|
10 | // {
|
---|
11 | // if (a[0]==0 && a[1] < 0 && a[0].m_sign != 0 && ra==-1)
|
---|
12 | // return true; // patch, boost returns +1, my answer is -1. Mine is better
|
---|
13 | // if (isnan(a[1]) && isnan(ra))
|
---|
14 | // return true; // patch, boost returns 0, my answer is nan. Mine is better
|
---|
15 | // if (a[0]==0 && a[1]==0 && isnan(ra))
|
---|
16 | // return true; // patch, boost returns 0, my answer is nan. Mine is better
|
---|
17 | // return false;
|
---|
18 | // }
|
---|
19 |
|
---|
20 | int main(int , char** )
|
---|
21 | {
|
---|
22 | double tests[][2] = {
|
---|
23 | { HUGE_VAL, HUGE_VAL},
|
---|
24 | { -HUGE_VAL, HUGE_VAL},
|
---|
25 | { HUGE_VAL,-HUGE_VAL},
|
---|
26 | { -HUGE_VAL,-HUGE_VAL},
|
---|
27 | { -0.0, -1.0 },
|
---|
28 | { 0.0, nan("")},
|
---|
29 | { HUGE_VAL, nan("")},
|
---|
30 | { -HUGE_VAL, nan("")},
|
---|
31 | };
|
---|
32 | for (int i = 0; i < 8; ++i) {
|
---|
33 | double y = tests[i][0];
|
---|
34 | double x = tests[i][1];
|
---|
35 | double r = atan2(y, x);
|
---|
36 | boost_float128_t by = y;
|
---|
37 | boost_float128_t bx = x;
|
---|
38 | boost_float128_t br = atan2(by, bx);
|
---|
39 | std::cout << "C RTL atan2(" << y << "," << x << ") = " << r << "\n";
|
---|
40 | std::cout << "Boost atan2(" << by << "," << bx << ") = " << br << "\n";
|
---|
41 | }
|
---|
42 | return 0;
|
---|
43 | }
|
---|