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.

Author mark.dickinson
Recipients daniel.urban, dtorp, eric.smith, loewis, mark.dickinson, rhettinger
Date 2011-05-01.17:50:53
SpamBayes Score 2.3130937e-07
Marked as misclassified No
Message-id <1304272254.43.0.149286889953.issue11967@psf.upfronthosting.co.za>
In-reply-to
Content
> The only way to do that now is t=frexp(x) and y=ldexp(t[0],t[1]+2).

What's wrong with the more direct ldexp(x, 2)?

N.B.  There *are* edge cases where Martin's suggested alternative won't work.  E.g., to compute 1e-300 * 2**1500:

>>> ldexp(1e-300, 1500)
3.507466211043404e+151

But:

>>> 1e-300 * (1 << 1500)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: long int too large to convert to float

I'm -1 on the proposal:  I recognise the need for these operations, but I think 'ldexp(x, n)' gives an adequate solution.  Fitting the functionality to the << and >> operators is awkward, because that's not what those operators do for integers (>> produces the *floor* of the quotient, and << doesn't currently accept negative arguments on the right, so there's no neat way for integers to divide by a power of 2).

See also the rejected issue 1205239.
History
Date User Action Args
2011-05-01 17:50:54mark.dickinsonsetrecipients: + mark.dickinson, loewis, rhettinger, dtorp, eric.smith, daniel.urban
2011-05-01 17:50:54mark.dickinsonsetmessageid: <1304272254.43.0.149286889953.issue11967@psf.upfronthosting.co.za>
2011-05-01 17:50:53mark.dickinsonlinkissue11967 messages
2011-05-01 17:50:53mark.dickinsoncreate