unifinv and colleagues with single arguments
John W. Eaton
jwe at octave.org
Tue May 5 12:44:10 CDT 2009
On 13-Mar-2009, Francesco Potorti` wrote:
| unifinv (single(0.5), 1, 3) returns a double in 3.1.54.
|
| Is this anticipated and correct?
|
| Maybe it should return a single if either of its arguments is single.
Yes, it should return a single value. Looking at unifinv, I see:
function inv = unifinv (x, a, b)
if (nargin != 1 && nargin != 3)
print_usage ();
endif
if (nargin == 1)
a = 0;
b = 1;
endif
if (!isscalar (a) || !isscalar(b))
[retval, x, a, b] = common_size (x, a, b);
if (retval > 0)
error ("uniform_cdf: x, a and b must be of common size or scalar");
endif
endif
sz = size (x);
inv = zeros (sz);
Instead, we need to initialize the return value to single if any of
the arguments are single. Something like:
if (isa (x, "single") || isa (a, "single") || isa (b, "single"))
inv = zeros (sz, "single");
else
inv = zeros (sz, "double");
endif
This kind of change will likely be needed in more than just
unifinv.m. Would someone like to take a look at all the distribution
functions and contribute a changeset?
| Is there an easy way of determining if a returned value is single? The
| only way that I have found is to assign it to a variable and use whos on it.
Try class (x).
jwe
More information about the Bug-octave
mailing list