|
| 1 | +from jepler_udecimal import * |
| 2 | +setcontext(ExtendedContext) |
| 3 | +print(Decimal(0)) |
| 4 | +print(Decimal('1')) |
| 5 | +print(Decimal('-.0123')) |
| 6 | +print(Decimal(123456)) |
| 7 | +print(Decimal('123.45e12345678')) |
| 8 | +print(Decimal('1.33') + Decimal('1.27')) |
| 9 | +print(Decimal('12.34') + Decimal('3.87') - Decimal('18.41')) |
| 10 | +dig = Decimal(1) |
| 11 | +print(dig / Decimal(3)) |
| 12 | +getcontext().prec = 18 |
| 13 | +print(dig / Decimal(3)) |
| 14 | +print(dig.sqrt()) |
| 15 | +print(Decimal(3).sqrt()) |
| 16 | +print(Decimal(3) ** 123) |
| 17 | +inf = Decimal(1) / Decimal(0) |
| 18 | +print(inf) |
| 19 | +neginf = Decimal(-1) / Decimal(0) |
| 20 | +print(neginf) |
| 21 | +print(neginf + inf) |
| 22 | +print(neginf * inf) |
| 23 | +try: |
| 24 | + print(dig / 0) |
| 25 | +except Exception as e: |
| 26 | + print("Division by zero") |
| 27 | +getcontext().traps[DivisionByZero] = 1 |
| 28 | +try: |
| 29 | + print(dig / 0) |
| 30 | +except Exception as e: |
| 31 | + print("Division by zero") |
| 32 | +c = Context() |
| 33 | +c.traps[InvalidOperation] = 0 |
| 34 | +print(c.flags[InvalidOperation]) |
| 35 | +try: |
| 36 | + c.divide(Decimal(0), Decimal(0)) |
| 37 | +except Exception as e: |
| 38 | + print("Division by zero") |
| 39 | +c.traps[InvalidOperation] = 1 |
| 40 | +print(c.flags[InvalidOperation]) |
| 41 | +c.flags[InvalidOperation] = 0 |
| 42 | +print(c.flags[InvalidOperation]) |
| 43 | +try: |
| 44 | + print(c.divide(Decimal(0), Decimal(0))) |
| 45 | +except Exception as e: |
| 46 | + print("Division by zero") |
| 47 | +print(c.flags[InvalidOperation]) |
| 48 | +try: |
| 49 | + print(c.divide(Decimal(0), Decimal(0))) |
| 50 | +except Exception as e: |
| 51 | + print("Division by zero") |
| 52 | +print(c.flags[InvalidOperation]) |
| 53 | +import jepler_udecimal.utrig |
| 54 | +from jepler_udecimal import Decimal |
| 55 | +print(Decimal('.7').atan()) |
| 56 | +print(Decimal('.1').acos()) |
| 57 | +print(Decimal('-.1').asin()) |
| 58 | +print(Decimal('.4').tan()) |
| 59 | +print(Decimal('.5').cos()) |
| 60 | +print(Decimal('.6').sin()) |
0 commit comments