digitalmars.D.learn - direct conversion to integral type for floor, ceil, and friends that
- Timothee Cour (15/15) May 28 2013 What's the most efficient way to convert a float/double/real to an integ...
What's the most efficient way to convert a float/double/real to an integer type with a specified rounding scheme (eg floor/ceil etc)? Is there anything besides: int x=floor(1.2); ? there's also core.stdc.math.floor{l,f,} Because these first convert to floating point representation and then then the conversion to int happens. Could we support the following instead: T floor(T,S)(S x) if (/+insert good template constraits+/) { //right now just return existing floor and convert to T but later can provide more efficient direct implementation, so user can start using it right now. } and friends, modeled after std.conv.to.
May 28 2013