简体   繁体   English

出于测试目的,在 Java 中模拟 excel 微积分行为

[英]Emulate excel calculus behavior in Java for testing purposes

I'm implementing in Java an algorithm written with Excel formulas, based on Markov's chains, and comparing the results with Jxl library.我在 Java 中实现了一个用 Excel 公式编写的算法,基于马尔可夫链,并将结果与​​ Jxl 库进行比较。 The problem is, as I have read, that the two languages haven't the same precision.问题是,正如我所读到的,这两种语言的精度不同。 In fact, they return equal results only to the second decimal digit.事实上,它们只返回第二个十进制数字的相等结果。 Is there a method to "emulate" Excel precision in Java, to test if the algorithms behave exactly the same way?是否有一种方法可以在 Java 中“模拟”Excel 精度,以测试算法的行为方式是否完全相同?

You can find an analysis how Excel precision works here:您可以在此处找到 Excel 精度如何工作的分析:

https://community.oracle.com/thread/2053255?start=15&tstart=0 https://community.oracle.com/thread/2053255?start=15&tstart=0

It appears that the 16th decimal digit is rounded down when processing.处理时似乎将第 16 位十进制数字四舍五入。

See this question for a method to emulate the floating point precision:有关模拟浮点精度的方法,请参阅此问题:

Matching Excel's floating point in Java 在 Java 中匹配 Excel 的浮点数

I suppose that this all taken together means that internally, meaning inside the formula of a single cell, Excel is using normal doubles.我想这一切都意味着在内部,即在单个单元格的公式中,Excel 正在使用正常的双打。 But when setting the value of the cell, the 16 decimal place is rounded down.但是在设置单元格的值时,小数点后16位会四舍五入。 Which means for your algorithm that whenever there used to be an intermediate result written to a cell, you need to use the rounding method from the linked answer.这意味着对于您的算法,每当曾经将中间结果写入单元格时,您都需要使用链接答案中的舍入方法。 Test this, for me it is not clear whether these intermediate values need to be rounded or not.对此进行测试,我不清楚这些中间值是否需要四舍五入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM