在win32,win64下,float运算结果不同是什么原因

秋风之刀 2015-10-23 09:55:27
有个c++程序分别编译为32bit和64bit,分别在win7-32bit和win7-64bit上运行,该程序中存在大量的float运算,运算结果中,有一部分结果会发生差异,这是什么原因造成的?
...全文
349 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
u010231493 2015-10-23
  • 打赏
  • 举报
回复
64位也有很多种, l64、f64 32位也同样。 所以跨平台编程不会使用int long float这种模糊的类型。。size32 size 16等这种才会被使用
fefe82 2015-10-23
  • 打赏
  • 举报
回复
浮点运算是有误差的。 分别按照 32bit 和 64bit 编译的时候,有可能生成不同的指令,计算结果也可能有细微的差别。浮点运算很多的时候,这些误差有可能积累起来,导致运行结果不同。
赵4老师 2015-10-23
  • 打赏
  • 举报
回复
Collapse AllExpand All Code: All Code: Multiple Code: Visual Basic Code: C# Code: Visual C++ Code: J# Code: JScript Visual Basic C# Visual C++ J# JScript Run-Time Library Reference _set_controlfp See Also Send Feedback Sets the floating-point control word. void __cdecl _set_controlfp( unsigned int newControl, unsigned int mask ); Parameters newControl New control-word bit values. mask Mask for new control-word bits to set. Return Value None. Remarks The _set_controlfp is similar to _control87, but it only sets the floating-point control word to newControl. The bits in the values indicate the floating-point control state. The floating-point control state allows the program to change the precision, rounding, and infinity modes in the floating-point math package. You can also mask or unmask floating-point exceptions using _set_controlfp. For more information, see _control87, _controlfp, __control87_2. This function is deprecated when compiling with /clr (Common Language Runtime Compilation) or /clr:pure because the common language runtime only supports the default floating-point precision. Requirements Routine Required header Compatibility _set_controlfp <float.h> x86 processor only For more compatibility information, see Compatibility in the Introduction. See Also Concepts Floating-Point Support _clear87, _clearfp _status87, _statusfp, _statusfp2 Send feedback on this topic to Microsoft.
paschen 版主 2015-10-23
  • 打赏
  • 举报
回复
float在32位和64位下不都是4字节 你先确定你问题是由于float导致的? 另外浮点数可能有精度丢失问题,但如果代码一样,32位与64位也应该是一样的

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧