mirror of
				https://github.com/KevinMidboe/python-gpiozero.git
				synced 2025-10-29 17:50:37 +00:00 
			
		
		
		
	
							
								
								
									
										27
									
								
								gpiozero/compat.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								gpiozero/compat.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| from __future__ import ( | ||||
|     unicode_literals, | ||||
|     absolute_import, | ||||
|     print_function, | ||||
|     division, | ||||
|     ) | ||||
| str = type('') | ||||
|  | ||||
| import cmath | ||||
|  | ||||
|  | ||||
| # Back-ported from python 3.5; see | ||||
| # github.com/PythonCHB/close_pep/blob/master/is_close.py for original | ||||
| # implementation | ||||
| def isclose(a, b, rel_tol=1e-9, abs_tol=0.0): | ||||
|     if rel_tol < 0.0 or abs_tol < 0.0: | ||||
|         raise ValueError('error tolerances must be non-negative') | ||||
|     if a == b: # fast-path for exact equality | ||||
|         return True | ||||
|     if cmath.isinf(a) or cmath.isinf(b): | ||||
|         return False | ||||
|     diff = abs(b - a) | ||||
|     return ( | ||||
|         (diff <= abs(rel_tol * b)) or | ||||
|         (diff <= abs(rel_tol * a)) or | ||||
|         (diff <= abs_tol) | ||||
|         ) | ||||
		Reference in New Issue
	
	Block a user