Re: RealDigits

• To: mathgroup at christensen.cybernetics.net
• Subject: [mg1794] Re: [mg1741] RealDigits
• From: Paul Wellin <wellin at telospub.COM>
• Date: Sun, 30 Jul 1995 21:41:54 -0400

```Here is a very simple approach using Horner's rule for fast polynomial
multiplication. First, define a function that will work with a list of
integer digits.

In[1]:= convert[digits_List, base_:10] :=
Fold[(base #1 + #2)&, 0, digits]

And then define the case for the situation returned by RealDigits:

In[2]:= convert[{{a__},n_}, base_:10] :=
Fold[(#1 base + #2)&, 0, {a}] / 10^(Length[{a}]-n)

Here is a list of real digits:

In[3]:= d = RealDigits[213.143]
Out[3]= {{2, 1, 3, 1, 4, 3}, 3}

In[4]:= convert[d] //N
Out[4]= 213.143

And here is what happens when a list of integer digits is passed:

In[5]:= IntegerDigits[238345]
Out[5]= {2, 3, 8, 3, 4, 5}

In[6]:= convert[%]
Out[6]= 238345

> The function RealDigits[x, b] returns a list of two items.  For example,
>
> RealDigits[Pi //N]
> {{3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3}, 1}
>
> What is the inverse of this function?  That is, given the base b, a list
> {...} of base b digits, and an interger n, how do we elegantly obtain x for
> which RealDigits[x, b] = {{...},n}?
>
> ==================================
> Samuel H. Cox
> insshc at gsusgi2.gsu.edu
> Department of Risk Management and Insurance
> Georgia State University

_____________________________________________________________________
Paul Wellin, Editor
TELOS/Springer-Verlag                  phone: 408-249-9314
3600 Pruneridge Ave., Suite 200        fax: 408-249-2595
Santa Clara, CA 95051  USA             email: wellin at telospub.com

```

• Prev by Date: Re: RealDigits
• Next by Date: Re: 3D Axes Label & bounding box of graphics [help]
• Previous by thread: Re: RealDigits