3 ms·
Now that we know floats have coarse granularity on large scale, why not reduce the scale first? float fr = (int)f; if(f-fr>=0.5f)fr+=1.0f; return fr; It works
by v-yadli 13y ago
Now that we know floats have coarse granularity on large scale, why not reduce the scale first?
float fr = (int)f;
if(f-fr>=0.5f)fr+=1.0f;
return fr;
It works for all the examples in the article.
I'm not saying that I've created a good solution. I'm saying that the author is trying to create a problem out of nowhere.
Thought it would be an article to teach people how to manually do float rounding according to a specific fp encoding scheme... :-(
- pascal_cuoq 13y agoThis is a good solution that I did not think of at the time. But it is no less expensive than the final (int)(f + 0.49999997f), to compare apples with apples (both still need to be guarded against overflow in the conversion).