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

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

[Octave-bug-tracker] [bug #61319] idivide fails to distinguish between c


From: Markus Mützel
Subject: [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares
Date: Mon, 21 Feb 2022 14:17:54 -0500 (EST)

Follow-up Comment #14, bug #61319 (project octave):

Integer division for Octave integer types doesn't follow the same rules as in
C++ for compatibility with Matlab.

Afaict, it is implemented here:
https://hg.savannah.gnu.org/hgweb/octave/file/9a95ccd6c417/liboctave/util/oct-inttypes.h#l491

  // Division with rounding to nearest.  Note that / and % are
  // probably computed by a single instruction.

  static T div (T x, T y)
  {
    if (y != 0)
      {
        T z = x / y;
        T w = x % y;

        if (w >= y-w)
          z += 1;

        return z;
      }
    else
      return x ? octave_int_base<T>::max_val () : 0;
  }


You are right that we'll essentially need to revert that post-processing. But
afaict, there is no way to "just" call the C++ division from .m code. (Please,
correct me if that is wrong.)

It would probably be possible to unpack the underlying rep in an .oct file
function, apply the C++ integer division to that and repack into an Octave
array. But with the function call overhead, I don't know if that would be any
faster...


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?61319>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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