Using fractions instead of floats

Nick Craig-Wood nick at craig-wood.com
Mon Oct 1 14:30:11 CEST 2007


Gabriel Genellina <gagsl-py2 at yahoo.com.ar> wrote:
>  And gmpy: http://www.aleax.it/gmpy.html

And a concrete example

  >>> from gmpy import mpq
  >>> mpq(1,3)+mpq(0.4)
  mpq(11,15)
  >>> mpq(1,3)+mpq(4,10)
  mpq(11,15)
  >>> mpq(1,3)+mpq(6,10)
  mpq(14,15)
  >>> mpq(1,3)+0.6
  mpq(14,15)
  >>> mpq(5,2)
  mpq(5,2)
  >>> mpq(1,3)*mpq(6,10)*mpq(4,10)+mpq(7,8)
  mpq(191,200)
  >>>  

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list