JuliaLang/julia — pull request #3076 by tlycken (2013-05-11 03:01:35+00:00)
Title: RFC: isapprox(n)/isequal -> base

This is to take care of `nearequal.jl` per #2422.

`isapprox` and `isapproxn` work for most standard `Number` types, including arrays of them, but there are some odd edge-cases (like `Rational{Rational{FloatingPoint}}` and other deeply nested floating types) that might behave incorrectly. I don't think they are types that anyone would ever use, though...

One way to make it easier to "cover all bases" would be to sacrifice some functionality, and not allow `isapprox` for non-floating types. Then any non-floats that are sent together with floats would be promoted, and non-floats without accompanying floats would throw errors, but all values could be treated as floats. I opted against this, because I think it is less confusing to have `isapprox` defined for all standard `Number` types.

The test suite is an attempt at covering most intended behavior, and some edge cases I could think of, but I will gladly add test cases and make sure they pass if there are cases that you think need attention.

While working on this, I thought it would be cool to have an operator that works like `isapprox`, so you can do things like

> x = 1.9999999999999; y = 2.0; x ~= y
true

This would be in line with other mathematical notation in Julia, but I find three main arguments against this specific notation:

* `~=` means "not equal" in Matlab, so this might be a source of confusion
* It is hard to define how `~=` should behave for various number types, and the behavior will not always be the same. This might be more confusing if it is "hidden" in an operator.
* This doesn't exist anywhere else, which suggests that it isn't really needed

The third point is actually an argument *for* it as well - it might become one of the many (!) cool things about Julia.