Pav*_*ara 9 .net java floating-point
我有Java的算法/计算和单元测试.单元测试期望结果具有一定的精度/ delta.现在我将算法移植到.NET中,并希望使用相同的单元测试.我使用双数据类型.
问题是Java对Math类中的某些操作使用strictfp(64位)..NET使用FPU/CPU总是(80位)..NET更精确,更快捷.Java更具可预测性.
Because my algo is cyclic and reuses the results from previous round, the error/difference/more-precision accumulates too big. I don't rely on speed (for unit test). And I'm happy to use .NET precision in production, but I would like to validate the implementation.
Consider this from JDK
public final class Math {
public static double atan2(double y, double x) {
return StrictMath.atan2(y, x); // default impl. delegates to StrictMath
}
}
Run Code Online (Sandbox Code Playgroud)
I'm looking for library or technique to use strict FP in .NET.
Preemptive comment: I do understand IEEE 754 format and the fact that floating point number is not exact decimal number or fraction. No Decimal, no BigInt or BigNumber. Please don't answer this way, thanks.
不幸的是,在 C# 中没有办法强制执行 FP 严格性,.Net CLR 只是缺乏以低于最大精度的精度进行计算的能力。
我认为这样做可以提高性能 - 它不会检查您可能需要较低的精度。也没有必要 - .Net 不在虚拟机中运行,因此不必担心不同的浮点处理器。
然而不是strictfp可选的吗?你能在没有修饰符的情况下执行你的Java代码吗strictfp?然后它应该采用与 .Net 相同的浮点机制
因此,strictfp您可以强制 Java 不使用并检查它是否与 .Net 代码相同,而不是强制 .Net 使用strictfp并检查它是否与 Java 代码相同。