On 3/18/12 4:12 PM, James Miller wrote:
On 19 March 2012 08:53, Andrej Mitrovic<[email protected]> wrote:
Another classic which fails to compile is:
import std.random;
ubyte c = uniform(0, 256);
In the call uniform returns a number anywhere from 0 to and including
255, which can fit perfectly in a ubyte. But I have to use a cast
(which is error-prone if I change the right interval), or use a
to!ubyte call (which is verbose). Granted for simple-purpose random
number generation a cast might be safe..
Another thing I have noticed, is that that compared to a cast,
to!<type> is incredibly slow. Most of the time it doesn't matter, but
I was doing some work with noise generation, and found that casting
the floats to integers was an order of magnitude faster than using
to!int.
There's a check involved, and possibly inlining doesn't make it for
whatever reason.
Andrei