summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/include/std/ratio
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-02-28 16:46:23 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-02-28 16:46:23 +0000
commitc8ad0c7dd5ab9d85a00af9d711c60d7497e9cd62 (patch)
treeba6b532c4a17ae79857e84f545a7642e9b761144 /libstdc++-v3/include/std/ratio
parentcd799492f31f7ba49a8b32bc539de7c92f49679b (diff)
downloadppe42-gcc-c8ad0c7dd5ab9d85a00af9d711c60d7497e9cd62.tar.gz
ppe42-gcc-c8ad0c7dd5ab9d85a00af9d711c60d7497e9cd62.zip
2011-02-28 Paolo Carlini <paolo.carlini@oracle.com>
* testsuite/20_util/ratio/comparisons/comp3.cc: New. 2011-02-28 Marc Glisse <marc.glisse@normalesup.org> PR libstdc++/42622 * include/std/ratio (ratio_less): Reimplement to never overflow. * testsuite/20_util/ratio/comparisons/comp2.cc: Extend. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@170567 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std/ratio')
-rw-r--r--libstdc++-v3/include/std/ratio44
1 files changed, 39 insertions, 5 deletions
diff --git a/libstdc++-v3/include/std/ratio b/libstdc++-v3/include/std/ratio
index 69c0b6e14bb..2b10da7c688 100644
--- a/libstdc++-v3/include/std/ratio
+++ b/libstdc++-v3/include/std/ratio
@@ -1,6 +1,6 @@
// ratio -*- C++ -*-
-// Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -274,9 +274,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: integral_constant<bool, !ratio_equal<_R1, _R2>::value>
{ };
- template<typename _R1>
+ // 0 <= _Ri < 1
+ template<typename _R1, typename _R2>
+ struct __ratio_less_impl_2;
+
+ // _Ri > 0
+ template<typename _R1, typename _R2, intmax_t __q1 = _R1::num / _R1::den,
+ intmax_t __q2 = _R2::num / _R2::den, bool __eq = (__q1 == __q2)>
struct __ratio_less_impl_1
- : integral_constant<bool, _R1::num < _R1::den>
+ : __ratio_less_impl_2<ratio<_R1::num % _R1::den, _R1::den>,
+ ratio<_R2::num % _R2::den, _R2::den> >::type
+ { };
+
+ template<typename _R1, typename _R2, intmax_t __q1, intmax_t __q2>
+ struct __ratio_less_impl_1<_R1, _R2, __q1, __q2, false>
+ : integral_constant<bool, (__q1 < __q2) >
+ { };
+
+ template<typename _R1, typename _R2>
+ struct __ratio_less_impl_2
+ : __ratio_less_impl_1<ratio<_R2::den, _R2::num>,
+ ratio<_R1::den, _R1::num> >::type
+ { };
+
+ template<intmax_t __d1, typename _R2>
+ struct __ratio_less_impl_2<ratio<0, __d1>, _R2>
+ : integral_constant<bool, true>
+ { };
+
+ template<typename _R1, intmax_t __d2>
+ struct __ratio_less_impl_2<_R1, ratio<0, __d2> >
+ : integral_constant<bool, false>
+ { };
+
+ template<intmax_t __d1, intmax_t __d2>
+ struct __ratio_less_impl_2<ratio<0, __d1>, ratio<0, __d2> >
+ : integral_constant<bool, false>
{ };
template<typename _R1, typename _R2,
@@ -286,7 +319,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool = (__static_sign<_R1::num>::value == -1
&& __static_sign<_R2::num>::value == -1)>
struct __ratio_less_impl
- : __ratio_less_impl_1<typename ratio_divide<_R1, _R2>::type>::type
+ : __ratio_less_impl_1<_R1, _R2>::type
{ };
template<typename _R1, typename _R2>
@@ -296,7 +329,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _R1, typename _R2>
struct __ratio_less_impl<_R1, _R2, false, true>
- : __ratio_less_impl_1<typename ratio_divide<_R2, _R1>::type>::type
+ : __ratio_less_impl_1<ratio<-_R2::num, _R2::den>,
+ ratio<-_R1::num, _R1::den> >::type
{ };
/// ratio_less
OpenPOWER on IntegriCloud