SHOW:
|
|
- or go back to the newest paste.
| 1 | - | #!/usr/bin/env python |
| 1 | + | #!/usr/bin/env python |
| 2 | - | |
| 2 | + | |
| 3 | - | # credit for this goes to the author |
| 3 | + | # credit for this goes to the author |
| 4 | - | # of The Python Standard Library by example |
| 4 | + | # of The Python Standard Library by example |
| 5 | - | # Jesse Noller, Python Core Developer and PSF Board Member |
| 5 | + | # Jesse Noller, Python Core Developer and PSF Board Member |
| 6 | - | # Book can be purchased on amazon, it is also |
| 6 | + | # Book can be purchased on amazon, it is also |
| 7 | - | # on the oreilly bookshelf and may be at your |
| 7 | + | # on the oreilly bookshelf and may be at your |
| 8 | - | # library. I'm only reprinting the code example |
| 8 | + | # library. I'm only reprinting the code example |
| 9 | - | # here because I'm working on this stuff as a |
| 9 | + | # here because I'm working on this stuff as a |
| 10 | - | # student of the Python Programming language. |
| 10 | + | # student of the Python Programming language. |
| 11 | - | # Thanks Jesse Noller for such a good book. |
| 11 | + | # Thanks Jesse Noller for such a good book. |
| 12 | - | |
| 12 | + | |
| 13 | - | import decimal |
| 13 | + | import decimal |
| 14 | - | |
| 14 | + | |
| 15 | - | for value in ['Infinity', 'NaN', '0']: |
| 15 | + | for value in ['Infinity', 'NaN', '0']: |
| 16 | - | print decimal.Decimal(value), decimal.Deciamal('-' + value) |
| 16 | + | print decimal.Decimal(value), decimal.Decimal('-' + value)
|
| 17 | - | |
| 17 | + | |
| 18 | - | |
| 18 | + | |
| 19 | - | # Math with infinity |
| 19 | + | # Math with infinity |
| 20 | - | print 'Infinity + 1:', (decimal.Decimal('Infinity') + 1) |
| 20 | + | print 'Infinity + 1:', (decimal.Decimal('Infinity') + 1)
|
| 21 | - | print '-Infinity + 1:', (decimal.Decimal('-Infinity') + 1) |
| 21 | + | print '-Infinity + 1:', (decimal.Decimal('-Infinity') + 1)
|
| 22 | - | |
| 22 | + | |
| 23 | - | # Print comparing NaN |
| 23 | + | # Print comparing NaN |
| 24 | - | print decimal.Decimal('NaN') == decimal.Decimal('Infinity') |
| 24 | + | print decimal.Decimal('NaN') == decimal.Decimal('Infinity')
|
| 25 | print decimal.Decimal('NaN') != decimal.Decimal(1) |