   Bad double accuracy
  I am having trouble getting the accuracy I think I should do with doubles. I am using visual c express on vista. Is there maybe some compiler option I'm missing? As an example, take the following code:doublea=480000000.0;doubleb=2222;doublec;c = a+b;The value of c I get is 440002208. I would expect to be getting something like 16 figure accuracy with doubles but this is nothing near that. Strangely if I switch to floats, its much better and I get 480002221. Whats going on?   
  C is set exactly correctly, to 480002222.0. If you put a breakpoint after it's set and examine its value in the debugger, you should see that.   ;  Read more carefully, would you? The OP is claiming/complaining that doubles are exhibiting less accuracy for him in this test case than floats. The inexactness floating-point arithmetic (at whatever number of bits) in general isn't particularly relevant to that.   ;  Are you doing this in a graphical application? Direct3D has a habit of setting the FPU to single-precision mode. You can use _controlfp to see whether this is the case, and to set the precision.   ;  I think thats the problem. Thanks! I added the line:  _controlfp_s(&control_word, _PC_64, _MCW_PC);and I suddenly get my accuracy back. The previous value of these bits was _PC_32.   ;  Small correction on the last post. The previous value was _PC_24. Seems like this number is the number of bits used for the mantissa.   ;Quote:Original post by Paul65Small correction on the last post. The previous value was _PC_24. Seems like this number is the number of bits used for the mantissa.Correct. _PC_53 is what corresponds to a 64-bit double, and I prefer it because it makes results more reproducible.   ;  You take a large cycle hit on some operations in float, however. You can have divisions that can take as many as 80 cycles on some system. You sound like you know what you're doing, however, and I'm sure you realize this issue :)   