Neal D. Becker wrote:[color=blue]
> Is there a way in python to access properties of floats? I need something
> equiv to C DBL_EPSILON defined in <float.h>.
>
>[/color]
you could try the traditional algorithm
[color=blue][color=green][color=darkred]
>>> def dbl_epsilon():[/color][/color][/color]
.... n = 0
.... while 1:
.... e = 1.0/2**n
.... if (1.0+e==1.0): break
.... n += 1
.... pe = e
.... return pe
....[color=blue][color=green][color=darkred]
>>> print dbl_epsilon()[/color][/color][/color]
2.22044604925e-016[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
Robin Becker wrote:[color=blue]
> Neal D. Becker wrote:
>[color=green]
>> Is there a way in python to access properties of floats? I need
>> something
>> equiv to C DBL_EPSILON defined in <float.h>.
>>
>>[/color]
> you could try the traditional algorithm
>[color=green][color=darkred]
> >>> def dbl_epsilon():[/color][/color]
> ... n = 0
> ... while 1:
> ... e = 1.0/2**n
> ... if (1.0+e==1.0): break
> ... n += 1
> ... pe = e
> ... return pe
> ...[color=green][color=darkred]
> >>> print dbl_epsilon()[/color][/color]
> 2.22044604925e-016[color=green][color=darkred]
> >>>[/color][/color]
>[/color]
on looking further I find my 'traditional' algorithm is actually
something like this
def dbl_epsilon(_ep s=[]):
if not _eps:
etop = 1.0
ebot = 0.0
eps = ebot+(etop-ebot)/2.0
while eps!=ebot and eps!=etop:
epsp1 = 1.0 - eps
if epsp1<1.0: etop = eps
else: ebot = eps
eps = ebot+(etop-ebot)/2.0
_eps.append(eto p)
assert (1.0-etop)<1.0 and (1.0-ebot)==1.0, 'Error in epsilon calculation'
return _eps[0]
Comment