octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #46859] Error in "for" cycle


From: Lachlan Andrew
Subject: [Octave-bug-tracker] [bug #46859] Error in "for" cycle
Date: Mon, 11 Jan 2016 06:52:12 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0

Follow-up Comment #7, bug #46859 (project octave):

Here is a patch to show small fractional parts of indices in the error
message, as Michael suggested.  It shows


>> a = 1:(1001/250)/(1/250);
>> b(a(end)) = 1
error: b(1001-1.13687e-13): subscripts must be either integers 1 to (2^31)-1
or logicals


It looks a little unwieldy, but I think it is clearer than hex, and certainly
less misleading than omitting the fractional part.

However, the main problem remains: given  sum(ones(1001,1))==1001, why does
the range contain a non-integer final value?  I assume the problem is in


Range::max (void) const
{
  double retval = 0.0;
  if (rng_numel > 0)
    {
      if (rng_inc > 0)
        {
          retval = rng_base + (rng_numel - 1) * rng_inc;

          // On some machines (x86 with extended precision floating point
          // arithmetic, for example) it is possible that we can overshoot
the
          // limit by approximately the machine precision even though we were
          // very careful in our calculation of the number of elements.
          // Therefore, we clip the result to the limit if it overshoots.
          // The test also includes equality (>= rng_limit) to have
expressions
          // such as -5:1:-0 result in a -0 endpoint.
          if (retval >= rng_limit)
            retval = rng_limit;


We could check for integrality of the base and step and not return a
fractional rng_limit, but that would slow things down.

My vote would be to treat the upper limit literally, and only return values up
to 1000 as Matlab does, even if that confuses some people...

(file #35984)
    _______________________________________________________

Additional Item Attachment:

File name: bug_46859_gripe.cset           Size:1 KB


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?46859>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]