0

A very similar question was asked 8 years ago in this post Tie breaking of round with numpy. But the chosen answer at that time doesn't actually really answer the question: the question was asking about how to customize the tiebreaker, while the answer given was actually customizing the entire behavior of rounding.

For example: both rint(1.5) and rint(2.5) will return 2 because of IEEE 754 convention, but I (and probably the original PO) want to tweak the tie-breaker such that on tie it rounds to zero i.e. rint(1.5) = 1, rint(2.5) = 2, rint(-1.5) = -1.

But following the solution in the above mentioned post and setting rounding mode to FE_TOWARDZERO with ctype will cause rint(1.6) = 1 which is not desired as it changes the entire rounding behavior of rint from round to the closet integer to round towards zero.

Dan Qiao
  • 1
  • 2

1 Answers1

0

You don't have that level of control within rint. You can have the default (banker's rounding) or the draconian choices afforded by the C rounding modes.

Python's Decimal package can give you finer control.

Prune
  • 76,765
  • 14
  • 60
  • 81
  • 1
    Decimal package can do that for a single value but doesn't work very elegantly with numpy arrays. C rounding modes is not the feature I'm looking for. I want to keep it as round to the nearest int except different tiebreaker. – Dan Qiao May 28 '21 at 20:52