I am creating a physics engine that needs a way to simulate immoveable objects, such as an object with infinite mass. I could use math.inf for this, and I have been, but then I would like some special features of it: inf / inf = 1
, inf * 0 = 0
, inf + -inf = 0
and inf - inf = 0
. I thought of creating my own "Infinity" class, but then it would be very long for just a simple thing.
I then wondered if I could override some of the dunderscore methods (or "magic methods"), so that I could use the four equations above. I could just use isinf to check if they are infinity, but then it would be quite annoying to use. Is it possible to inherit from float or something to create my own infinity class?
EDIT: I know how to subclass from float, so now what do I need to override to completely use the equations?