# HG changeset patch # User John W. Eaton # Date 1389150397 18000 # Node ID 36057e2411f8285e07b2666027bcbb96a8d37bef # Parent 450f50d3eb18040376ac8f8d5b33e990f92e0173 test float rcond using float arithmetic in inv function (bug #41065) * inv.cc (Finv): Test float rcond using float arithmetic. Use correct rcond in warning message. diff -r 450f50d3eb18 -r 36057e2411f8 libinterp/corefcn/inv.cc --- a/libinterp/corefcn/inv.cc Tue Jan 07 10:57:09 2014 -0500 +++ b/libinterp/corefcn/inv.cc Tue Jan 07 22:06:37 2014 -0500 @@ -213,11 +213,22 @@ retval(0) = result; - volatile double xrcond = rcond; - xrcond += 1.0; - if (nargout < 2 && (info == -1 || xrcond == 1.0)) + bool rcond_plus_one_eq_one = false; + + if (isfloat) + { + volatile float xrcond = frcond; + rcond_plus_one_eq_one = xrcond + 1.0F == 1.0F; + } + else + { + volatile double xrcond = rcond; + rcond_plus_one_eq_one = xrcond + 1.0 == 1.0; + } + + if (nargout < 2 && (info == -1 || rcond_plus_one_eq_one)) warning ("inverse: matrix singular to machine precision, rcond = %g", - rcond); + (isfloat ? frcond : rcond)); } return retval; @@ -230,6 +241,16 @@ %!error inv () %!error inv ([1, 2; 3, 4], 2) %!error inv ([1, 2; 3, 4; 5, 6]) + +%!test +%! [xinv, rcond] = inv (single ([1,2;3,4])); +%! assert (isa (xinv, 'single')); +%! assert (isa (rcond, 'single')); + +%!test +%! [xinv, rcond] = inv ([1,2;3,4]); +%! assert (isa (xinv, 'double')); +%! assert (isa (rcond, 'double')); */ // FIXME: this should really be done with an alias, but