summaryrefslogtreecommitdiff
path: root/boost/safe_numerics/automatic.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/safe_numerics/automatic.hpp')
-rw-r--r--boost/safe_numerics/automatic.hpp134
1 files changed, 79 insertions, 55 deletions
diff --git a/boost/safe_numerics/automatic.hpp b/boost/safe_numerics/automatic.hpp
index ee19c97e0a..df63bf8d90 100644
--- a/boost/safe_numerics/automatic.hpp
+++ b/boost/safe_numerics/automatic.hpp
@@ -1,11 +1,6 @@
#ifndef BOOST_NUMERIC_AUTOMATIC_HPP
#define BOOST_NUMERIC_AUTOMATIC_HPP
-// MS compatible compilers support #pragma once
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
// Copyright (c) 2012 Robert Ramey
//
// Distributed under the Boost Software License, Version 1.0. (See
@@ -83,14 +78,17 @@ public:
constexpr static const r_interval_type r_interval = t_interval + u_interval;
+ constexpr static auto rl = r_interval.l;
+ constexpr static auto ru = r_interval.u;
+
using type = typename result_type<
temp_base_type,
- r_interval.l.exception()
+ rl.exception()
? std::numeric_limits<temp_base_type>::min()
- : static_cast<temp_base_type>(r_interval.l),
- r_interval.u.exception()
+ : static_cast<temp_base_type>(rl),
+ ru.exception()
? std::numeric_limits<temp_base_type>::max()
- : static_cast<temp_base_type>(r_interval.u)
+ : static_cast<temp_base_type>(ru)
>::type;
};
@@ -115,14 +113,17 @@ public:
constexpr static const r_interval_type r_interval = t_interval - u_interval;
+ constexpr static auto rl = r_interval.l;
+ constexpr static auto ru = r_interval.u;
+
using type = typename result_type<
temp_base_type,
- r_interval.l.exception()
+ rl.exception()
? std::numeric_limits<temp_base_type>::min()
- : static_cast<temp_base_type>(r_interval.l),
- r_interval.u.exception()
+ : static_cast<temp_base_type>(rl),
+ ru.exception()
? std::numeric_limits<temp_base_type>::max()
- : static_cast<temp_base_type>(r_interval.u)
+ : static_cast<temp_base_type>(ru)
>::type;
};
@@ -154,14 +155,17 @@ public:
constexpr static const r_interval_type r_interval = t_interval * u_interval;
+ constexpr static auto rl = r_interval.l;
+ constexpr static auto ru = r_interval.u;
+
using type = typename result_type<
temp_base_type,
- r_interval.l.exception()
+ rl.exception()
? std::numeric_limits<temp_base_type>::min()
- : static_cast<temp_base_type>(r_interval.l),
- r_interval.u.exception()
+ : static_cast<temp_base_type>(rl),
+ ru.exception()
? std::numeric_limits<temp_base_type>::max()
- : static_cast<temp_base_type>(r_interval.u)
+ : static_cast<temp_base_type>(ru)
>::type;
};
@@ -192,33 +196,36 @@ public:
};
constexpr static const r_interval_type rx(){
- if(u_interval.u < r_type(0)
- || u_interval.l > r_type(0))
- return t_interval / u_interval;
- return utility::minmax(
- std::initializer_list<r_type> {
- t_interval.l / u_interval.l,
- t_interval.l / r_type(-1),
- t_interval.l / r_type(1),
- t_interval.l / u_interval.u,
- t_interval.u / u_interval.l,
- t_interval.u / r_type(-1),
- t_interval.u / r_type(1),
- t_interval.u / u_interval.u,
- }
- );
+ if(u_interval.u < r_type(0)
+ || u_interval.l > r_type(0))
+ return t_interval / u_interval;
+ return utility::minmax(
+ std::initializer_list<r_type> {
+ t_interval.l / u_interval.l,
+ t_interval.l / r_type(-1),
+ t_interval.l / r_type(1),
+ t_interval.l / u_interval.u,
+ t_interval.u / u_interval.l,
+ t_interval.u / r_type(-1),
+ t_interval.u / r_type(1),
+ t_interval.u / u_interval.u,
+ }
+ );
}
constexpr static const r_interval_type r_interval = rx();
+ constexpr static auto rl = r_interval.l;
+ constexpr static auto ru = r_interval.u;
+
using type = typename result_type<
temp_base_type,
- r_interval.l.exception()
+ rl.exception()
? std::numeric_limits<temp_base_type>::min()
- : static_cast<temp_base_type>(r_interval.l),
- r_interval.u.exception()
+ : static_cast<temp_base_type>(rl),
+ ru.exception()
? std::numeric_limits<temp_base_type>::max()
- : static_cast<temp_base_type>(r_interval.u)
+ : static_cast<temp_base_type>(ru)
>::type;
};
@@ -268,14 +275,17 @@ public:
constexpr static const r_interval_type r_interval = rx();
+ constexpr static auto rl = r_interval.l;
+ constexpr static auto ru = r_interval.u;
+
using type = typename result_type<
temp_base_type,
- r_interval.l.exception()
+ rl.exception()
? std::numeric_limits<temp_base_type>::min()
- : static_cast<temp_base_type>(r_interval.l),
- r_interval.u.exception()
+ : static_cast<temp_base_type>(rl),
+ ru.exception()
? std::numeric_limits<temp_base_type>::max()
- : static_cast<temp_base_type>(r_interval.u)
+ : static_cast<temp_base_type>(ru)
>::type;
};
@@ -308,6 +318,8 @@ public:
checked::cast<temp_base_type>(base_value(std::numeric_limits<U>::max()))
};
+ // workaround some microsoft problem
+ #if 0
constexpr static r_type min(const r_type & t, const r_type & u){
// assert(! u.exception());
// assert(! t.exception());
@@ -319,6 +331,7 @@ public:
// assert(! t.exception());
return static_cast<bool>(t < u) ? u : t;
}
+ #endif
// union of two intervals
// note: we can't use t_interval | u_interval because it
@@ -328,22 +341,27 @@ public:
const r_interval_type & t,
const r_interval_type & u
){
- const r_type & rl = min(t.l, u.l);
- const r_type & ru = max(t.u, u.u);
- return r_interval_type(rl, ru);
+ //const r_type & rl = min(t.l, u.l);
+ const r_type & rmin = static_cast<bool>(t.l < u.l) ? t.l : u.l;
+ //const r_type & ru = max(t.u, u.u);
+ const r_type & rmax = static_cast<bool>(t.u < u.u) ? u.u : t.u;
+ return r_interval_type(rmin, rmax);
}
constexpr static const r_interval_type r_interval =
union_interval(t_interval, u_interval);
+ constexpr static auto rl = r_interval.l;
+ constexpr static auto ru = r_interval.u;
+
using type = typename result_type<
temp_base_type,
- r_interval.l.exception()
+ rl.exception()
? std::numeric_limits<temp_base_type>::min()
- : static_cast<temp_base_type>(r_interval.l),
- r_interval.u.exception()
+ : static_cast<temp_base_type>(rl),
+ ru.exception()
? std::numeric_limits<temp_base_type>::max()
- : static_cast<temp_base_type>(r_interval.u)
+ : static_cast<temp_base_type>(ru)
>::type;
};
@@ -373,14 +391,17 @@ public:
constexpr static const r_interval_type r_interval =
t_interval << u_interval;
+ constexpr static auto rl = r_interval.l;
+ constexpr static auto ru = r_interval.u;
+
using type = typename result_type<
temp_base_type,
- r_interval.l.exception()
+ rl.exception()
? std::numeric_limits<temp_base_type>::min()
- : static_cast<temp_base_type>(r_interval.l),
- r_interval.u.exception()
+ : static_cast<temp_base_type>(rl),
+ ru.exception()
? std::numeric_limits<temp_base_type>::max()
- : static_cast<temp_base_type>(r_interval.u)
+ : static_cast<temp_base_type>(ru)
>::type;
};
@@ -413,14 +434,17 @@ public:
constexpr static const r_interval_type r_interval = t_interval >> u_interval;
+ constexpr static auto rl = r_interval.l;
+ constexpr static auto ru = r_interval.u;
+
using type = typename result_type<
temp_base_type,
- r_interval.l.exception()
+ rl.exception()
? std::numeric_limits<temp_base_type>::min()
- : static_cast<temp_base_type>(r_interval.l),
- r_interval.u.exception()
+ : static_cast<temp_base_type>(rl),
+ ru.exception()
? std::numeric_limits<temp_base_type>::max()
- : static_cast<temp_base_type>(r_interval.u)
+ : static_cast<temp_base_type>(ru)
>::type;
};