Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evalf does not correctly interpret the number of digits #371

Closed
mzaffalon opened this issue Sep 11, 2020 · 4 comments
Closed

evalf does not correctly interpret the number of digits #371

mzaffalon opened this issue Sep 11, 2020 · 4 comments

Comments

@mzaffalon
Copy link
Contributor

mzaffalon commented Sep 11, 2020

evalf seems to convert the argument to Float64 and then extend its precision. I would expect evalf to behave like the last command in the example below. Is my expectation incorrect?

julia> Sym(2.45).evalf(70)
2.450000000000000177635683940025046467781066894531250000000000000000000
julia> BigFloat(2.45, 200) # turn a Float64 into a BigFloat
2.45000000000000017763568394002504646778106689453125
julia> BigFloat("2.45", 200) # parse "2.45" as a BigFloat
2.4500000000000000000000000000000000000000000000000000000000005

This is with [24249f21] SymPy v1.0.28.

Probably related to #369.

@jverzani
Copy link
Collaborator

I was going to suggest sympify("2.45") to avoid the conversion to a float within julia before SymPy has a chance to do something, but this has the same issue. Scanning the docs, I see you can use Float passing a string (similar to the big constructor):

sympy.Float("2.45", 100)

@mzaffalon
Copy link
Contributor Author

It looks like the problem remains:

julia> BigFloat(N(sympy.Float("2.45"), 256), 200)
2.45000000000000017763568394002504646778106689453125

@jverzani
Copy link
Collaborator

You need to specify a precision to Float, as in Float(“2.45”, 200)

@mzaffalon
Copy link
Contributor Author

Oh, I missed that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants