casting problems
-
Hi, I have an awefull problem with casting floats to doubles, for example: float f = 0.2f; double d = (double)f; results in d == 0.20000000232323442 or other garbage after the precision of float. I'll be glad to any ideas other than fitting the result to float precision since float precision might be change between platforms. (theoreticly speaking). thanks, BishGada. :confused:
-
Hi, I have an awefull problem with casting floats to doubles, for example: float f = 0.2f; double d = (double)f; results in d == 0.20000000232323442 or other garbage after the precision of float. I'll be glad to any ideas other than fitting the result to float precision since float precision might be change between platforms. (theoreticly speaking). thanks, BishGada. :confused:
-
Hi, I have an awefull problem with casting floats to doubles, for example: float f = 0.2f; double d = (double)f; results in d == 0.20000000232323442 or other garbage after the precision of float. I'll be glad to any ideas other than fitting the result to float precision since float precision might be change between platforms. (theoreticly speaking). thanks, BishGada. :confused:
That problem has existed on every Intell computer that I know of for the last 30 years. Its not really Intell's fault, but rather the nature of the beast. Many numbers cannot be represented exactly by floating-point math due to the way they are calculated. It has something to do with powers of 2, but I don't recall the exact calculation. Here's an article, if you can wade through it. http://www.math.grin.edu/~stone/courses/fundamentals/IEEE-reals.html