简体   繁体   English

Visual C ++双重vs C ++双重

[英]Visual C++ double vs C++ double

I have ported some code from C++ to Visual C++ (this is the first time I have coded in the Visual C++ environment). 我已经将一些代码从C ++移植到了Visual C ++(这是我第一次在Visual C ++环境中进行编码)。 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. 我的几乎所有变量的数据类型都是double。

Maybe it's a dumb question, but is there any difference between a Visual C++ double and a C++ double? 也许这是一个愚蠢的问题,但是Visual C ++ double和C ++ double之间有什么区别吗? Any range differences? 有范围差异吗? I can't seem to find any Visual C++ documentation explaining its datatypes. 我似乎找不到任何解释其数据类型的Visual C ++文档。

Take a look at this: http://www.altdevblogaday.com/2012/03/22/intermediate-floating-point-precision/ 看看这个: 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). VS具有/ fp选项( http://msdn.microsoft.com/zh-cn/library/e7s85ffb.aspx ),用于指定浮点精度(类似于CUDA的fastmath)。 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 ) 最后,这些设置的行为和默认值取决于编译器( http://social.msdn.microsoft.com/Forums/vstudio/en-US/ebab293c-0c85-462e-a352-22ff8ee55c36/sqrt-code-optimization-is -vs20082010比-vs2012-sse更快-两次?论坛= vcgeneral

Visual C++ stores doubles using the IEEE 754 format. Visual C ++使用IEEE 754格式存储双精度型。 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. 对于“ C ++ double”没有特定的定义,但是如果您发现它没有使用IEEE 754,因为它是大多数CPU的本机编码,我会感到惊讶。

So no, there isn't a difference! 所以不,没有区别!

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. 它可以是精确,严格或快速的。

As far as I understand in 32-bit mode Visual Studio uses x87 and in 64-bit mode it uses at least SSE2. 据我了解,在32位模式下,Visual Studio使用x87,而在64位模式下,它至少使用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. Visual Studio的默认值是即使在64位OS上也要以32位模式进行编译,而GCC的默认值是在64位OS上要使用64位模式。 So perhaps it's just a question of 32-bit or 64-bit mode. 因此,也许这只是32位或64位模式的问题。 Try compiling your code in 64-bit mode in Visual Studio. 尝试在Visual Studio中以64位模式编译代码。 You can do that even in the Express version since MSVC 2010. 自MSVC 2010起,您甚至可以在Express版本中执行此操作。

x87 and SSE are different hardware. x87和SSE是不同的硬件。 x87 uses 80-bits for internal calculations (but only stores 64-bits) and SSE only has 64-bits. x87使用80位进行内部计算(但仅存储64位),而SSE仅具有64位。 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 Wikipedia很好地解释了为什么为x87选择80位http://en.wikipedia.org/wiki/Extended_precision#Need_for_the_80-bit_format

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM