2011-03-11 09:42 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/src/rtl/hbrandom.c
    ! fixed double number calculation for random values by removing
      some wrong trick with epsilon value. rand() function returns
      numbers in range [0,RAND_MAX] (inclusive) so can give RAND_MAX+1
      different results and this is the correct divisor to map rand()
      results to real range [0,1)  ( 0 <= n < 1 )
This commit is contained in:
Przemyslaw Czerpak
2011-03-11 08:42:10 +00:00
parent cdc7804bc8
commit f84b6db84b
2 changed files with 9 additions and 10 deletions

View File

@@ -16,6 +16,14 @@
The license applies to all entries newer than 2009-04-28.
*/
2011-03-11 09:42 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/src/rtl/hbrandom.c
! fixed double number calculation for random values by removing
some wrong trick with epsilon value. rand() function returns
numbers in range [0,RAND_MAX] (inclusive) so can give RAND_MAX+1
different results and this is the correct divisor to map rand()
results to real range [0,1) ( 0 <= n < 1 )
2011-03-10 19:13 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/qtcore/hbqt_init.cpp
! Fixed: one remaining warning - arguments.

View File

@@ -136,16 +136,7 @@ double hb_random_num()
}
d1 = ( double ) rand();
d2 = ( double ) RAND_MAX;
#if defined( __BORLANDC__ )
/* It seems that on Windows platform there some weirdness about EPSILON value so
that a float division using an epsilon smaller than 1e-10 may be rounded.
Must dig if it's a borland lib bug or a windows problem.
*/
d2 += 0.001;
#else
d2 += DBL_EPSILON;
#endif
d2 = ( double ) RAND_MAX + 1.0;
return d1 / d2;
}