Java和C#双打之间的区别 [英] Difference between java and C# doubles

查看:53
本文介绍了Java和C#双打之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

double是一种表示Java中64位IEEE 754浮点数的类型

double is a type that represents 64-bit IEEE 754 floating-point number in Java

double是一种以C#表示IEEE 754格式的64位双精度数字的类型.

double is a type that represents 64-bit double-precision number in IEEE 754 format in C#.

两种语言都遵循相同的规范.那么为什么下面的代码有区别呢?我也检查了Mono.

Both languages follow the same specification. So why there is difference in following code? I checked Mono as well.

Double.MIN_VALUE == (Double.MIN_VALUE + 1.0); // false 

Java ideone

Console.WriteLine(Double.MinValue == (Double.MinValue + 1.0)); // true

C#ideone

推荐答案

Java的Double.MIN_VALUE2^-1074

同时

C#的Double.MinValue-1.7976931348623157E+308

它们具有不同的值,因为它们遵循不同的语义.

They have different values because they follow a different semantic.

在Java中:

一个常量,该常量持有double类型的最小正非零值

A constant holding the smallest positive nonzero value of type double

在C#中:

代表Double的最小可能值.此常数的值为负1.7976931348623157E + 308

Represents the smallest possible value of a Double [...] The value of this constant is negative 1.7976931348623157E+308

这篇关于Java和C#双打之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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