astyle formatting

[ci skip]
This commit is contained in:
Daniel Marjamäki 2014-04-15 06:32:25 +02:00
parent 4b6164087e
commit 28751c8ad0
2 changed files with 77 additions and 75 deletions

View File

@ -25,98 +25,100 @@
#include <cctype> #include <cctype>
#include <limits> #include <limits>
MathLib::biguint MathLib::toULongNumber(const std::string & str) { MathLib::biguint MathLib::toULongNumber(const std::string & str)
// hexadecimal numbers: {
if (isHex(str)) { // hexadecimal numbers:
if (str[0] == '-') { if (isHex(str)) {
biguint ret = 0; if (str[0] == '-') {
std::istringstream istr(str);
istr >> std::hex >> ret;
return ret;
} else {
unsigned long long ret = 0;
std::istringstream istr(str);
istr >> std::hex >> ret;
return (biguint)ret;
}
}
// octal numbers:
if (isOct(str)) {
biguint ret = 0; biguint ret = 0;
std::istringstream istr(str); std::istringstream istr(str);
istr >> std::oct >> ret; istr >> std::hex >> ret;
return ret; return ret;
} else {
unsigned long long ret = 0;
std::istringstream istr(str);
istr >> std::hex >> ret;
return (biguint)ret;
} }
}
// binary numbers: // octal numbers:
if (isBin(str)) { if (isOct(str)) {
biguint ret = 0;
for (std::string::size_type i = str[0] == '0'?2:3; i < str.length(); i++) {
ret <<= 1;
if (str[i] == '1')
ret |= 1;
}
/* if (str[0] == '-')
ret = -ret; */
return ret;
}
if (isFloat(str)) {
return static_cast<biguint>(std::atof(str.c_str()));
}
biguint ret = 0; biguint ret = 0;
std::istringstream istr(str); std::istringstream istr(str);
istr >> ret; istr >> std::oct >> ret;
return ret; return ret;
}
// binary numbers:
if (isBin(str)) {
biguint ret = 0;
for (std::string::size_type i = str[0] == '0'?2:3; i < str.length(); i++) {
ret <<= 1;
if (str[i] == '1')
ret |= 1;
}
/* if (str[0] == '-')
ret = -ret; */
return ret;
}
if (isFloat(str)) {
return static_cast<biguint>(std::atof(str.c_str()));
}
biguint ret = 0;
std::istringstream istr(str);
istr >> ret;
return ret;
} }
MathLib::bigint MathLib::toLongNumber(const std::string & str) { MathLib::bigint MathLib::toLongNumber(const std::string & str)
// hexadecimal numbers: {
if (isHex(str)) { // hexadecimal numbers:
if (str[0] == '-') { if (isHex(str)) {
bigint ret = 0; if (str[0] == '-') {
std::istringstream istr(str);
istr >> std::hex >> ret;
return ret;
} else {
unsigned long long ret = 0;
std::istringstream istr(str);
istr >> std::hex >> ret;
return (bigint)ret;
}
}
// octal numbers:
if (isOct(str)) {
bigint ret = 0; bigint ret = 0;
std::istringstream istr(str); std::istringstream istr(str);
istr >> std::oct >> ret; istr >> std::hex >> ret;
return ret; return ret;
} else {
unsigned long long ret = 0;
std::istringstream istr(str);
istr >> std::hex >> ret;
return (bigint)ret;
} }
}
// binary numbers: // octal numbers:
if (isBin(str)) { if (isOct(str)) {
bigint ret = 0;
for (std::string::size_type i = str[0] == '0'?2:3; i < str.length(); i++) {
ret <<= 1;
if (str[i] == '1')
ret |= 1;
}
if (str[0] == '-')
ret = -ret;
return ret;
}
if (isFloat(str)) {
return static_cast<bigint>(std::atof(str.c_str()));
}
bigint ret = 0; bigint ret = 0;
std::istringstream istr(str); std::istringstream istr(str);
istr >> ret; istr >> std::oct >> ret;
return ret; return ret;
}
// binary numbers:
if (isBin(str)) {
bigint ret = 0;
for (std::string::size_type i = str[0] == '0'?2:3; i < str.length(); i++) {
ret <<= 1;
if (str[i] == '1')
ret |= 1;
}
if (str[0] == '-')
ret = -ret;
return ret;
}
if (isFloat(str)) {
return static_cast<bigint>(std::atof(str.c_str()));
}
bigint ret = 0;
std::istringstream istr(str);
istr >> ret;
return ret;
} }