Thread: Floating point numbers

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    3

    Floating point numbers

    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.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571

    Re: Floating point numbers

    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.
    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:

    -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.

  3. #3
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    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;
    }
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  4. #4
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    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.
    Last edited by ripper079; 10-23-2002 at 07:52 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For the numerical recipes in C types!
    By Smattacus in forum C Programming
    Replies: 5
    Last Post: 10-28-2008, 07:57 PM
  2. Replies: 7
    Last Post: 12-02-2007, 05:55 AM
  3. floating point operators
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2003, 07:53 PM
  4. 2 questions about floating point and %
    By ams80 in forum C Programming
    Replies: 2
    Last Post: 08-14-2002, 10:55 AM
  5. Floating point faster than fixed-point
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-08-2001, 11:34 PM