• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry
2 // Unit Test
3 
4 // Copyright (c) 2015 Oracle and/or its affiliates.
5 
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7 
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11 
12 
13 #include <geometry_test_common.hpp>
14 
15 #include <limits>
16 #include <boost/geometry/util/condition.hpp>
17 #include <boost/geometry/util/math.hpp>
18 
19 namespace bgm = bg::math;
20 
21 template <typename T>
test_all()22 void test_all()
23 {
24     BOOST_CHECK(bgm::equals(0, 0));
25     BOOST_CHECK(bgm::equals(1, 1));
26     BOOST_CHECK(bgm::equals(123456, 123456));
27 
28     T eps = std::numeric_limits<T>::epsilon();
29     if ( eps > 0 )
30     {
31         BOOST_CHECK(bgm::equals(0, 0+eps));
32         BOOST_CHECK(bgm::equals(0+eps, 0));
33         BOOST_CHECK(bgm::equals(1, 1+eps));
34         BOOST_CHECK(bgm::equals(1+eps, 1));
35         BOOST_CHECK(bgm::equals(12345+eps, 12345));
36     }
37 
38     if (BOOST_GEOMETRY_CONDITION(std::numeric_limits<T>::has_infinity))
39     {
40         T inf = std::numeric_limits<T>::infinity();
41         BOOST_CHECK(!bgm::equals(0, inf));
42         BOOST_CHECK(!bgm::equals(0, -inf));
43         BOOST_CHECK(!bgm::equals(1, inf));
44         BOOST_CHECK(!bgm::equals(1, -inf));
45         BOOST_CHECK(!bgm::equals(12345, inf));
46         BOOST_CHECK(!bgm::equals(12345, -inf));
47         BOOST_CHECK(!bgm::equals(inf, 0));
48         BOOST_CHECK(!bgm::equals(-inf, 0));
49         BOOST_CHECK(!bgm::equals(inf, 1));
50         BOOST_CHECK(!bgm::equals(-inf, 1));
51         BOOST_CHECK(!bgm::equals(inf, 12345));
52         BOOST_CHECK(!bgm::equals(-inf, 12345));
53         BOOST_CHECK(bgm::equals(inf, inf));
54         BOOST_CHECK(bgm::equals(-inf, -inf));
55         BOOST_CHECK(!bgm::equals(inf, -inf));
56         BOOST_CHECK(!bgm::equals(-inf, inf));
57     }
58 
59     if (BOOST_GEOMETRY_CONDITION(std::numeric_limits<T>::has_quiet_NaN))
60     {
61         T nan = std::numeric_limits<T>::quiet_NaN();
62         BOOST_CHECK(!bgm::equals(0, nan));
63         BOOST_CHECK(!bgm::equals(nan, 0));
64         BOOST_CHECK(!bgm::equals(nan, nan));
65         BOOST_CHECK(!bgm::equals(1, nan));
66         BOOST_CHECK(!bgm::equals(nan, 1));
67         BOOST_CHECK(!bgm::equals(12345, nan));
68         BOOST_CHECK(!bgm::equals(nan, 12345));
69     }
70 }
71 
test_main(int,char * [])72 int test_main(int, char* [])
73 {
74     test_all<int>();
75     test_all<float>();
76     test_all<double>();
77 
78     return 0;
79 }
80