Advertisement
rfmonk

decimal_special2.py

Jan 22nd, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. # credit for this goes to the author
  4. # of The Python Standard Library by example
  5. # Jesse Noller, Python Core Developer and PSF Board Member
  6. # Book can be purchased on amazon, it is also
  7. # on the oreilly bookshelf and may be at your
  8. # library. I'm only reprinting the code example
  9. # here because I'm working on this stuff as a
  10. # student of the Python Programming language.
  11. # Thanks Jesse Noller for such a good book.
  12.  
  13. import decimal
  14.  
  15. for value in ['Infinity', 'NaN', '0']:
  16.     print decimal.Decimal(value), decimal.Decimal('-' + value)
  17. print
  18.  
  19. # Math with infinity
  20. print 'Infinity + 1:', (decimal.Decimal('Infinity') + 1)
  21. print '-Infinity + 1:', (decimal.Decimal('-Infinity') + 1)
  22.  
  23. # Print comparing NaN
  24. print decimal.Decimal('NaN') == decimal.Decimal('Infinity')
  25. print decimal.Decimal('NaN') != decimal.Decimal(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement