[Tutor] How to assert a float?

Willi Richert richert@upb.de
Mon, 7 Jan 2002 23:50:08 +0100


Hi Tutor,

How do you assert the following:

============================
import math

def log2(x):
    return math.log(x)/math.log(2.0)

assert 2**log2(5)==5.0
============================

2**log2(5) yields 4.9999999999999991 which is not 5.0

To round is also not very wise. Do you know how one can assert floats? 

Thanks
willi