Re:A Quick Introduction to R
by salamandersauce on Sunday February 06, 2022 @09:23AM
(#30232701)
Okay. But I'm storing it in a variable explicitly declared to be a double. That should be enough. If I divide two integers in python or R or Julia or a dollar store calculator I don't get an integer and I don't even have to explicitly type the variable. You have to know that C++ will do that. It's not common sense just like R recycling shorter vectors.
[ Parent
| on HN ]
I agree with your point that all languages have their quirks. This is a very poor example however. If it automatically converted to float what would you do if you wanted integer division? I think automatic casting tends to get messy/be pretty evil in general but of course there are exceptions.
Re:A Quick Introduction to R
by salamandersauce on Sunday February 06, 2022 @10:35AM
(#30233397)
You could always do something like:
int divRes = IntA/intB;
double something = divRes*5.342;
At the very least it could warn me. I just tried it in rust and that will error out if you try to divide two ints and store the result in a float which is fine by me.