diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2008-12-17 16:19:07 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2008-12-17 16:19:07 (GMT) |
commit | 54bc1ec4c7689ceab900f453fdd4c8cf5a308e59 (patch) | |
tree | 87dd2371d042f3b8e63a32a4bda589ccce0b2303 /Doc/whatsnew | |
parent | 81c93fb45c4076506a5ab3d89aeec1f42e0e6be2 (diff) | |
download | cpython-54bc1ec4c7689ceab900f453fdd4c8cf5a308e59.zip cpython-54bc1ec4c7689ceab900f453fdd4c8cf5a308e59.tar.gz cpython-54bc1ec4c7689ceab900f453fdd4c8cf5a308e59.tar.bz2 |
Forward merge of r67822 to py3k: add bit_length method to int.
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/2.7.rst | 18 | ||||
-rw-r--r-- | Doc/whatsnew/3.1.rst | 22 |
2 files changed, 39 insertions, 1 deletions
diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst index a9eb0ba..61084c8 100644 --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -66,7 +66,23 @@ Other Language Changes Some smaller changes made to the core Python language are: -* List of changes to be written here. +* The :func:`int` and :func:`long` types gained a ``bit_length`` + method that returns the number of bits necessary to represent + its argument in binary:: + + >>> n = 37 + >>> bin(37) + '0b100101' + >>> n.bit_length() + 6 + >>> n = 2**123-1 + >>> n.bit_length() + 123 + >>> (n+1).bit_length() + 124 + + (Contributed by Fredrik Johansson and Victor Stinner; :issue:`3439`.) + .. ====================================================================== diff --git a/Doc/whatsnew/3.1.rst b/Doc/whatsnew/3.1.rst index a244568..7df4d1e 100644 --- a/Doc/whatsnew/3.1.rst +++ b/Doc/whatsnew/3.1.rst @@ -66,4 +66,26 @@ This article explains the new features in Python 3.1, compared to 3.0. .. ====================================================================== +Other Language Changes +====================== + +Some smaller changes made to the core Python language are: + +* The :func:`int` type gained a ``bit_length`` method that returns the + number of bits necessary to represent its argument in binary:: + + >>> n = 37 + >>> bin(37) + '0b100101' + >>> n.bit_length() + 6 + >>> n = 2**123-1 + >>> n.bit_length() + 123 + >>> (n+1).bit_length() + 124 + + (Contributed by Fredrik Johansson and Victor Stinner; :issue:`3439`.) + + .. ====================================================================== |