3 ms·
The only thing that jumps out at me is this: if (percentage == 0) return […]; if (percentage > 0.0 && […] Can a double have a value that is la
by Freak_NL 4y ago
The only thing that jumps out at me is this:
if (percentage == 0)
return […];
if (percentage > 0.0 && […]
Can a double have a value that is larger than 0 but smaller or equal to 0.0? I would have expected '> 0' instead.
- kadoban 4y agoIn any language I can think of, 0 and 0.0 are the same, once you're comparing them against a double.
- DoingIsLearning 4y agoTechnically what is happening behind the scenes is that for most languages the compiler/interpreter will promote the integer to a double to avoid foot guns. Nevertheless integer comparisons with any kind of floating point is not a wise choice. The idiomatic way to compare a double would be to take into account whatever is the double precision epsilon for that language. Or just use the greater/less than like they have in the subsequent if statements in the original code snippet.