➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

作者 vstinner
收信人 fredrikj, loewis, mark.dickinson, rhettinger, terry.reedy, vstinner
日期 2008-11-04.18:15:59
SpamBayes Score 2.0208565e-06
Marked as misclassified 否
Message-id <1225822560.71.0.903135284864.issue3439@psf.upfronthosting.co.za>
In-reply-to
内容
> It would be nicer if the OverflowError from _PyLong_NumBits 
> were propagated, so that the second case raises OverflowError
> instead of giving an incorrect result

Why not, but I prefer your second proposition: return a long integer. 
Attached patch implements this solution.

>>> x=1<<(2**31-1)
>>> n=x.numbits(); n, n.numbits()
(2147483648L, 32L)
>>> x<<=(2**31-1)
>>> n=x.numbits(); n, n.numbits()
(4294967295L, 32L)
>>> x<<=1
>>> n=x.numbits(); n, n.numbits()
(4294967296L, 33L) # yeah!

With my patch, there are two functions:
 - _PyLong_NumBits(long)->size_t: may overflow
 - long_numbits(long)->long: don't raise overflow error, but may raise 
other errors like memory error
历史
日期 用户 动作 参数
2008-11-04 18:16:00vstinner修改recipients: + vstinner, loewis, rhettinger, terry.reedy, mark.dickinson, fredrikj
2008-11-04 18:16:00vstinner修改messageid: <1225822560.71.0.903135284864.issue3439@psf.upfronthosting.co.za>
2008-11-04 18:15:59vstinner链接issue3439 messages
2008-11-04 18:15:59vstinner创建