Hacker News new | ask | show | jobs
by consp 847 days ago
because it's a float and not an int, it's strictly talking about integers here, not floats. All int conversions of floats are converted by discarding the remainder afaik but I could be wrong here (e.g. int(1.9) == 1, and int(-1.9) == -1)

edit: -3//2 == -2 for instance, since it's strictly integer division

1 comments

It's a valid criticism: By the principle of least surprise, one should strive for a//b = int(a/b).

Basically, there's no free lunch. Personally, I prefer truncating integer division in combination with a pair of remainder operators.

Inspired by Monty Python, the surprises are part of the charm. ¯\_(ツ)_/¯