This is because the closest (64 bit) floatmay be the "true value" 10/3.
I use cython here (to wrap math.h nexttoward) because I don't know any built-in function for this:
%load_ext cython
%%cython
cdef extern from "<math.h>" nogil:
# A function that get the next representable float for the
# first argument in direction to the second argument.
double nexttoward(double, long double)
def next_float_toward(double i, long double j):
return nexttoward(i, j)
(or, as pointed out by @DSM, you can also use numpy.nextafter)
10/3 , :
>>> '{:.50}'.format(10/3)
3.3333333333333334813630699500208720564842224121094
>>> '{:.50}'.format(next_float_toward(10/3., 0))
3.3333333333333330372738600999582558870315551757812
>>> '{:.50}'.format(next_float_toward(10/3., 10))
3.3333333333333339254522798000834882259368896484375
, "".