RealDigits

RealDigits[x]

gives a list of the digits in the approximate real number x, together with the number of digits that are to the left of the decimal point.

RealDigits[x,b]

gives a list of baseb digits in x.

RealDigits[x,b,len]

gives a list of len digits.

RealDigits[x,b,len,n]

gives len digits starting with the coefficient of bn.

Details

  • RealDigits gives the most significant digits first, as in standard positional notation.
  • RealDigits[x] normally returns a list of digits of length Round[Precision[x]].
  • RealDigits[x] and RealDigits[x,b] normally require that x be an approximate real number, returned for example by N. RealDigits[x,b,len] also works on exact numbers.
  • For integers and rational numbers with terminating digit expansions, RealDigits[x] returns an ordinary list of digits. For rational numbers with nonterminating digit expansions, it yields a list of the form {a1,a2,,{b1,b2,}} representing the digit sequence consisting of the ai followed by infinite cyclic repetitions of the bi. »
  • If len is larger than Precision[x]/Log[10,b], then remaining digits are filled in as Indeterminate.
  • RealDigits[x,b,len,n] starts with the digit which is the coefficient of bn, truncating or padding with zeros as necessary. »
  • RealDigits[x,b,len,-1] starts with the digit immediately to the right of the baseb decimal point in x.
  • RealDigits[x,b,Automatic,n] gives as many digits as it can in a fixed-precision number.
  • The base b in RealDigits[x,b] need not be an integer. For any real b such that b>1, RealDigits[x,b] successively finds the largest integer multiples of powers of b that can be removed while leaving a nonnegative remainder.
  • RealDigits[x] discards the sign of x.
  • RealDigits[0.] gives {{0},-Floor[Accuracy[0.]]}.
  • FromDigits can be used as the inverse of RealDigits.

Examples

open allclose all

Basic Examples  (3)

Give the list of digits and exponent:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Give 25 digits of in base 10:

In[1]:=
Click for copyable input
Out[1]=

Give 25 digits of 19/7:

In[1]:=
Click for copyable input
Out[1]=

Give an explicit recurring decimal form:

In[2]:=
Click for copyable input
Out[2]=

Scope  (3)

Generalizations & Extensions  (2)

Applications  (6)

Properties & Relations  (1)

Possible Issues  (2)

Neat Examples  (1)

See Also

MantissaExponent  IntegerDigits  BaseForm  FromDigits  ContinuedFraction  MultiplicativeOrder  ChampernowneNumber  FindTransientRepeat  DecimalForm

Tutorials

Introduced in 1991
(2.0)
| Updated in 2007
(6.0)