我有一个客户端库,我在其中对我的休息服务进行http远程调用,然后我返回List<DataResponse>给调用我们的库的客户,我从REST服务获取响应以及任何错误,如果有任何包装DataResponse对象周围.
public class DataResponse {
private final String response;
private final boolean isLink;
private final TypeOfId idType;
private final long ctime;
private final long lmd;
private final String maskInfo;
// below are for error stuff
private final ErrorCode error;
private final StatusCode status;
// constructors and getters here
}
Run Code Online (Sandbox Code Playgroud)
这是我的ErrorCode枚举类:
public enum ErrorCode {
// enum values
private final int code;
private final String status;
private final String description;
// constructors and getters
} …Run Code Online (Sandbox Code Playgroud) 这是我试过的:
public class LongToDoubleTest{
public static void main(String... args) {
System.out.println(Long.MAX_VALUE);
System.out.println(Long.MAX_VALUE/2);
System.out.println(Math.floor(Long.MAX_VALUE/2));
System.out.println(new Double(Math.floor(Long.MAX_VALUE/2)).longValue());
}
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
9223372036854775807
4611686018427387903
4.6116860184273879E18
4611686018427387904
Run Code Online (Sandbox Code Playgroud)
我最初想弄清楚,是否有可能将Long.MAX_VALUE的一半保持在双倍而不会丢失数据,所以我对所有这些行进行了测试,除了最后一行.所以看来我是对的,最后一次3失踪了.然后,为了澄清它,我添加了最后一行.并没有3出现但是4.所以我的问题是,从那些4出现的地方以及它为什么4而不是3.因为4这里实际上是一个不正确的值.PS我的知识很差IEEE 754,所以我发现的行为绝对是正确的,但这4显然是错误的价值.