[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Unidentified subject!
From: |
John W. Eaton |
Subject: |
Unidentified subject! |
Date: |
Sun, 10 Dec 2000 00:01:17 -0600 |
On 17-May-2000, I wrote:
|
| On 17-May-2000, address@hidden <address@hidden> 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 <address@hidden>
* 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
@@ -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<int> (tmp) : 0);
+ int n_elt = (tmp > 0.0 ? static_cast<int> (tmp) : 0);
- return (n_intervals >= INT_MAX - 1) ? -1 : n_intervals;
+ return (n_elt >= INT_MAX - 1) ? -1 : n_elt;
}
/*