Mercurial > hg > octave-lyh
changeset 5985:5f662c1cfbbe
[project @ 2006-09-12 02:41:46 by jwe]
author | jwe |
---|---|
date | Tue, 12 Sep 2006 02:41:46 +0000 |
parents | 82a73f5dadd9 |
children | 14078139f941 |
files | src/ChangeLog src/DLD-FUNCTIONS/gcd.cc |
diffstat | 2 files changed, 13 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2006-09-11 Yozo Hida <yozo@cs.berkeley.edu> + + * DLD-FUNCTIONS/gcd.cc (Fgcd): Extend range by using std::floor + instead of converting to int. + 2006-09-05 John W. Eaton <jwe@octave.org> * mex.cc (mxArray_sparse::as_octave_value): Cast nzmax to
--- a/src/DLD-FUNCTIONS/gcd.cc +++ b/src/DLD-FUNCTIONS/gcd.cc @@ -36,7 +36,7 @@ static inline bool is_integer_value (double x) { - return x == static_cast<double> (static_cast<long> (x)); + return x == std::floor (x); } DEFUN_DLD (gcd, args, nargout, @@ -166,7 +166,7 @@ while (y(0) > 0) { - RowVector r = x - y * (static_cast<int> ( x(0) / y(0))); + RowVector r = x - y * std::floor (x(0) / y(0)); x = y; y = r; } @@ -184,9 +184,9 @@ } else if (all_args_scalar && nargout < 3) { - double g = args(0).int_value (true); + double g = args(0).double_value (); - if (error_state) + if (error_state || ! is_integer_value (g)) { error ("gcd: all arguments must be integer"); return retval; @@ -206,7 +206,7 @@ x(1) = 1; x(2) = 0; - y(0) = args(k).int_value (true); + y(0) = args(k).double_value (); y(1) = 0; y(2) = 1; @@ -214,7 +214,7 @@ y(0) = std::abs (y(0)); - if (error_state) + if (error_state || ! is_integer_value (g)) { error ("gcd: all arguments must be integer"); return retval; @@ -222,7 +222,7 @@ while (y(0) > 0) { - RowVector r = x - y * (static_cast<int> (x(0) / y(0))); + RowVector r = x - y * std::floor (x(0) / y(0)); x = y; y = r; } @@ -290,7 +290,7 @@ while (y(0) > 0) { - RowVector r = x - y * (static_cast<int> (x(0) / y(0))); + RowVector r = x - y * std::floor (x(0) / y(0)); x = y; y = r; }