TITLE: Rational and irrational numbers under base pi
QUESTION [6 upvotes]: I am wondering, what would happen to the representation of a number like 2 in base pi? I know that things like $π^2$ would simply be 100, but what about numbers that are not of the form $π^n$ ? I think it ought to get tricky!

REPLY [8 votes]: See here for formal definition of representation in a non integral base. With such a definition $2$ in base $\pi$ is simply... $2$. This because $2<\pi$ hence it can be represented by itself.
In any base $\beta$ most numbers (all but a countable set) have an infinite representation. Only sums of powers of $\beta$ have a finite representation.
Here is an algorithm (written in python) to compute the representation in any base:
from math import *
import string

def repr(x,b,digits=30):
    """ represent @x in base @b """
    DIGITS = string.digits + string.ascii_uppercase
    n = int(floor(log(x) / log(b)))
    r = ''
    while n>0 or (len(r)<digits and x != 0.0):
        d = int(x/b**n)
        if n==-1:
            r += '.'
        r += DIGITS[d]
        x = x - d * b**n
        n -= 1
    if r=='':
        r= DIGITS[0]
    return r

for x,b in [(1973.0,10), (8.0,2), (10.0,pi)]:
    print x, 'in base', b, 'is written:', repr(x,b)

The output is:
1973.0 in base 10 is written: 1973
8.0 in base 2 is written: 100
10.0 in base 3.14159265359 is written: 100.01022122221121122001111210