在.NET转换长双NET

2023-09-06 19:23:46 作者:Mr.〢、低調

我要转换一些C code(即运行在Linux机器)到.NET,并发现了一些运营长一倍。他们不是特别行动,只是一些乘法,而有很多小数结束分歧,看来'类型,只是因为它的大小。

I have to convert some C code (that ran in a Linux machine) to .Net, and found some operations with long double. They are not special operations, just some multiplications and divisions that end with a lot of decimals, it seems the type was used just because of its size.

你会为了转换code吗?我想只是乘以值和除法回在结束时看看是否有帮助,因为code在年底反正返回短值,再加上我不知道原来的二进制文件确实使用所有尺寸长双能提供或者如果它只是使用普通的64位引擎盖下的两倍。

What would you do in order to convert the code? I'm thinking of just multiply the values and divide back at the end to see if it helps since the code is anyway returning short values at the end, plus I don't know if the original binary was indeed using all the size a long double can provide or if it was just using a common 64-bit double under the hood.

如果你不认为这是一个好主意,你知道,可用于包装和模拟长双任何类或结构的?制作一个包装在C / C ++和净称这是不可能的。

If you don't think this is a good idea, do you know of any class or structure that can be used to wrap and simulate a long double? Making a wrapper in C/C++ and call it from .Net is "not possible".

推荐答案

这是最有可能的是,C长双实际上映射到一个双等不知道更多关于计算我会假设你被罚款使用双在C#

It's most likely that the C long double actually mapped to a double and so without knowing more about the calculations I'd assume you were fine to use double in C#.

在我的经验,这是非常罕见的科学或工程计算这64位双是不够的。

In my experience it's very rare to find a scientific or engineering calculation for which 64 bit double is not sufficient.

的唯一方法是100%肯定的是,双足以将研究算法,所以这一建议是基于本能,独自体验。

The only way to be 100% certain that double is sufficient would be to study the algorithm so this advice is based on instinct and experience alone.

 
精彩推荐
图片推荐