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.