Mercurial > octave-nkf
comparison libinterp/corefcn/inv.cc @ 18242:36057e2411f8 stable
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 07 Jan 2014 22:06:37 -0500 |
parents | 175b392e91fe |
children | 9feb46ac6847 |
comparison
equal
deleted
inserted
replaced
18241:450f50d3eb18 | 18242:36057e2411f8 |
---|---|
211 if (nargout > 1) | 211 if (nargout > 1) |
212 retval(1) = isfloat ? octave_value (frcond) : octave_value (rcond); | 212 retval(1) = isfloat ? octave_value (frcond) : octave_value (rcond); |
213 | 213 |
214 retval(0) = result; | 214 retval(0) = result; |
215 | 215 |
216 volatile double xrcond = rcond; | 216 bool rcond_plus_one_eq_one = false; |
217 xrcond += 1.0; | 217 |
218 if (nargout < 2 && (info == -1 || xrcond == 1.0)) | 218 if (isfloat) |
219 { | |
220 volatile float xrcond = frcond; | |
221 rcond_plus_one_eq_one = xrcond + 1.0F == 1.0F; | |
222 } | |
223 else | |
224 { | |
225 volatile double xrcond = rcond; | |
226 rcond_plus_one_eq_one = xrcond + 1.0 == 1.0; | |
227 } | |
228 | |
229 if (nargout < 2 && (info == -1 || rcond_plus_one_eq_one)) | |
219 warning ("inverse: matrix singular to machine precision, rcond = %g", | 230 warning ("inverse: matrix singular to machine precision, rcond = %g", |
220 rcond); | 231 (isfloat ? frcond : rcond)); |
221 } | 232 } |
222 | 233 |
223 return retval; | 234 return retval; |
224 } | 235 } |
225 | 236 |
228 %!assert (inv (single ([1, 2; 3, 4])), single ([-2, 1; 1.5, -0.5]), sqrt (eps ("single"))) | 239 %!assert (inv (single ([1, 2; 3, 4])), single ([-2, 1; 1.5, -0.5]), sqrt (eps ("single"))) |
229 | 240 |
230 %!error inv () | 241 %!error inv () |
231 %!error inv ([1, 2; 3, 4], 2) | 242 %!error inv ([1, 2; 3, 4], 2) |
232 %!error <argument must be a square matrix> inv ([1, 2; 3, 4; 5, 6]) | 243 %!error <argument must be a square matrix> inv ([1, 2; 3, 4; 5, 6]) |
244 | |
245 %!test | |
246 %! [xinv, rcond] = inv (single ([1,2;3,4])); | |
247 %! assert (isa (xinv, 'single')); | |
248 %! assert (isa (rcond, 'single')); | |
249 | |
250 %!test | |
251 %! [xinv, rcond] = inv ([1,2;3,4]); | |
252 %! assert (isa (xinv, 'double')); | |
253 %! assert (isa (rcond, 'double')); | |
233 */ | 254 */ |
234 | 255 |
235 // FIXME: this should really be done with an alias, but | 256 // FIXME: this should really be done with an alias, but |
236 // alias_builtin() won't do the right thing if we are actually using | 257 // alias_builtin() won't do the right thing if we are actually using |
237 // dynamic linking. | 258 // dynamic linking. |