c# - 为什么 C++ 和 C# 对 double 类型有不同的最大值的解释?

标签 c# c++ types double specifications

<分区>

在 C# 中,double 类型的最大值为:1.79769313486232E+308。

但是,在 C++ 中,double 类型的最大值为:1.79769e+308。

这意味着 C++ 程序(使用 strtod 函数)不能总是解析 C# 输出的 double 类型值。

是否有针对此行为的任何解释以及处理该问题的任何好的解决方案?

最佳答案

来自 C++ / C# differences with float and double

C++ allows the program to retain a higher precision for temporary results than the type of the subexpressions would imply. One thing that can happen is that intermediate expressions (or an unspecified subset of them) are computed as extended 80-bit floats.

更多信息 Precision and Accuracy in Floating-Point Calculations

引用 Eric Lippert

section 4.1.6 of the C# specification, which begins **Floating-point operations may be performed with higher precision than the result type of the operation. For example, some hardware architectures support an “extended” or “long double” floating-point type with greater range and precision than the double type, and implicitly perform all floating-point operations using this higher precision type. ... ** See the spec for more details.

关于c# - 为什么 C++ 和 C# 对 double 类型有不同的最大值的解释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49187441/

相关文章:

c# - 文本框两次触发 TextChanged 事件并两次回发,第一次回发状态中止

C# 多线程访问 Excel 文件

c# - Kendo UI 日期选择器与 Chrome 56 不兼容

c# - 旋转大量 Timers.Timer 线程

c++ - 按字母顺序排列的字符串

c++ - 通过访问成员传回多维数组

c++ - 这段代码中 switch/default 有什么奇怪的目的吗?

xml - 来自 F# XmlProvider 的类型检查错误 FS3033

c++ - 类型转换 C++ 的行为方式很奇怪

apache-spark - pyspark.sql.utils.AnalysisException : Parquet data source does not support void data type