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: Arun Giridhar
Subject: [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares
Date: Sat, 9 Oct 2021 12:19:29 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0

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

This is where I am now after some testing. The tricky ones are the cases near
intmin, intmax, and the unsigned cases. I think it might be better to split
signed and unsigned types separately.


  if (strcmp (op, "fix"))
    ii = (y > 0) & (x > 0) | (y < 0) & (x < 0);      ## ii == same signs for x
and y
    z(ii) = (x(ii) - mod (x(ii), y(ii))) ./ y(ii);   ## same as floor for
positive
    z(~ii) = (-x(~ii) - mod (-x(~ii), y(~ii))) ./ y(~ii);   ## opposite sign
for negative
    ## FIXME: unsigned types will break if user is mixing unsigned and
signed.
  elseif (strcmp (op, "round"))
    z = x ./ y;
  elseif (strcmp (op, "floor"))
    z = (x - mod (x, y)) ./ y;   ## FIXME: underflow near intmin?
  elseif (strcmp (op, "ceil"))
    r = mod (x, y);
    z = (x - r) ./ y;            ## FIXME: underflow near intmin?
    z(r>0) += 1;
  else
    error ('idivide: unrecognized rounding type "%s"', op);
  endif


Hopefully there's a better way to do it.

    _______________________________________________________

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]