str.cc (2665:a124942bacb8) | str.cc (5547:747034106af4) |
---|---|
1/* 2 * Copyright (c) 2001-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 14 unchanged lines hidden (view full) --- 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Nathan Binkert 29 */ 30 | 1/* 2 * Copyright (c) 2001-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 14 unchanged lines hidden (view full) --- 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Nathan Binkert 29 */ 30 |
31#include <ctype.h> 32 | 31#include <cctype> |
33#include <cstring> 34#include <iostream> | 32#include <cstring> 33#include <iostream> |
34#include <limits> |
|
35#include <string> 36#include <vector> 37 38#include "base/intmath.hh" 39#include "base/str.hh" 40 41using namespace std; 42 --- 69 unchanged lines hidden (view full) --- 112 * value for a signed type 113 */ 114 115template <class T> 116inline bool 117__to_number(string value, T &retval) 118{ 119 static const T maxnum = ((T)-1); | 35#include <string> 36#include <vector> 37 38#include "base/intmath.hh" 39#include "base/str.hh" 40 41using namespace std; 42 --- 69 unchanged lines hidden (view full) --- 112 * value for a signed type 113 */ 114 115template <class T> 116inline bool 117__to_number(string value, T &retval) 118{ 119 static const T maxnum = ((T)-1); |
120 static const bool sign = maxnum < 0; 121 static const int bits = sizeof(T) * 8; 122 static const T hexmax = maxnum & (((T)1 << (bits - 4 - sign)) - 1); 123 static const T octmax = maxnum & (((T)1 << (bits - 3 - sign)) - 1); 124 static const T signmax = 125 (sign) ? maxnum & (((T)1 << (bits - 1)) - 1) : maxnum; | 120 static const bool sign = numeric_limits<T>::is_signed; 121 static const int bits = numeric_limits<T>::digits; 122 static const T hexmax = maxnum & (((T)1 << (bits - 4)) - 1); 123 static const T octmax = maxnum & (((T)1 << (bits - 3)) - 1); 124 static const T signmax = numeric_limits<T>::max(); |
126 static const T decmax = signmax / 10; 127 128#if 0 129 cout << "maxnum = 0x" << hex << (unsigned long long)maxnum << "\n" 130 << "sign = 0x" << hex << (unsigned long long)sign << "\n" 131 << "hexmax = 0x" << hex << (unsigned long long)hexmax << "\n" 132 << "octmax = 0x" << hex << (unsigned long long)octmax << "\n" 133 << "signmax = 0x" << hex << (unsigned long long)signmax << "\n" --- 242 unchanged lines hidden --- | 125 static const T decmax = signmax / 10; 126 127#if 0 128 cout << "maxnum = 0x" << hex << (unsigned long long)maxnum << "\n" 129 << "sign = 0x" << hex << (unsigned long long)sign << "\n" 130 << "hexmax = 0x" << hex << (unsigned long long)hexmax << "\n" 131 << "octmax = 0x" << hex << (unsigned long long)octmax << "\n" 132 << "signmax = 0x" << hex << (unsigned long long)signmax << "\n" --- 242 unchanged lines hidden --- |