3 ms·
While implicitly converting floats to ints is bad, performing a float operation (especially multiplication or division) with an int is meaningful and should not
by throwawaymaths 4y ago
While implicitly converting floats to ints is bad, performing a float operation (especially multiplication or division) with an int is meaningful and should not be banned.
I can only have discrete buckets of things. These things have a floating point weight. What is the total weight? Forcing explicit conversion of your int to a float to do the multiplication is semantically wrong.
I could live with banning int + float or int - float.
It's almost as bad as go requiring you to convert a number to a time to figure out the integer multiple of a time interval.
- HWR_14 4y agoFloat divided by int or int divided by float is also an issue. Does 4.25 / 2 equal 2.125 or 2? Does 16 / 3.25 equal 4 or 5 or some floating point number in between?
- throwawaymaths 4y agoYou do what FIMUL does. The other options are silly.
- HWR_14 4y agoI don't understand. You want to convert everything to floats all the time? Then just start and stay in float-land and never use ints.
- ArchD 4y agoInt-to-float conversion is lossy, as my Python example demonstrates, and thus should not be automatic. Performing a float op with an int, which you said should be allowed, entails automatic int-to-float conversion before the op, does it not?
- throwawaymaths 4y agoLossy doesn't make sense as a criterion with floats. Float to float addition can be lossy. Whether there is a conversion is architecture dependent. I believe x86 has an opcode for direct multiplication.