direct conversion to integral type for floor, ceil, and friends that return integer as real

Timothee Cour thelastmammoth at gmail.com
Tue May 28 14:52:49 PDT 2013


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130528/b122b7aa/attachment.html>


More information about the Digitalmars-d-learn mailing list