3 ms·
> To you that might be obvious. The compiler can't infer what your intentions were from your code. How does the compiler know what my intentions were when I mu
by civilized 4y ago
> To you that might be obvious. The compiler can't infer what your intentions were from your code.
How does the compiler know what my intentions were when I multiplied two floats? Maybe I intended to receive a partridge in a pear tree.
Intentions are not relevant here. What's relevant is what makes sense for a multiplication operator to do.
- throwawaymaths 4y agoYes and it makes sense for a multiplication operator to support float * int or float / int. Suppose you take the average height of 10 people. Converting the 10 to a float before multiplying seems wrong because the compiler is implicitly suggesting "I am not letting you take this average until you consider the possibility of non integral human count.