473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Double - Float Problem !!!!!

Please find details of small program written by me:

( UNIX NCR MP-RAS, NCR C/C++ Complier, Double is 8 bytes (Just in case))

double j;

j = 3003486271;

printf("\n double - > %17.14E ",j);


j = 3003486271.0;

printf("\nDouble value 3003486271 with format - > %17.14E\n\n\n",j);

Ouput:


double - > -1.29148102500000E+09

Double value 3003486271 with format - > 3.00348627100000E+09

Why the first case is not showing the correct value ? Any Ideas ...
Sep 19 '06 #1
2 3173
D_C
293 100+
Here is my guess. In the first assignment, you assign an integer value, which is then converted to a double. That integer is greater than INT_MAX, so it overflows to a negative value. Then the negative integer value is converted to a double. It looks like your problem is with int not double :).
Sep 19 '06 #2
Banfa
9,065 Expert Mod 8TB
Here is my guess. In the first assignment, you assign an integer value, which is then converted to a double. That integer is greater than INT_MAX, so it overflows to a negative value. Then the negative integer value is converted to a double. It looks like your problem is with int not double :).
Nice thinking reckon you got it right, I didn't think of that :D

It is always a good idea to add a .0 to and constant that you want to be a double. If you want a float constant rather thana double constant suffix an F


12345 - Integer costant

12345.0 - double constant

12345.0F - float constant

You can do the same with L for long, U for unsigned and UL for unsigned long

12345 - int constant

12345U - unsigned constant

12345L - long constant

12345UL - unsigned long constant

I think that strictly speaking the letters should be uppercase but many compilers accept lower or upper case. Uppercase is better in the case of L because an l can be mistaken for 1 in some fonts.
Sep 20 '06 #3

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.