objective c - Why does casting a large double to a long sometimes return a positive and other times return a negative value in C? -
I put it in the case of an iOS test and run it in the (32 bit iPad simulator):
Double Wow = 3166323616091.220215; NSLog (@ "Double:% F", WOW); NSLog (@ "long:% ld", (long) whu); NSLog (@ "double:% F", 3166323616091.220215); NSLog (@ "long:% ld", (long) 3166323616091.220215); Output is:
2014-04-23 13:40: 50.904 extract [53336: 303] double: 3166323616091.220215 2014-04-23 13: 40: 50.905 ext. [53336: 303] Long: -2147483648 2014-04-23 13:40: 50.906 ext. [53336: 303] Double: 3166323616091.220215 2014-04-23 13:40:40: 50.907 Execute [53336: 303] Long: 2147483647 Why do I get this to shorten the big double value in maximum value for maximum (32 bit) but when literally cut a positive Value returns variable casting negative value Gives Yon? In fact, I do not understand why the negative has returned back to everyone. Am I missing something like this with precision, perhaps?
Runtime code will result from a variable casting and the resultant overflow produces a maximum negative number (0x80000000 is an undetermined result, but what the runtime is doing). Constantly casting the compiler will change the number and it will be converted to the maximum positive number (0x7FFFFFFF).
Comments
Post a Comment