Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Floating point does not behave in a mathematical way

It approximately does. The only common way that newbies would get tripped up is something like (3 * 1/3) != 3. Maybe that is a case for not allowing == operator to operate on floats (use a function/keyword instead), but I think that may be a step too far.



I don't think that is a step too far. When I was writing embedded code, == and != were prohibited for floating-point values. I support such a rule in general.


Years ago, I worked on software that dealt with computational geometry a lot, and I quickly found out the hard way that the equality operator is pretty much useless for floating point values.

On the other hand, that is a property of floating point numbers, regardless of what language one uses.


> On the other hand, that is a property of floating point numbers, regardless of what language one uses.

That's true, but, OTOH, having floating point rather than an exact representation be the default representation for values represented as decimal literals, and the only non-integer type supported by convenient operators is a language-specific "feature" of C that many other languages don't share. (Though, to be fair, there are also many newer and popular languages that do share both, and more just the first, of those features.)


Yeah, and integer division behaves approximately to real division, too.


Personally, I like my addition associative, but you do you.

EDIT: Also I like my numbers reflexive.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: