summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/geometry/test/util/math_equals.cpp
blob: 0f26f6951e0d01d5c3a698aec8cef4e098729194 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Boost.Geometry
// Unit Test

// Copyright (c) 2015 Oracle and/or its affiliates.

// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)


#include <geometry_test_common.hpp>

#include <limits>
#include <boost/geometry/util/condition.hpp>
#include <boost/geometry/util/math.hpp>

namespace bgm = bg::math;

template <typename T>
void test_all()
{
    BOOST_CHECK(bgm::equals(0, 0));
    BOOST_CHECK(bgm::equals(1, 1));
    BOOST_CHECK(bgm::equals(123456, 123456));
    
    T eps = std::numeric_limits<T>::epsilon();
    if ( eps > 0 )
    {
        BOOST_CHECK(bgm::equals(0, 0+eps));
        BOOST_CHECK(bgm::equals(0+eps, 0));
        BOOST_CHECK(bgm::equals(1, 1+eps));
        BOOST_CHECK(bgm::equals(1+eps, 1));
        BOOST_CHECK(bgm::equals(12345+eps, 12345));
    }

    if (BOOST_GEOMETRY_CONDITION(std::numeric_limits<T>::has_infinity))
    {
        T inf = std::numeric_limits<T>::infinity();
        BOOST_CHECK(!bgm::equals(0, inf));
        BOOST_CHECK(!bgm::equals(0, -inf));
        BOOST_CHECK(!bgm::equals(1, inf));
        BOOST_CHECK(!bgm::equals(1, -inf));
        BOOST_CHECK(!bgm::equals(12345, inf));
        BOOST_CHECK(!bgm::equals(12345, -inf));
        BOOST_CHECK(!bgm::equals(inf, 0));
        BOOST_CHECK(!bgm::equals(-inf, 0));
        BOOST_CHECK(!bgm::equals(inf, 1));
        BOOST_CHECK(!bgm::equals(-inf, 1));
        BOOST_CHECK(!bgm::equals(inf, 12345));
        BOOST_CHECK(!bgm::equals(-inf, 12345));
        BOOST_CHECK(bgm::equals(inf, inf));
        BOOST_CHECK(bgm::equals(-inf, -inf));
        BOOST_CHECK(!bgm::equals(inf, -inf));
        BOOST_CHECK(!bgm::equals(-inf, inf));
    }

    if (BOOST_GEOMETRY_CONDITION(std::numeric_limits<T>::has_quiet_NaN))
    {
        T nan = std::numeric_limits<T>::quiet_NaN();
        BOOST_CHECK(!bgm::equals(0, nan));
        BOOST_CHECK(!bgm::equals(nan, 0));
        BOOST_CHECK(!bgm::equals(nan, nan));
        BOOST_CHECK(!bgm::equals(1, nan));
        BOOST_CHECK(!bgm::equals(nan, 1));
        BOOST_CHECK(!bgm::equals(12345, nan));
        BOOST_CHECK(!bgm::equals(nan, 12345));
    }
}

int test_main(int, char* [])
{
    test_all<int>();
    test_all<float>();
    test_all<double>();
    
    return 0;
}