-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expected behavior of math.ceil, math.floor, math.trunc, and round #143
Comments
I would like to propose another alternative that sounds more consistent to what gmpy2 is.
|
I would like to strongly advise that gmpy2 follow the Python 3 behavior and return integer types for the built-in Python math functions. I don't see a need for gmpy2 to continue to support Python 2 at this point, but if you do, you should match the behavior of the Python version that is running (option 1), unless that makes the code too complicated in which case just use Python 3 behavior everywhere (option 3) (although if the code is too complicated, that's a good sign you should drop Python 2 support). The @videlec suggestion to not implement math.ceil, etc. is a bad one. Not only would that break compatibility with existing code, but it breaks with the design of gmpy2 which is to have Python duck-typed numeric types that wrap GMP types. I don't really follow the argument as to how this would be more consistent with what gmpy2 is. |
There are no options. The Python documentation says: "If x is not a float, delegates to x.floor, which should return an Integral value." (c) Same for |
Yes the result should definitely stay as a gmpy type as long as Python allows it. |
Would this be considered a bugfix and appropriate for v2.2.2 or must it wait for v2.3.0? I personally am ok with it as a bugfix. |
For me this looks as a bugfix as well. Probably, you should create a dedicated branch for 2.2.x releases. |
Note: I am specifically discussing float/mpfr inputs.
The behavior of the
math.ceil
,math.floor
,math.trunc
, andround
changed between Python 2 and Python 3. In Python 2.x, a float was always returned. In Python 3.x,math.ceil
,math.floor
, andmath.trunc
return an integer type instead of a floating point type.round
returns an integer type if the requested numbers of digits is 0 but returns a floating point type for in the requested number of digits is either greater than 0 or less than 0.What should gmpy2 2.1 do?
The text was updated successfully, but these errors were encountered: