Reputation: 5948
I have ported some code from C++ to Visual C++ (this is the first time I have coded in the Visual C++ environment). The code is doing a lot of math and I can see that the original code and the ported code have different results.
Almost all my variables are of datatype double.
Maybe it's a dumb question, but is there any difference between a Visual C++ double and a C++ double? Any range differences? I can't seem to find any Visual C++ documentation explaining its datatypes.
Upvotes: 1
Views: 1113
Reputation: 33669
As far as I understand in 32-bit mode Visual Studio uses x87 and in 64-bit mode it uses at least SSE2. The default for Visual Studio is to compile in 32-bit mode even on a 64-bit OS whereas the default for compiling on GCC is to use 64-bit mode on a 64-bit OS. So perhaps it's just a question of 32-bit or 64-bit mode. Try compiling your code in 64-bit mode in Visual Studio. You can do that even in the Express version since MSVC 2010.
x87 and SSE are different hardware. x87 uses 80-bits for internal calculations (but only stores 64-bits) and SSE only has 64-bits. Wikipedia has a good explanation of why 80-bits were chosen for x87 http://en.wikipedia.org/wiki/Extended_precision#Need_for_the_80-bit_format
Upvotes: 1
Reputation: 62492
Visual C++ stores doubles using the IEEE 754 format. There's no specific definition for a "C++ double", but I'd be amazed if you could find out that wasn't using IEEE 754 as it's the native encoding for most CPUs.
So no, there isn't a difference!
Upvotes: 4
Reputation: 43662
Take a look at this: http://www.altdevblogaday.com/2012/03/22/intermediate-floating-point-precision/
VS has a /fp option (http://msdn.microsoft.com/en-us/library/e7s85ffb.aspx) to specify the floating point precision (similar to fastmath for CUDA). Some of these can also prevent intrinsics; if you have conversions it may be a lot of difference..
Finally, behavior and defaults for these settings are compiler-dependent (http://social.msdn.microsoft.com/Forums/vstudio/en-US/ebab293c-0c85-462e-a352-22ff8ee55c36/sqrt-code-optimization-is-twice-faster-on-vs20082010-than-vs2012-sse?forum=vcgeneral)
Upvotes: 3
Reputation: 8824
There is no difference at first sight, but different compilers may optimize expressions differently.
Code generation options in a project properties have a floating point model setting. It can be precise, strict or fast.
Upvotes: 1