[sage-support] Rational approximation of a number

2014-04-08 Thread Nathann Cohen
Hello everybody ! I just discovered this very nice feature : sage: QQ(1.5) 3/2 It is quite cool to get the rational associated with a float ! LP solvers often give such output. This being said, the following is... Well... :-) sage: QQ(0.3) 3/10 sage: QQ(0.33) 33/100 ... sage:

Re: [sage-support] Rational approximation of a number

2014-04-08 Thread Jeroen Demeyer
RIF can do this: sage: x = RIF(0.333) sage: x.simplest_rational() 1/3 More generally, if you know a number to a certain precision: sage: x = RIF(0.3) sage: y = x + RIF(-1,1)/1e3# Add error term sage: y.simplest_rational() 1/3 -- You received this