# Working with the set of real numbers (was: Finding size of Variable)

Chris Angelico rosuav at gmail.com
Wed Feb 12 09:47:55 CET 2014

```On Wed, Feb 12, 2014 at 7:17 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> Chris Angelico <rosuav at gmail.com> writes:
>
>> I have yet to find any computer that works with the set of real
>> numbers in any way. Never mind optimization, they simply cannot work
>> with real numbers.
>
> Not *any* computer? Not in *any* way? The Python built-in ‘float’ type
> “works with the set of real numbers”, in a way.

No, the Python built-in float type works with a subset of real numbers:

>>> float("pi")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
float("pi")
ValueError: could not convert string to float: 'pi'
>>> float("π")
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
float("π")
ValueError: could not convert string to float: 'π'

Same goes for fractions.Fraction and [c]decimal.Decimal. All of them
are restricted to some subset of rational numbers, not all reals.

> The <URL:http://docs.python.org/2/library/numbers.html#numbers.Real> ABC
> defines behaviours for types implementing the set of real numbers.
>
> What specific behaviour would, for you, qualify as “works with the set
> of real numbers in any way”?

Being able to represent surds, pi, e, etc, for a start. It'd
theoretically be possible with an algebraic notation (eg by carrying
through some representation like "2*pi" rather than 6.28....), but
otherwise, irrationals can't be represented with finite storage and a
digit-based system.

ChrisA

```