Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16f966e

Browse files
committed
Merged revisions 70489 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r70489 | mark.dickinson | 2009-03-20 23:16:14 +0000 (Fri, 20 Mar 2009) | 4 lines Rewrite Py_ARITHMETIC_RIGHT_SHIFT so that it's valid for all signed integer types T, not just those for which "unsigned T" is legal. ........
1 parent be075b1 commit 16f966e

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Include/pyport.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,19 +361,23 @@ extern "C" {
361361
* C doesn't define whether a right-shift of a signed integer sign-extends
362362
* or zero-fills. Here a macro to force sign extension:
363363
* Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
364-
* Return I >> J, forcing sign extension.
364+
* Return I >> J, forcing sign extension. Arithmetically, return the
365+
* floor of I/2**J.
365366
* Requirements:
366-
* I is of basic signed type TYPE (char, short, int, long, or long long).
367-
* TYPE is one of char, short, int, long, or long long, although long long
368-
* must not be used except on platforms that support it.
369-
* J is an integer >= 0 and strictly less than the number of bits in TYPE
370-
* (because C doesn't define what happens for J outside that range either).
367+
* I should have signed integer type. In the terminology of C99, this can
368+
* be either one of the five standard signed integer types (signed char,
369+
* short, int, long, long long) or an extended signed integer type.
370+
* J is an integer >= 0 and strictly less than the number of bits in the
371+
* type of I (because C doesn't define what happens for J outside that
372+
* range either).
373+
* TYPE used to specify the type of I, but is now ignored. It's been left
374+
* in for backwards compatibility with versions <= 2.6 or 3.0.
371375
* Caution:
372376
* I may be evaluated more than once.
373377
*/
374378
#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
375379
#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
376-
((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J))
380+
((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
377381
#else
378382
#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
379383
#endif

0 commit comments

Comments
 (0)