Faster uniform() in [0.0 - 1.0(

tn no at email.invalid
Mon Nov 22 08:36:27 PST 2010


tn Wrote:

> --------------------
> int      []     271
> int      [)     271
> int      (]     283
> int      ()     285
> 
> long     []     372
> long     [)     399
> long     (]     401
> long     ()     397
> 
> float    []     286
> float    [)     374
> float    (]    5252
> float    ()    5691
> 
> double   []     348
> double   [)     573
> double   (]    5319
> double   ()    5875
> 
> real     []     434
> real     [)     702
> real     (]    2832
> real     ()    3056
> --------------------
> 
> In my opinion floating point uniforms with (] or () as boundary types are unacceptably slow. I had to use 1 - uniform!"[)"(0.0, 1.0) instead of uniform!"(]"(0.0, 1.0) because of this issue. I would also expect versions using float and double to be faster than the version using real.

After further investigation it seems that the slowdown happens because of subnormal numbers in calculations. If there is an open boundary at zero then the call of nextafter in uniform returns a subnormal number. Perhaps next normal number could be used instead?


More information about the Digitalmars-d mailing list