On 5 April 2016 at 18:21, Isuru Fernando <isu...@gmail.com> wrote:
>
> I think the current way of representing Floats is reasonable.
>
> Float internally keeps it in binary representation, so any non-terminating
> number in base 2 is truncated when stored as a Float. That's why there is a
> string constructor which can take in an exact decimal value and create a
> number in binary representation with precision mentioned.
>
> Note that in this way only numbers representable as a sum of different
> powers of two have an exact value. Others can also be represented in an
> exact form if the base of the float is different than 2, but I think mpmath
> and many other libraries use only base 2.

Some do and some use decimal. The advantage of decimal is being able
to exactly represent numbers input as decimal. Maybe the key here is
not to have Float automatically turn into an mpf in the first place if
it can't be done losslessly. Maybe a Float can remember the exact
input it was given e.g. "1.4142" and not try to turn that into a
binary representation until the precision is specified later.

> If you want an exact form, best way would be to define it as a Rational and
> then you can do 1/3 as well which you can't if it's in decimal form. One
> other good thing about Rational is that `sin(Rational)` won't be evaluated
> unless SymPy knows the exact value, whereas `sin(Float)` would evaluate
> leading to error propagation even if it's something like `0.5` which
> represented exactly in binary representation.

Exactly sin(Rational) won't be auto-evaluated because it's not clear
how many digits to use until someone later calls .evalf(). I think it
should be the same for sin(Float). It shouldn't really matter whether
the user does S("0.1") or S("1/10").

--
Oscar

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxTL72-KgEixLa9gWWMaDuEkEedbTT6rEep3yxSOmdnMLA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to