What is the difference between `numpy.fix` and `numpy.trunc`?

Viewed 235

Aside from the additional functionality that trunc possesses as a ufunc, is there any difference between these two functions? I expected fix to be defined using trunc as is fairly common throughout NumPy, but it is actually defined using floor and ceil.

If the ufunc functionality is the only difference, why does fix exist? (Or at least, why does fix not just wrap trunc?

1 Answers

There is no difference in the results. Both functions, though implemented differently internally, produce the same results on the same set of input types and produce the same results in both value and type. There is no good reason for having both functions, particularly when one will work more slowly and/or take more resources than the other and both must be maintained for as long as numpy survives. Quite frankly, this is one problem with Python and many other design-by-committee projects, and you see debates over this trunc/fix issue in other language and library development projects like Julia.

Related