3 ms·
I heard this referred to as a language's tendency to "keep on truckin'". Instead of causing an error by dividing by 0, JavaScript, for example, will return Inf
by justin_oaks 5y ago
I heard this referred to as a language's tendency to "keep on truckin'".
Instead of causing an error by dividing by 0, JavaScript, for example, will return Infinity which corrupts any further calculations.
It can be caused by dynamic typing but it also creeps into any language that allows implicit type conversion. Java, for example, is statically typed but allows some implicit type conversion in primitive types.
The problem is that an implicit type conversion is easy for a programmer to miss, and thus they don't realize that that the variable doesn't have the value or type they're expecting.
- pletnes 5y agoAFAIK, division by zero in IEEE 754 floating point shall return infinity, which is a valid floating point value. For once, javascript does the right thing.
- justin_oaks 5y agoFair enough. I was trying to come up with something weird that JavaScript does with numbers and I guess I chose the wrong thing.
- pletnes 5y agoJavascript is truly weird to me (I’ve programmed mostly in python and Fortran). From what I understood though, js uses IEEE 754 floating point for everything, simply because it works the same on pretty much any hardware platform. Arm, intel, power, whatever. Int/uint/… not so much. The numbers are therefore 100% sane. The insanity stems from converting «0.0» to float then guessing at how to format it (maybe «int» is what he meant?). Etc.