float_parse.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. # test parsing of floats
  2. inf = float('inf')
  3. # it shouldn't matter where the decimal point is if the exponent balances the value
  4. print(float('1234') - float('0.1234e4'))
  5. print(float('1.015625') - float('1015625e-6'))
  6. # very large integer part with a very negative exponent should cancel out
  7. print('%.4e' % float('9' * 60 + 'e-60'))
  8. print('%.4e' % float('9' * 60 + 'e-40'))
  9. # many fractional digits
  10. print(float('.' + '9' * 70))
  11. print(float('.' + '9' * 70 + 'e20'))
  12. print(float('.' + '9' * 70 + 'e-50') == float('1e-50'))
  13. # tiny fraction with large exponent
  14. print(float('.' + '0' * 60 + '1e10') == float('1e-51'))
  15. print(float('.' + '0' * 60 + '9e25') == float('9e-36'))
  16. print(float('.' + '0' * 60 + '9e40') == float('9e-21'))
  17. # ensure that accuracy is retained when value is close to a subnormal
  18. print(float('1.00000000000000000000e-37'))
  19. print(float('10.0000000000000000000e-38'))
  20. print(float('100.000000000000000000e-39'))
  21. # very large exponent literal
  22. print(float('1e4294967301'))
  23. print(float('1e-4294967301'))
  24. print(float('1e18446744073709551621'))
  25. print(float('1e-18446744073709551621'))