Neil's News

Python in Python

8 July 2012

Here's a fun little challenge. Re-implement the int() and float() functions of Python (or equivalents in your favourite language) without using calls to int, long, float, eval, or similar cheats. Sounds easy?

It is quite easy; just a hundred lines of code for each function. But it is healthy to periodically remind ourselves of how high-level our languages have become. The entirety of my first programming language contained the same amount of code as these two numeric functions.

Here's my solution for int() and float().

< Previous | Next >

Legal yada yada: My views do not necessarily represent those of my employer or my goldfish.