2%> Generate and
return the **probabilistically-rounded** to the nearest integer value of the input real number.
5%> Unlike the intrinsic Fortran `nint()` function, the procedures of
this generic
6%>
interface round the input real number to the nearest integer value **probabilistically**.<br>
7%> The closer the input `val` is to its `nint(val)` result, the more likely it will be rounded to it.<br>
8%> See below
for example usage.<br>
10%> \param[in] val : The input scalar or array of the same rank as other array-like arguments,
11%> containing the number to be rounded probabilistically.<br>
14%> `whole` : The output scalar or array of the same rank and shape as the input arguments,
15%> of
default `integer` kind, containing the **probabilistically-rounded** input value to the nearest integer.<br>
20%> whole = pm.math.pnint(val);
29%> \include{lineno} example/math/
pnint/main.m
31%> \include{lineno} example/math/
pnint/main.out.m
36%> \AmirShahmoradi, April 23, 2017, 1:36 AM, Institute
for Computational Engineering and Sciences (ICES), University of Texas at Austin
39 residual = val - whole; %
abs(residual) < .5 always holds.
40 urand = unifrnd(0, 1, size(val, 1), size(val, 2));
41 mask = 1 -
abs(residual) < urand;
42 mask1 = mask & residual < 0;
43 mask2 = mask & residual >= 0;
44 whole(mask1(:)) = whole(mask1(:)) - 1;
45 whole(mask2(:)) = whole(mask2(:)) + 1;
function abs(in path, in style)
Return the Get absolute canonical path of a file or folder.
function pnint(in val)
Generate and return the probabilistically-rounded to the nearest integer value of the input real numb...