>>> round(2.0) 2.0 >>> round(2.5) 3.0
(x, d=0)
| 224 | |
| 225 | # Reference: http://python3porting.com/differences.html |
| 226 | def round(x, d=0): |
| 227 | """ |
| 228 | >>> round(2.0) |
| 229 | 2.0 |
| 230 | >>> round(2.5) |
| 231 | 3.0 |
| 232 | """ |
| 233 | |
| 234 | p = 10 ** d |
| 235 | if x > 0: |
| 236 | return float(math.floor((x * p) + 0.5)) / p |
| 237 | else: |
| 238 | return float(math.ceil((x * p) - 0.5)) / p |
| 239 | |
| 240 | # Reference: https://code.activestate.com/recipes/576653-convert-a-cmp-function-to-a-key-function/ |
| 241 | def cmp_to_key(mycmp): |
no outgoing calls
searching dependent graphs…