Best way to convert and apply floor()

monarch_dodra monarchdodra at gmail.com
Sun Apr 6 02:35:31 PDT 2014


On Sunday, 6 April 2014 at 09:23:21 UTC, anonymous wrote:
> Conversion to int drops the fractional part, so you don't really
> need floor. But if you think it makes the intent clearer, feel
> free to leave it in.

Well, conversion to int "drops" the fractional part, rounding 
*towards* 0, whereas floor floor will reduce to the lower 
integral.

It can make a difference for negatives:

auto x = -3.5;
floor(x); // => -4
cast(int)x; // => -3


More information about the Digitalmars-d-learn mailing list