ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 02 Mar 2017 20:21:57 -0600Difference between RealNumber and RealLiteralhttps://ask.sagemath.org/question/36798/difference-between-realnumber-and-realliteral/I discovered this tonight.
sage: L = srange(-1,1,.01)
sage: type(L[50])
<type 'sage.rings.real_mpfr.RealNumber'>
sage: type(-.5)
<type 'sage.rings.real_mpfr.RealLiteral'>
and hence
sage: -.5 in L
False
In some sense I'm cool with that, but in another sense I'm very annoyed. (Especially since I probably should have known about it but missed this.) So ... what exactly is the difference between these types, and when should they each be used? You might see my confusion given this result:
sage: L[50] in RR
True
sage: -.5 in RR
True
Oh, and this is really awesome:
sage: type(RealNumber(-.5))
<type 'sage.rings.real_mpfr.RealLiteral'>
Also, perhaps if anyone ever makes the full list of real numbers types as in [Question 9950](https://ask.sagemath.org/question/9950/what-are-the-different-real-numbers-in-sage/), one could add these.kcrismanThu, 02 Mar 2017 20:21:57 -0600https://ask.sagemath.org/question/36798/What are the differences between RealDoubleField() and RealField(53) ?https://ask.sagemath.org/question/9991/what-are-the-differences-between-realdoublefield-and-realfield53/Hi,
This question is related to
[question 2402](http://ask.sagemath.org/question/2402/what-are-the-different-real-numbers-in-sage)
(still open!) and tries to collect differences between RDF=RealDoubleField() and RR=RealField(53).
These are two floating point real number fields with both 53 bits of precision. The first one comes from the processor floating-point arithmetic, the second one is "emulated" by mpfr. They are assumed to follow the same rounding standards (to the nearest, according to the [sagebook](http://sagebook.gforge.inria.fr/), but i may be wrong).
However, we can see some differences between them:
sage: RDF(1/10)*10 == RDF(1)
False
sage: RDF(1/10)*10 - RDF(1)
-1.11022302463e-16
sage: RR(1/10)*10 == RR(1)
True
sage: sage: RR(1/10)*10 - RR(1)
0.000000000000000
Could you explain that ?
**EDIT: this was a bug and it is now fixed**, see [trac ticket 14416](http://trac.sagemath.org/ticket/14416).
There are also some specificities on which field should be used for some
methods.
- For example, it seems that the eignevalues are not well computed on RR, but are
correctly computed on RDF ([see trac #13660](http://trac.sagemath.org/sage_trac/ticket/13660)). What is the reason for that ?
- Also, it seems that when dealing with huge matrices, the fast atlas library in
only used when entries are in RDF, not in RR
([see trac #10815](http://trac.sagemath.org/sage_trac/ticket/10815)).
Are there other difference that should be known between both implementations of floating point numbers in Sage ?
ThierrytmonteilThu, 04 Apr 2013 13:34:40 -0500https://ask.sagemath.org/question/9991/