[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/
- [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares, Arun Giridhar, 2021/10/09
- [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares, Arun Giridhar, 2021/10/09
- [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares, Michael Leitner, 2021/10/09
- [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares, anonymous, 2021/10/09
- [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares, Markus Mützel, 2021/10/09
- [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares, Arun Giridhar, 2021/10/09
- [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares, Markus Mützel, 2021/10/09
- [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares,
Arun Giridhar <=
- [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares, Michael Leitner, 2021/10/09
- [Octave-bug-tracker] [bug #61319] idivide fails to distinguish between ceil and floor for inputs close to perfect squares, Markus Mützel, 2021/10/09