Ask Your Question
2

Something like RealDigits in Sage?

asked 2015-02-21 16:07:06 +0100

logomath gravatar image

updated 2015-02-21 23:36:29 +0100

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)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2015-02-21 18:17:16 +0100

Thorsten gravatar image

updated 2015-02-21 20:21:58 +0100

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
edit flag offensive delete link more

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: 2015-02-21 16:07:06 +0100

Seen: 675 times

Last updated: Feb 21 '15

Related questions