mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Different shift implementation.
This commit is contained in:
		
							parent
							
								
									a38c0ff7cd
								
							
						
					
					
						commit
						f3b351f140
					
				
					 1 changed files with 34 additions and 2 deletions
				
			
		|  | @ -375,7 +375,19 @@ int_lshift(v, w) | ||||||
| 	} | 	} | ||||||
| 	a = v->ob_ival; | 	a = v->ob_ival; | ||||||
| 	b = ((intobject *)w) -> ob_ival; | 	b = ((intobject *)w) -> ob_ival; | ||||||
| 	return newintobject((unsigned long)a << b); | 	if (b < 0) { | ||||||
|  | 		err_setstr(ValueError, "negative shift count"); | ||||||
|  | 		return NULL; | ||||||
|  | 	} | ||||||
|  | 	if (a == 0 || b == 0) { | ||||||
|  | 		INCREF(v); | ||||||
|  | 		return (object *) v; | ||||||
|  | 	} | ||||||
|  | 	if (b >= 32) { | ||||||
|  | 		return newintobject(0L); | ||||||
|  | 	} | ||||||
|  | 	a = (unsigned long)a << b; | ||||||
|  | 	return newintobject(a); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static object * | static object * | ||||||
|  | @ -390,7 +402,27 @@ int_rshift(v, w) | ||||||
| 	} | 	} | ||||||
| 	a = v->ob_ival; | 	a = v->ob_ival; | ||||||
| 	b = ((intobject *)w) -> ob_ival; | 	b = ((intobject *)w) -> ob_ival; | ||||||
| 	return newintobject((unsigned long)a >> b); | 	if (b < 0) { | ||||||
|  | 		err_setstr(ValueError, "negative shift count"); | ||||||
|  | 		return NULL; | ||||||
|  | 	} | ||||||
|  | 	if (a == 0 || b == 0) { | ||||||
|  | 		INCREF(v); | ||||||
|  | 		return (object *) v; | ||||||
|  | 	} | ||||||
|  | 	if (b >= 32) { | ||||||
|  | 		if (a < 0) | ||||||
|  | 			a = -1; | ||||||
|  | 		else | ||||||
|  | 			a = 0; | ||||||
|  | 	} | ||||||
|  | 	else { | ||||||
|  | 		if (a < 0) | ||||||
|  | 			a = ~( ~(unsigned long)a >> b ); | ||||||
|  | 		else | ||||||
|  | 			a = (unsigned long)a >> b; | ||||||
|  | 	} | ||||||
|  | 	return newintobject(a); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static object * | static object * | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum