Checking the limits of the type long long using
std::cout << std::numeric_limits<long long>::min();
I get -9223372036854775808
However when compiling the following code:
int main() {
long long l;
l=-9223372036854775808LL;
}
I get the warnings:
test.cpp:3:7: warning: integer constant is so large that it is unsigned.
test.cpp:3: warning: this decimal constant is unsigned only in ISO C90
What am I missing? Many thanks in advance for your help.
Giorgio
This 9223372036854775808LL
is a positive number. So you need to take
std::cout << std::numeric_limits<long long>::max();
into consideration. Negating it immediately afterwards doesn't make the operand of the -
operator itself negative.
It works fine with std::numeric and boost::numeric; it gives no warnings.
#include <iostream>
#include <boost/numeric/conversion/bounds.hpp>
#include <boost/limits.hpp>
int main(int argc, char* argv[]) {
std::cout << "The minimum value for long long:\n";
std::cout << boost::numeric::bounds<long long>::lowest() << std::endl;
std::cout << std::numeric_limits<long long>::min() << std::endl << std::endl;
std::cout << "The maximum value for long long:\n";
std::cout << boost::numeric::bounds<long long>::highest() << std::endl;
std::cout << std::numeric_limits<long long>::max() << std::endl << std::endl;
std::cout << "The smallest positive value for long long:\n";
std::cout << boost::numeric::bounds<long long>::smallest() << std::endl << std::endl;
long long l;
l = boost::numeric::bounds<long long>::lowest();
std::cout << l << std::endl;
l = std::numeric_limits<long long>::min();
std::cout << l << std::endl;
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With