我正在使用 attoparsec 的内置解析器“double”和“number”来解析浮点值,我从不同的解析器得到不同的结果。
>parse number "8.918605790440055e-2"
Done "" 8.918605790440054e-2
> parse double "8.918605790440055e-2"
Done "" 8.918605790440055e-2
使用“数字”解析器似乎会失去一些精度,而“双”解析器则不会。由于可以将 8.918605790440055e-2 表示为 double,因为“double”解析器设法做到了,为什么“number”解析器返回不同的结果?这是一个错误吗?
我正在使用 attoparsec 0.10.4.0。
最佳答案
Note: This function is almost ten times faster than rational. On integral inputs, it gives perfectly accurate answers, and on floating point inputs, it is slightly less accurate than
rational
.
attoparsec
默认以速度换取精度,如果您需要完全准确的解析,则必须使用较慢的 rational
解析器。结果的差异非常小,以至于对于大多数目的而言,这无关紧要,因此总体而言,更快的默认解析器可能会获得更大的胜利。
关于parsing - attoparsec 错误解析 double ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15298961/