Ian Lance Taylor wrote:
One way to write this expression in a fully defined manner is:
(((((T)1 << 30) - 1) << 1) + 1)
Thanks Ian.
Therefore, I'd like to apply to mainline the below (finishing testing on
x86-linux), can you check it?
Thanks in advance,
Paolo.
/////////////
2007-01-15 Ian Lance Taylor <[EMAIL PROTECTED]>
Paolo Carlini <[EMAIL PROTECTED]>
* include/ext/type_traits.h: Fix __glibcxx_max macro.
* include/std/limits: Likewise.
Index: include/ext/type_traits.h
===================================================================
--- include/ext/type_traits.h (revision 120793)
+++ include/ext/type_traits.h (working copy)
@@ -1,6 +1,6 @@
// -*- C++ -*-
-// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007 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 terms
@@ -161,7 +161,8 @@
(__glibcxx_signed(_Tp) ? (_Tp)1 << __glibcxx_digits(_Tp) : (_Tp)0)
#define __glibcxx_max(_Tp) \
- (__glibcxx_signed(_Tp) ? ((_Tp)1 << __glibcxx_digits(_Tp)) - 1 : ~(_Tp)0)
+ (__glibcxx_signed(_Tp) ? \
+ (((((_Tp)1 << (__glibcxx_digits(_Tp) - 1)) - 1) << 1) + 1) : ~(_Tp)0)
template<typename _Value>
struct __numeric_traits_integer
@@ -197,4 +198,9 @@
_GLIBCXX_END_NAMESPACE
+#undef __glibcxx_signed
+#undef __glibcxx_min
+#undef __glibcxx_max
+#undef __glibcxx_digits
+
#endif
Index: include/std/limits
===================================================================
--- include/std/limits (revision 120776)
+++ include/std/limits (working copy)
@@ -1,6 +1,6 @@
// The template and inlines for the numeric_limits classes. -*- C++ -*-
-// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -137,7 +137,8 @@
(__glibcxx_signed (T) ? (T)1 << __glibcxx_digits (T) : (T)0)
#define __glibcxx_max(T) \
- (__glibcxx_signed (T) ? ((T)1 << __glibcxx_digits (T)) - 1 : ~(T)0)
+ (__glibcxx_signed (T) ? \
+ (((((T)1 << (__glibcxx_digits (T) - 1)) - 1) << 1) + 1) : ~(T)0)
#define __glibcxx_digits(T) \
(sizeof(T) * __CHAR_BIT__ - __glibcxx_signed (T))