digitalmars.D.learn - Rounding Functions in Phobos
- starcanopy (14/14) Aug 02 2020 Is there a reason why ceil, floor, round, and friends return
Is there a reason why ceil, floor, round, and friends return floats instead of an integer? There are l' variants for some of these, but I'd imagine template implementations of these operations would be better. Too much bloat? Naively, you'd have for ceil... // Return type would be numeric but the concrete type will be whatever is smallest to fit the result. auto ceil(Float)(Float x) if (isFloatingPoint!Float) { ... } or... Integer ceil(Float, Integer = long)(Float x) if (isFloatingPoint!Float && isIntegral!Integer) { ... } For reals that are too big for long, I'd guess (u)cent would need an implementation.
Aug 02 2020