Hi, On Wed, Mar 29, 2017 at 08:00:14AM -0700, Dima Pasechnik wrote: > > > On Wednesday, March 29, 2017 at 2:23:14 PM UTC+1, Jeroen Demeyer wrote: > > > > On 2017-03-29 11:24, Dima Pasechnik wrote: > > > Is the following a bug, or not: > > > > A bug in what :-) > > > > in pari (why don't they chop off a factor of x^j, it costs next to nothing) > (or Sage can do this, too) > > > > This is already interesting (on Linux): > > > > sage: float(RR(3).sqrt()) > > 1.7320508075688772 > > sage: float(RDF(3).sqrt()) > > 1.7320508075688772 > > sage: float(RR(sqrt(3))) > > 1.7320508075688772 > > sage: float(RDF(sqrt(3))) > > 1.7320508075688774
Note that the difference exists already in the representation of the numbers (no relation with conversion into floats): sage: RR(3).sqrt().sign_mantissa_exponent() (1, 7800463371553962, -52) sage: RDF(3).sqrt().sign_mantissa_exponent() (1, 7800463371553962, -52) sage: RR(sqrt(3)).sign_mantissa_exponent() (1, 7800463371553962, -52) sage: RDF(sqrt(3)).sign_mantissa_exponent() (1, 7800463371553963, -52) I do not remember where i read that (correct me if i am wrong, or provide a reference if you know where it is), but RDF is supposed to round towards the nearest floating-point number. However: sage: a2 = 7800463371553962*2^-52 sage: a3 = 7800463371553963*2^-52 sage: R = RealIntervalField(1000) sage: R(a2 -sqrt(3)).endpoints() (-1.00350842218069026527919215165919755628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050819683258448262e-16, -1.00350842218069026527919215165919755628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050446377811046973e-16) sage: R(a3 -sqrt(3)).endpoints() (1.21693762706962281556807118452244306871944193020548066983091199962918853813242751424324373858584593296970030054905001047521188344487905626351471906768097694417932025179898915325076734984687656733096677113349327745331078162028772952868339632138411980950013462620140610532349652493423949180316741551738e-16, 1.21693762706962281556807118452244306871944193020548066983091199962918853813242751424324373858584593296970030054905001047521188344487905626351471906768097694417932025179898915325076734984687656733096677113349327745331078162028772952868339632138411980950013462620140610532349652493423949553622188953027e-16) I would vote for having conversions to round the same way than operations. Realfield seems to take care of rounding modes when converting from SR: sage: R = RealField(53,rnd='RNDZ') sage: R(sqrt(3)).sign_mantissa_exponent() (1, 7800463371553962, -52) sage: R = RealField(53,rnd='RNDN') sage: R(sqrt(3)).sign_mantissa_exponent() (1, 7800463371553962, -52) sage: R = RealField(53,rnd='RNDD') sage: R(sqrt(3)).sign_mantissa_exponent() (1, 7800463371553962, -52) sage: R = RealField(53,rnd='RNDU') sage: R(sqrt(3)).sign_mantissa_exponent() (1, 7800463371553963, -52) sage: R = RealField(53,rnd='RNDA') sage: R(sqrt(3)).sign_mantissa_exponent() (1, 7800463371553963, -52) Where is the conversion from SR to RDF defined ? Ciao, Thierry > > The last one is actually more wrong (error: 0.55 ulp) than the first > > three (error: 0.45 ulp). Interestingly, it is precisely this wrong > > answer which is used in the doctest. > > > > I think it's fair to say that the doctest isn't robust. > > > > Actually, on FreeBSD I get > sage: float(RDF(sqrt(3))) > 1.7320508075688772 > > Do you mean to say that Linux's (g)libm is not as good? :-) > > > > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-devel@googlegroups.com. > Visit this group at https://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.