gpt4 book ai didi

julia - 在 Julia : Is there a way to test for equality like R's all. equal() 中?

转载 作者:行者123 更新时间:2023-12-04 19:02:26 26 4
gpt4 key购买 nike

拿这个R例子:

> x = 0.5 - 0.3
> y = 0.3 - 0.1
> x == y # although mathematically TRUE, it’s FALSE for limited precision
[1] FALSE
> all.equal(x,y) # equal up to precision of computer
[1] TRUE

引用 R 文档:

‘all.equal(x, y)’ is a utility to compare R objects ‘x’ and ‘y’ testing ‘near equality’. If they are different, comparison is still made to some extent, and a report of the differences is returned. Do not use ‘all.equal’ directly in ‘if’ expressions-either use ‘isTRUE(all.equal(....))’ or ‘identical’ if appropriate.



Julia , x == y将返回 false .有没有办法在 Julia 中检查这种相等性直至机器精度?

最佳答案

isapprox(x,y)就是你要找的。

使用 ?isapprox在 REPL 中获取更多帮助。具体来说,2 个参数指定相对误差容限和绝对误差容限。

2016年快乐

关于julia - 在 Julia : Is there a way to test for equality like R's all. equal() 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34554364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com