|
1 | | -from __future__ import (absolute_import, division, print_function, |
2 | | - unicode_literals) |
| 1 | +from __future__ import absolute_import |
| 2 | +from __future__ import division |
| 3 | +from __future__ import print_function |
| 4 | +from __future__ import unicode_literals |
3 | 5 |
|
| 6 | +import decimal |
| 7 | +import math |
4 | 8 | import re |
| 9 | + |
5 | 10 | import six |
6 | | -import math |
7 | | -import decimal |
8 | 11 |
|
9 | 12 |
|
10 | 13 | def to_int(input_, default=0, exception=(ValueError, TypeError), regexp=None): |
@@ -263,22 +266,23 @@ def remap(value, old_min, old_max, new_min, new_max): |
263 | 266 | >>> 0.1 + 0.1 + 0.1 |
264 | 267 | 0.30000000000000004 |
265 | 268 |
|
266 | | - If floating point remaps need to be done my suggstion is to pass at least one |
267 | | - parameter as a `decimal.Decimal`. This will ensure that the output from this |
268 | | - function is accurate. I left passing `floats` for backwards compatability and |
269 | | - there is no conversion done from float to `decimal.Decimal` unless one of the passed |
270 | | - parameters has a type of `decimal.Decimal`. This will ensure that any existing code |
271 | | - that uses this funtion will work exactly how it has in the past. |
| 269 | + If floating point remaps need to be done my suggstion is to pass at least |
| 270 | + one parameter as a `decimal.Decimal`. This will ensure that the output |
| 271 | + from this function is accurate. I left passing `floats` for backwards |
| 272 | + compatability and there is no conversion done from float to |
| 273 | + `decimal.Decimal` unless one of the passed parameters has a type of |
| 274 | + `decimal.Decimal`. This will ensure that any existing code that uses this |
| 275 | + funtion will work exactly how it has in the past. |
272 | 276 |
|
273 | 277 | Some edge cases to test |
274 | 278 | >>> remap(1, 0, 0, 1, 2) |
275 | 279 | Traceback (most recent call last): |
276 | | - ... |
| 280 | + ... |
277 | 281 | ValueError: Input range (0-0) is empty |
278 | 282 |
|
279 | 283 | >>> remap(1, 1, 2, 0, 0) |
280 | 284 | Traceback (most recent call last): |
281 | | - ... |
| 285 | + ... |
282 | 286 | ValueError: Output range (0-0) is empty |
283 | 287 |
|
284 | 288 | :param value: value to be converted |
@@ -310,19 +314,19 @@ def remap(value, old_min, old_max, new_min, new_max): |
310 | 314 | ''' |
311 | 315 |
|
312 | 316 | if ( |
313 | | - isinstance(value, decimal.Decimal) or |
314 | | - isinstance(old_min, decimal.Decimal) or |
315 | | - isinstance(old_max, decimal.Decimal) or |
316 | | - isinstance(new_min, decimal.Decimal) or |
317 | | - isinstance(new_max, decimal.Decimal) |
| 317 | + isinstance(value, decimal.Decimal) or |
| 318 | + isinstance(old_min, decimal.Decimal) or |
| 319 | + isinstance(old_max, decimal.Decimal) or |
| 320 | + isinstance(new_min, decimal.Decimal) or |
| 321 | + isinstance(new_max, decimal.Decimal) |
318 | 322 | ): |
319 | 323 | type_ = decimal.Decimal |
320 | 324 | elif ( |
321 | | - isinstance(value, float) or |
322 | | - isinstance(old_min, float) or |
323 | | - isinstance(old_max, float) or |
324 | | - isinstance(new_min, float) or |
325 | | - isinstance(new_max, float) |
| 325 | + isinstance(value, float) or |
| 326 | + isinstance(old_min, float) or |
| 327 | + isinstance(old_max, float) or |
| 328 | + isinstance(new_min, float) or |
| 329 | + isinstance(new_max, float) |
326 | 330 | ): |
327 | 331 | type_ = float |
328 | 332 |
|
|
0 commit comments