isapprox is misleading near floatmin(BigFloat)
bugmathsbignums
Because `BigFloat` doesn't have subnormal values (thanks MPFR!), subtraction behaves weirdly near `floatmin(BigFloat)`, and this breaks `isapprox`:
```jl
julia> x = floatmin(BigFloat)
8.50969131174083613912978790962048280567755996982969624908264897850135431080301e-1388255822130839284
julia> 1.5x
1.276453696761125420869468186443072420851633995474454437362397346775203146620452e-1388255822130839283
julia> 1.5x - x # <--- misleading because of lack of subnormals!
0.0
julia> x ≈ 1.5x # seems false! (default rtol ≈ 4.2e-39)
true
```
whereas I would expect the last line to return `false`.
One solution would be to replace `norm(x - y) <= rtol * max(norm(x), norm(y))` with `norm(x*s - y*s) <= rtol * max(norm(x), norm(y)) * s` for some appropriate scale factor `s`, e.g. `floatmax`, when the values are close to `floatmin`.
Getting all of the corner cases right is a pain, though, especially if we don't want to slow down the common cases where scaling isn't needed.
Maybe only crazy people work near `floatmin(BigFloat)`, since this is $\approx 10^{-1388255822130839283}$ regardless of the precision, so we shouldn't worry about this.
2 条评论