I am most likely wrong but I just did a test using both INT and Double. Double was capable of holding both whole and not whole numbers whereas INT was only capable of holding whole numbers. To my understanding Double also holds much larger numbers as well as smaller numbers. Why would I choose to use INT where I can use double? Even if I know the number will be whole like asking for x number of months in a year. Why not just use double?
Thanks for the speedy reply!
9 replies to this topic
#1
Posted 26 October 2010 - 04:33 PM
|
|
|
#2
Posted 26 October 2010 - 05:29 PM
The sizes of data types differ in different platforms, but a double should store the mantissa and exponent in 8 bytes or 64 bits which ranges +/- 1.7e +/- 308 to roughly ~15 digits signed. This is double that of a normal 4 byte or 32 bit integer which ranges -2,147,483,648 to 2,147,483,647 signed.
You should use them if you are wanting to work with decimal numbers that are double precision, or rather slightly more precise than floats, otherwise you should use an integer or float. It is sluggish to the processor opcodes otherwise, but a good compiler with optimization should change it to the appropriate data type anyway.
You should use them if you are wanting to work with decimal numbers that are double precision, or rather slightly more precise than floats, otherwise you should use an integer or float. It is sluggish to the processor opcodes otherwise, but a good compiler with optimization should change it to the appropriate data type anyway.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 26 October 2010 - 05:36 PM
double is a floating-point type whereas int is an integer type. A floating point type is capable of holding non-integer numbers. double is just float with 64 bits rather than 32. A long double is the same thing but with 80 bits.
Programming is a journey, not a destination.
#4
Posted 26 October 2010 - 05:37 PM
DarkLordofthePenguins said:
double is a floating-point type whereas int is an integer type. A floating point type is capable of holding non-integer numbers. double is just float with 80 bits rather than 32.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#5
Posted 26 October 2010 - 05:39 PM
Nullw0rm said:
64 bits (1 for sign, 11 bits for the exponent and 52 bits for the mantissa) not 80. 80 would mess with the natural stack alignment.
Yes, I realized my mistake after I made that post and corrected it. I was thinking of long doubles, which are 80 bits. It's been a while since I did any C.
Programming is a journey, not a destination.
#6
Posted 26 October 2010 - 06:50 PM
Thanks guys! I +REPd you dark, but am unable to rep you null. I think its just lag :) I will try again in a bit ;)
#7
Posted 26 October 2010 - 06:57 PM
Something important to be aware of: int's can be used in case statements, doubles can't. Also, it is common that you will assign a double a value like 10.0, and it will fail when compared with 10, because a double's IEEE representation can't always exactly represent an integer value.
#8
Posted 26 October 2010 - 07:36 PM
Floats also can't be transmitted across a network in any portable format (except as literal strings, I think). Ints can, however.
sudo rm -rf /
#9
Posted 14 July 2011 - 10:31 AM
Following gives yet another e.g. of where doubles might be insufficient where integers are
http://forum.codecal...html#post305122
http://forum.codecal...html#post305122
Today is the first day of the rest of my life
#10
Posted 14 July 2011 - 04:40 PM
Please don't respond to threads more than a month old. The people involved have moved on (I had no memory of this when I got the notification) and it pushes newer, more active threads down in the list.
Closed.
Closed.
sudo rm -rf /
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

This topic is locked
Back to top









