From bug-octave-request at bevo dot che dot wisc dot edu Sat Dec 9 23:57:39 2000 Subject: Unidentified subject! From: "John W. Eaton" To: "emil at gollum dot fri dot uni-lj dot si" cc: help-octave at bevo dot che dot wisc dot edu, bug-octave@bevo.che.wisc.edu, octave-mantainers@bevo.che.wisc.edu Date: Sat, 9 Dec 2000 23:57:30 -0600 On 17-May-2000, I wrote: | | On 17-May-2000, emil at gollum dot fri dot uni-lj dot si wrote: | | | Hello! | | | | What is the MAIN reason that 1.8:0.05:1.9 produces [1.8000 1.8500] | | and not [1.8000 1.8500 1.9000]? | | I am using 2.0.14 version of Octave. | | Thank you for your answer. | | Best regards, | | Emil Zagar | | I'd guess that the MAIN reason is that there is a bug in the way | Octave is trying (very hard) to compute the correct number of elements | for ranges. If you're in a debugging mood, the code to look at is in | the Range::nelem_internal and related functions in liboctave/Range.cc. Here is a patch (against the 2.1.x sources, but it should be obvious how to apply it to the older sources as well) that should fix this problem. With it, here is what I see: GNU Octave, version 2.1.32 (i686-pc-linux-gnu). Copyright (C) 1996, 1997, 1998, 1999, 2000 John W. Eaton. This is free software with ABSOLUTELY NO WARRANTY. For details, type `warranty'. octave:1> 1.8:0.05:1.9 ans = 1.8000 1.8500 1.9000 octave:2> 1.0008:0.00005:1.0009 ans = 1.0008 1.0009 1.0009 It is a more than a little bit embarrassing to me that this bug has been in Octave for so long. Thanks, jwe 2000-12-09 John W. Eaton * Range.cc (Range::nelem_internal): Call round here, not tfloor. Rename n_intervals to be n_elt. Index: Range.cc =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/Range.cc,v retrieving revision 1.24 diff -u -r1.24 Range.cc --- Range.cc 2000/02/01 10:06:59 1.24 +++ Range.cc 2000/12/10 05:44:16 at @ -235,11 +235,11 @@ { double ct = 3.0 * DBL_EPSILON; - double tmp = tfloor ((rng_limit - rng_base + rng_inc) / rng_inc, ct); + double tmp = round ((rng_limit - rng_base + rng_inc) / rng_inc, ct); - int n_intervals = (tmp > 0.0 ? static_cast (tmp) : 0); + int n_elt = (tmp > 0.0 ? static_cast (tmp) : 0); - return (n_intervals >= INT_MAX - 1) ? -1 : n_intervals; + return (n_elt >= INT_MAX - 1) ? -1 : n_elt; } /* ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------