[numeric::convert] RoundNearest?
Dear All, I have just discovered Boost.NumericConvert, useful and a nice effort! However, I am missing a RoundNearest function for float to int conversions, with only RoundEven being provided. RoundEven of course does exactly what it is described to do, rounding .5 to 0 and 1.5 to 2, but i'd like the highschool (usual?) behavior of rounding up when a number exactly in the middle is provided. I can implement it myself by slightly modifying RoundEven of course, but I am wondering if I am missing something obvious or whether there is a good reason why this function is not included? Thank you very much for any thoughts! Best, Dee
Dear All,
And for a related question:
Why is promote used in the example at
http://www.boost.org/doc/libs/1_46_0/libs/type_traits/doc/html/boost_typetra...
Is it somehow advantageous to convert a double to an int if the input
type is float, or likewise to do int to double conversion when the
input type is char?
I hope someone could shed light on the benefits of this.
Thank you!
Best,
Dee
On Sun, Jul 3, 2011 at 18:21, Diederick C. Niehorster
Dear All,
I have just discovered Boost.NumericConvert, useful and a nice effort! However, I am missing a RoundNearest function for float to int conversions, with only RoundEven being provided.
RoundEven of course does exactly what it is described to do, rounding .5 to 0 and 1.5 to 2, but i'd like the highschool (usual?) behavior of rounding up when a number exactly in the middle is provided. I can implement it myself by slightly modifying RoundEven of course, but I am wondering if I am missing something obvious or whether there is a good reason why this function is not included?
Thank you very much for any thoughts!
Best, Dee
participants (1)
-
Diederick C. Niehorster