Function
safe_division_f
(
numerator,
denominator,
/,
ndigits=10, # Changed
*,
ignore_overflow=False,
ignore_zero_division=False,
)
Source from the content-addressed store, hash-verified
| 229 | |
| 230 | print("Example 16") |
| 231 | def safe_division_f( |
| 232 | numerator, |
| 233 | denominator, |
| 234 | /, |
| 235 | ndigits=10, # Changed |
| 236 | *, |
| 237 | ignore_overflow=False, |
| 238 | ignore_zero_division=False, |
| 239 | ): |
| 240 | try: |
| 241 | fraction = numerator / denominator # Changed |
| 242 | return round(fraction, ndigits) # Changed |
| 243 | except OverflowError: |
| 244 | if ignore_overflow: |
| 245 | return 0 |
| 246 | else: |
| 247 | raise |
| 248 | except ZeroDivisionError: |
| 249 | if ignore_zero_division: |
| 250 | return float("inf") |
| 251 | else: |
| 252 | raise |
| 253 | |
| 254 | |
| 255 | print("Example 17") |
Tested by
no test coverage detected