eoRNG.h (eoRng::random): Add comment on truncation as standard way of
floating point to integer conversion.
This commit is contained in:
parent
4c89acad72
commit
28e59ff064
2 changed files with 11 additions and 4 deletions
|
|
@ -1,3 +1,8 @@
|
||||||
|
2007-08-22 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||||
|
|
||||||
|
* eoRNG.h (eoRng::random): Add comment on truncation as standard way of
|
||||||
|
floating point to integer conversion.
|
||||||
|
|
||||||
2006-12-04 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
2006-12-04 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||||
|
|
||||||
* eoRNG.h (eoRng::normal(stdev)): Revert erroneous change.
|
* eoRNG.h (eoRng::normal(stdev)): Revert erroneous change.
|
||||||
|
|
|
||||||
|
|
@ -178,10 +178,12 @@ public :
|
||||||
*/
|
*/
|
||||||
uint32_t random(uint32_t m)
|
uint32_t random(uint32_t m)
|
||||||
{
|
{
|
||||||
// Make sure we always round towards zero, in order to get the
|
// C++ Standard (4.9 Floatingintegral conversions [conv.fpint])
|
||||||
// half-open interval we want (as documented). The floor function
|
// defines floating point to integer conversion as truncation
|
||||||
// does exactly this for the (always positive) values occuring here.
|
// ("rounding towards zero"): "An rvalue of a floating point type
|
||||||
return uint32_t(floor(uniform() * double(m)));
|
// can be converted to an rvalue of an integer type. The conversion
|
||||||
|
// truncates; that is, the fractional part is discarded"
|
||||||
|
return uint32_t(uniform() * double(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Biased coin toss
|
/** Biased coin toss
|
||||||
|
|
|
||||||
Reference in a new issue