Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upEquality operator fails with NaN #805
Comments
|
Hm, maybe we need to add a Though any “beginner” who knows |
|
Hi Ben,A lot of beginners (in my workshops) have heard of NaN but are not aware that NaN cannot be treated by logic operators. They think human (if x is not a number --> x == NaN).
The IDE gives warnings e.g. if a int is out of range. Maybe you could implement a warning if "Float.NaN" is found together with logic operators like == or != .
On Thursday, 30 April 2020, 12:58:01 CEST, Ben Fry <notifications@github.com> wrote:
Hm, maybe we need to add a NaN page to equality, since that's what would be seen in the console… (Not sure of a better place and also concerned that people would actually find it.) In that page we could mention testing a variable against itself if (x != x) and Float.isNan(x) as ways to test for NaN.
Though any “beginner” who knows Float.NaN probably also knows Float.isNaN() and its use. :)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
|
I'm wondering how common it is for beginners to see NaN and how it happens. I think some examples would help. It doesn't feel right to "bury" it inside the equality reference page (https://processing.org/reference/equality.html), but maybe that's right? What about NaN having it's own page? |
That would make it easy to add a "see also" reference from the equality page -- and from anywhere else needed. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Issue description
"==" operator fail with NaN confuses beginners
float result = float(s); // String s = "something wrong"
println(result); // prints NaN
if (result == Float.NaN) throw new Exception("Float error"); // does not throw exception
Proposed fix
maybe add correct syntax proposal (Float.isNaN) to language description, section Equality