寻找在例如多种编程语言类似precision的数据类型C / C ++,D,围棋 [英] Looking for datatypes of similar precision in multiple programming languages e.g. C/C++, D, Go

查看:128
本文介绍了寻找在例如多种编程语言类似precision的数据类型C / C ++,D,围棋的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现浮点数,使用两种或多种编程语言的程序。该方案不说,50k的迭代,最终带来误差非常小的。

I am trying to implement a program with floating point numbers, using two or more programming languages. The program does say 50k iterations to finally bring the error to very small value.

要确保我的结果有可比性,我想确保我用同样的precision的数据类型,在不同的语言。请您告诉我们,如果有对应的浮动D中的C / C /双++到而归。我希望C / C ++和D是相当接近在这方面,但不能肯定。非常感谢。

To ensure that my results are comparable, I wanted to make sure I use data types of same precision in different languages. Would you please tell if there is correspondence between float/double of C/C++ to that in D and Go. I expect C/C++ and D to be quite close in this regard, but not sure. Thanks a lot.

推荐答案

一般来说,对于编译语言,浮点格式和precision归结为两点:

Generally, for compiled languages, floating point format and precision comes down to two things:


  1. 用于实现不直接在硬件支持的浮点功能的库。

  2. 在系统上运行的硬件。

这也取决于你给编译器选项(以及如何复杂的编译器是一般的) - 许多现代的处理器具有矢量指令,结果可能会比你使用常规浮点指令微妙的不同(如FPU与上证所x86处理器)。您还可以看到差异,有时候,因为在x86 FPU的内部计算为80位,存储为64位完成计算的时候。

It may also depend on what compiler options you give (and how sophisticated the compiler is in general) - many modern processors have vector instructions, and the result may be subtly different than if you use "regular" floating point instructions (e.g. FPU vs. SSE on x86 processors). You may also see differences, sometimes, because the internal calculations on an x86 FPU is 80-bits, stored as 64-bits when the computation is completed.

但是总体来说,考虑到相同的硬件,以及类似类型的编译器,我期望得到同样的结果[和大致相同的性能]从两个不同的[足够相似]语言。

But generally, given the same hardware, and similar type of compilers, I'd expect to get the same result [and roughly the same performance] from two different [sufficiently similar] languages.

大多数语言要么只有双规(通常为64位)或单双(如浮动 - 通常是32位和双 - 在C通常为64位/ C ++ - 也许ð为好,但我不是为D)。

Most languages have either only "double" (typically 64-bit) or "single and double" (e.g. float - typically 32-bit and double - typically 64-bit in C/C++ - and probably D as well, but I'm not that into D).

这篇关于寻找在例如多种编程语言类似precision的数据类型C / C ++,D,围棋的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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