On Thu, Oct 14, 2021 at 11:52:11AM +1300, Greg Ewing wrote: > Scratch that, it seems __trunc__ also returns an int, at least > for floats. Not sure what the logic behind that is.
I'm not sure about the logic either, but it is documented as returning an Integral: "Truncates the Real x to the nearest Integral toward 0." so the option is there for third-party types to return some integral type apart from int. For the stdlib, the only Integral type we have is int. So I think we have the following intended behaviour. * Round a numeric (Real) value to an Integral value: - round to nearest (ties to even): __round__ - round down (towards negative infinity): __floor__ - round up (towards positive infinity): __ceil__ - round towards zero: __trunc__ * Convert a numeric Integral value to an actual int: (intended for indexing of sequences): __index__ * Convert any arbitrary value to an actual int: __int__ Does that seem right? -- Steve _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/TFKQPKGUU3G2HI5AVIFFKSULU3YCLLRY/ Code of Conduct: http://python.org/psf/codeofconduct/