Timeline for Why does Python's math.ceil return a float?
Current License: CC BY-SA 4.0
22 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 26, 2019 at 17:02 | history | edited | coredump | CC BY-SA 4.0 |
added 2 characters in body
|
May 23, 2017 at 12:40 | history | edited | CommunityBot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
Apr 12, 2017 at 7:31 | history | edited | CommunityBot |
replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
|
|
Sep 21, 2015 at 14:13 | history | edited | coredump | CC BY-SA 3.0 |
deleted 4 characters in body
|
Sep 21, 2015 at 13:40 | history | edited | coredump | CC BY-SA 3.0 |
added 13 characters in body
|
Sep 21, 2015 at 9:07 | history | edited | coredump | CC BY-SA 3.0 |
added 18 characters in body
|
Sep 9, 2015 at 8:30 | history | edited | coredump | CC BY-SA 3.0 |
deleted 1 character in body
|
Sep 9, 2015 at 7:01 | history | edited | coredump | CC BY-SA 3.0 |
added 11 characters in body
|
Sep 1, 2015 at 7:13 | history | edited | coredump | CC BY-SA 3.0 |
deleted 5 characters in body
|
Aug 31, 2015 at 21:29 | comment | added | Naftuli Kay |
"I generally do not combine the result of floor with a floating point." - Case in point: "%d" % (floor(a),) .
|
|
Aug 31, 2015 at 19:46 | comment | added | coredump | @MarkDickinson Thanks. I added a paragraph about this. | |
Aug 31, 2015 at 19:42 | history | edited | coredump | CC BY-SA 3.0 |
added 1999 characters in body
|
Aug 31, 2015 at 16:00 | comment | added | Mark Dickinson |
No, it wasn't a bug: it was a deliberate design decision (encoded in PEP 3141) to change the behaviour in Python 3. (And a misguided one, IMO: ceil : float -> float is computationally a simple and fast operation; ceil : float -> int is significantly more complicated and expensive, especially for large inputs. With the change in Python 3 there's no way to spell that simple operation, while in Python 2 it's easy to do int(ceil(x)) .)
|
|
Aug 20, 2015 at 23:29 | comment | added | dan04 |
@CodesInChaos: Python 3.4's math.ceil throws an OverflowError for infinity, or ValueError for NaN.
|
|
Aug 20, 2015 at 21:19 | history | edited | coredump | CC BY-SA 3.0 |
added 95 characters in body
|
Aug 20, 2015 at 9:34 | comment | added | robert | Seems more plausible than the accepted answer ... | |
Aug 20, 2015 at 9:07 | history | edited | coredump | CC BY-SA 3.0 |
deleted 21 characters in body
|
Aug 20, 2015 at 9:01 | history | edited | coredump | CC BY-SA 3.0 |
deleted 21 characters in body
|
Aug 20, 2015 at 8:39 | comment | added | coredump | @CodesInChaos It makes perfect sense in C to return doubles, I have no problem with that. But Python is supposed to be a higher-level language where things can be made differently. | |
Aug 20, 2015 at 8:36 | comment | added | CodesInChaos | In C you obviously need to return a double, since it has a much larger range than integers. I'd consider turning a 64 bit double into a 1000 bit integer by rounding slightly unintuitive even in a language with arbitrarily sized integers. It's be even more extreme for 80 bit floats (extended precision) or custom floats which aren't limited to measly 11 bit exponents. And how would you handle special values, like infinities and NaNs? | |
Aug 20, 2015 at 8:32 | history | edited | coredump | CC BY-SA 3.0 |
added 15 characters in body
|
Aug 20, 2015 at 8:27 | history | answered | coredump | CC BY-SA 3.0 |