http://www.perlmonks.org?node_id=1009231


in reply to Irrational numbers

Certain irrational numbers have a compact but useful representation; for example the square-root of two can be represented as bless(\'2 ** 0.5', 'Surd'). A suitably smart implementation of the Surd class could figure out that root-2 times 3-root-2 equals 6 without resorting to floating point arithmetic.

The problem with π is that it's not just irrational; it's transcendental. There's no convenient, accurate representation of it. You've just got to store an approximation as a float or string or whatever, and it will only be accurate to a certain number of decimal places.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'