C ++和C#中的精度 [英] Precision in C++ and in C#

查看:74
本文介绍了C ++和C#中的精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这不是一个新主题,但由于C ++和C#之间的精度不同,我确实遇到了一些麻烦。

I think this is not a new subject, but I have really some troubles due to a difference of Precision between C++ and C#.

1)我在C ++中的程序效果很好,但是当我用C#翻译它时变量的差异 是 

1) My program in C++ works well, but then, when I have translated it in C#  the difference in a variable  is 

这给我带来了很多问题。

That creates me a lot of problems.

有没有办法将设置调整到编译器中,以便C#的精子是C ++代码?

Is there a way to adjust settings into the compiler, so that C#'s precisons is as C++ code?




推荐答案

我想是的在这种情况下,C#precision不是问题(当然取决于你使用的函数)。

I guess the C# precision is not the problem in that case (For sure depends on which functions you use).

如果你在C#中使用,例如"双"精度为15-16位(https://msdn.microsoft.com/en-us/library/678hzkk9.aspx)。

If you use in C# e.g. "double" the precision is 15-16 digits (https://msdn.microsoft.com/en-us/library/678hzkk9.aspx).

这几乎与C ++相同( IEEE 754): 

Which is nearly the same as in C++ (IEEE 754): 

8字节 ±2.23 x 10-308至±1.80 x 10308
15-18有效数字,通常是16

8 bytes ±2.23 x 10-308 to ±1.80 x 10308 15-18 significant digits, typically 16

所以至少变量的精度不是问题。

So at least the precision of the variables cannot be the problem.

请检查你的功能用来处理数字。

Please check the functions you are using to work with the numbers.

必须有错误。

问候,

David


这篇关于C ++和C#中的精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆