News for hackers. Stuff that matters.
Re:How to compare floats in Python by saurik on Wednesday March 30, 2022 @12:51PM (#30857750)
> But while going through the docs I stumbled upon this Gem

You make it sound like that's crazy or something but the goal of .compare is to be used as a "comparator" to provide an ordering of all possible values in the implementation of various data structures or sorting algorithms, while the goal of the various operators is to support programmatic logic.

Re:How to compare floats in Python by cuteboy19 on Wednesday March 30, 2022 @01:05PM (#30857917)
We need a little bit of background for this. In Java the == operator checks if two variables are pointing to the same object. The .equals() method checks for actual value equality.

  new String("Hi")==new String("Hi"); // False
  new String("Hi").equals(new String("Hi")); // True
Except for primitives like ints and floats where == does value comparison.

  1==1;// True
For NaN the value comparison is false. Even then .equals returns true

  Float.NaN==Float.NaN; // False
  new Float(0f/0f).equals(new Float(0f/0f)); // True!!!