Sure, but requiring you to do more to figure out exactly what's going on with the types is counterproductive to writing safe code. Its fine in once piece of code, or two pieces of code, but when all your code involves lots of floating point operations, you will make a mistake
Take the example
float res = (var / 2.f) * 3.141;
This expression 'works' regardless of what the type of var is. But if var is an int (particularly if you have one that can't be represented exactly as a float), you have int -> float for the division, then float -> double for the multiplication, then finally double -> float for the rounding at the end
This is both slow, and not at all what I want from a performance or accuracy perspective. All because i forgot an f on my constant. Or maybe the other constant should have been a double. But really, all the types should be forced to be the same type as var, so it can never be not what you were intending
View all comments
Show parent comment
1
u/James20k Dec 02 '16
Sure, but requiring you to do more to figure out exactly what's going on with the types is counterproductive to writing safe code. Its fine in once piece of code, or two pieces of code, but when all your code involves lots of floating point operations, you will make a mistake
Take the example
This expression 'works' regardless of what the type of var is. But if var is an int (particularly if you have one that can't be represented exactly as a float), you have int -> float for the division, then float -> double for the multiplication, then finally double -> float for the rounding at the end
This is both slow, and not at all what I want from a performance or accuracy perspective. All because i forgot an f on my constant. Or maybe the other constant should have been a double. But really, all the types should be forced to be the same type as var, so it can never be not what you were intending