Ask Your Question
2

Something like RealDigits in Sage?

asked 10 years ago

logomath gravatar image

updated 10 years ago

slelievre gravatar image

Is there in Sagemath something like RealDigits in Mathematica for computing (binary) digits of any real number? (and not only for integers)

Can you please also explain how to transform back a non-integer binary string as '100.1000111001001' to the corresponding (approximated) base ten decimal? (not float)

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
4

answered 10 years ago

Thorsten gravatar image

updated 10 years ago

To get the binary representation just add a .str(base=2) to the approximated value.

 sage:  a = pi + sqrt(2)
 sage:  a.n(digits=10).str(base=2)
 '100.1000111001001001010100001111000010'

For the other direction the method RR is useful. Given as first argument the string and as second the base.

 sage:  s= a.n(digits=60).str(base=2)
 sage:  RR(s,2)
 4.55580621596289
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 10 years ago

Seen: 842 times

Last updated: Feb 21 '15

Related questions