Hi there,
I'm a novice (very novice) programming student. Can you tell me what the maximum and minimum values for doubles are. Or if you cannot tell what they are, can you teach me method to figuring this out. Thank you.
Printable View
Hi there,
I'm a novice (very novice) programming student. Can you tell me what the maximum and minimum values for doubles are. Or if you cannot tell what they are, can you teach me method to figuring this out. Thank you.
Sure, its really easy to figure out on your own. A double is a 64bit number. Think about a character first ( char ). It is a series of 1's and 0's....8 to be exact. So if we have an unsigned char ( 8 bits ) we can represent 2^8 different numbers. 2^8 = 256. We count 0 so our range for unsigned char's is 0 - 255. Now when we don't specify unsigned we are dealing with signed values ( negative possibility ). So that limits us to half. We now need the MSB ( most significant bit ) to be our sign bit to tell us whether the number is negative or positive. So our range is 2^7 = 128. So our positive range is 0 - 127 ( zero based ) and our complete range is:Quote:
Originally posted by noor_mirza
Hi there,
I'm a novice (very novice) programming student. Can you tell me what the maximum and minimum values for doubles are. Or if you cannot tell what they are, can you teach me method to figuring this out. Thank you.
-128 to 127 ( signed )
0 to 255 ( unsigned )
So you could probably do it on your own to figure out what double is relatively easily. If you need more help or want to check your answer, let me know. Good luck.
The max value for a double is much more complex than for integral types (short, char, int, long) because it is likely the IEEE 7somethingsomething standard, and involves two different kinds of numbers, one sequence is for the power of the number, and the other is for base.
The numeric limits of all types are actually stored in an easy to use template. This will output the maximum value of a double on a standard compiler.
Code:#include <iostream>
#include <limits>
int main() {
std::cout << std::numeric_limits<double>::max() << std::endl;
return 0;
}
Well if you want to cheat a little you can always open limits.h or float.h. There you can check for the maximum and minimum value for both intregral and floating-point numbers.