/search.css" rel="stylesheet" type="text/css"/> /search.js">
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
The u01fixedpt conversion functions

These functions convert unsigned W-bit integers to uniformly spaced real values (float or double) between 0.0 and 1.0 with mantissas of M bits.

PLEASE THINK CAREFULLY BEFORE USING THESE FUNCTIONS. THEY MAY NOT BE WHAT YOU WANT. YOU MAY BE MUCH BETTER SERVED BY THE FUNCTIONS IN ./uniform.hpp.

These functions produce a finite number uniformly spaced values in the range from 0.0 to 1.0 with uniform probability. The price of uniform spacing is that they may not utilize the entire space of possible outputs. E.g., u01fixedpt_closed_open_32_24 will never produce a non-zero value less than 2^-24, even though such values are representable in single-precision floating point.

There are 12 functions, corresponding to the following choices:

The W=64 M=24 cases are not implemented. To obtain an M=24 float from a uint64_t, use a cast (possibly with right-shift and bitwise and) to convert some of the bits of the uint64_t to a uint32_t and then use u01fixedpt_x_y_32_float. Note that the 64-bit random integers produced by the Random123 library are random in "all the bits", so with a little extra effort you can obtain two floats this way – one from the high bits and one from the low bits of the 64-bit value.

If the output is open at one end, then the extreme value (0.0 or 1.0) will never be returned. Conversely, if the output is closed at one end, then the extreme value is a possible return value.

The values returned are as follows. All values are returned with equal frequency, except as noted in the closed_closed case:

closed_open: Let P=min(M,W) there are 2^P possible output values: {0, 1, 2, ..., 2^P-1}/2^P

open_closed: Let P=min(M,W) there are 2^P possible values: {1, 2, ..., 2^P}/2^P

open_open: Let P=min(M, W+1) there are 2^(P-1) possible values: {1, 3, 5, ..., 2^P-1}/2^P

closed_closed: Let P=min(M, W-1) there are 1+2^P possible values: {0, 1, 2, ... 2^P}/2^P The extreme values (0.0 and 1.0) are returned with half the frequency of all others.

On x86 hardware, especially on 32bit machines, the use of internal 80bit x87-style floating point may result in 'bonus' precision, which may cause closed intervals to not be really closed, i.e. the conversions below might not convert UINT{32,64}_MAX to 1.0. This sort of issue is likely to occur when storing the output of a u01fixedpt_*_32_float function in a double, though one can imagine getting extra precision artifacts when going from 64_53 as well. Other artifacts may exist on some GPU hardware. The tests in kat_u01_main.h try to expose such issues, but caveat emptor.