|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r49971 - trunk/boost/units
From: steven_at_[hidden]
Date: 2008-11-27 18:35:06
Author: steven_watanabe
Date: 2008-11-27 18:35:06 EST (Thu, 27 Nov 2008)
New Revision: 49971
URL: http://svn.boost.org/trac/boost/changeset/49971
Log:
Try to fix static_rational on Borland
Text files modified:
trunk/boost/units/static_rational.hpp | 110 +++++++++++++++++++++++++++++++++++++--
1 files changed, 102 insertions(+), 8 deletions(-)
Modified: trunk/boost/units/static_rational.hpp
==============================================================================
--- trunk/boost/units/static_rational.hpp (original)
+++ trunk/boost/units/static_rational.hpp 2008-11-27 18:35:06 EST (Thu, 27 Nov 2008)
@@ -18,6 +18,7 @@
#ifdef __BORLANDC__
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/integral_c.hpp>
+#include <boost/mpl/identity.hpp>
#endif
#include <boost/units/config.hpp>
@@ -42,7 +43,7 @@
template<integer_type Value>
struct static_abs
{
- BOOST_STATIC_CONSTANT(integer_type,value) = Value < 0 ? -Value : Value;
+ BOOST_STATIC_CONSTANT(integer_type,value = Value < 0 ? -Value : Value);
};
/// Compile time rational number.
@@ -64,20 +65,28 @@
may not be floating point values, while powers and roots of rational numbers can produce floating point
values.
*/
+#ifdef __BORLANDC__
+
+template<integer_type X>
+struct make_integral_c {
+ typedef boost::mpl::integral_c<integer_type, X> type;
+};
+
template<integer_type N,integer_type D = 1>
class static_rational
{
-#ifdef __BORLANDC__
- private:
+ public:
+
+ typedef static_rational this_type;
typedef boost::mpl::integral_c<integer_type, N> N_type;
typedef boost::mpl::integral_c<integer_type, D> D_type;
- typedef boost::mpl::integral_c<integer_type,
+ typedef typename make_integral_c<
(::boost::math::static_gcd<
::boost::units::static_abs<N>::value,
::boost::units::static_abs<D>::value
- >::value)> gcd_type;
+ >::value)>::type gcd_type;
typedef typename boost::mpl::eval_if<
boost::mpl::less<
D_type,
@@ -111,7 +120,11 @@
// INTERNAL ONLY
static_rational() { }
//~static_rational() { }
+};
#else
+template<integer_type N,integer_type D = 1>
+class static_rational
+{
private:
static const integer_type nabs = static_abs<N>::value,
@@ -140,10 +153,9 @@
// INTERNAL ONLY
static_rational() { }
- //~static_rational() { }
-#endif
-
+ //~static_rational() { }
};
+#endif
}
@@ -178,6 +190,86 @@
namespace mpl {
+#ifdef __BORLANDC__
+
+template<>
+struct plus_impl<boost::units::detail::static_rational_tag, boost::units::detail::static_rational_tag>
+{
+ template<class T0, class T1>
+ struct apply {
+ typedef typename boost::units::static_rational<
+ ::boost::mpl::plus<
+ boost::mpl::times<typename T0::N_type, typename T1::D_type>,
+ boost::mpl::times<typename T1::N_type, typename T0::D_type>
+ >::value,
+ ::boost::mpl::times<typename T0::D_type, typename T1::D_type>::value
+ >::type type;
+ };
+};
+
+template<>
+struct minus_impl<boost::units::detail::static_rational_tag, boost::units::detail::static_rational_tag>
+{
+ template<class T0, class T1>
+ struct apply {
+ typedef typename boost::units::static_rational<
+ ::boost::mpl::minus<
+ boost::mpl::times<typename T0::N_type, typename T1::D_type>,
+ boost::mpl::times<typename T1::N_type, typename T0::D_type>
+ >::value,
+ ::boost::mpl::times<typename T0::D_type, typename T1::D_type>::value
+ >::type type;
+ };
+};
+
+template<>
+struct times_impl<boost::units::detail::static_rational_tag, boost::units::detail::static_rational_tag>
+{
+ template<class T0, class T1>
+ struct apply {
+ typedef typename boost::units::static_rational<
+ ::boost::mpl::times<typename T0::N_type, typename T1::N_type>::value,
+ ::boost::mpl::times<typename T0::D_type, typename T1::D_type>::value
+ >::type type;
+ };
+};
+
+template<>
+struct divides_impl<boost::units::detail::static_rational_tag, boost::units::detail::static_rational_tag>
+{
+ template<class T0, class T1>
+ struct apply {
+ typedef typename boost::units::static_rational<
+ ::boost::mpl::times<typename T0::N_type, typename T1::D_type>::value,
+ ::boost::mpl::times<typename T0::D_type, typename T1::N_type>::value
+ >::type type;
+ };
+};
+
+template<>
+struct negate_impl<boost::units::detail::static_rational_tag>
+{
+ template<class T0>
+ struct apply {
+ typedef typename boost::units::static_rational<
+ ::boost::mpl::negate<typename T0::N_type>::value,
+ ::boost::mpl::identity<T0>::type::Denominator
+ >::type type;
+ };
+};
+
+template<>
+struct less_impl<boost::units::detail::static_rational_tag, boost::units::detail::static_rational_tag>
+{
+ template<class T0, class T1>
+ struct apply
+ {
+ typedef mpl::bool_<((mpl::minus<T0, T1>::type::Numerator) < 0)> type;
+ };
+};
+
+#else
+
template<>
struct plus_impl<boost::units::detail::static_rational_tag, boost::units::detail::static_rational_tag>
{
@@ -245,6 +337,8 @@
};
};
+#endif
+
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk