Re: Parallel arithmetic?

2005-08-05 Thread jburgy
Dennis Lee Bieber wrote:
> On Thu, 04 Aug 2005 20:59:33 -0500, "Terrance N. Phillip"
> <[EMAIL PROTECTED]> declaimed the following in
> comp.lang.python:
>
> > Thank-you very much for all the excellent replies. I'm thinking of using
> > this to determine if a sequence is a "run" (as in a card game). If I've
> > got a sorted hand [3, 4, 5, 6, 7], then I know I've got a 5-card run
>
>   A sorted list?
>
>   if (hand[-1] - hand[0]) == (len(hand) - 1)
>
> would seem to do it for your example.
>
>   Actually, if you KNOW the list is only 5 entries long
>
>   if (hand[4] - hand[0]) == 4
>

It's cute but wrong! How 'bout hand = [ 0, 0, 0, 4 ]? It's sorted,
passes your test and does not meet the OP's requirement :(

> would do it.
>
>   Or any equivalent... (hand[0] + 4) == hand[4]
>
>
> --
>  > == <
>  >   [EMAIL PROTECTED]  | Wulfraed  Dennis Lee Bieber  KD6MOG <
>  >  [EMAIL PROTECTED] |   Bestiaria Support Staff   <
>  > == <
>  >   Home Page: <
>  >Overflow Page: <

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is There the Equivalent of FLT_EPS of C In Python?

2005-09-16 Thread jburgy
A. L. wrote:
> I am writing the code involved in numerical computation. When I need a
> float epsilon similar to FLT_EPS in C, eps in matlab, I fail to find
> the equivalent in python. Could somebody here can give me some advices?

Have you searched the documentation? I you can't find anything there,
you can always calculate it yourself. Epsilon is usually defined as
follows:

>>> eps = 1.
>>> while 1. + eps != 1.:
... eps /= 2.
...
>>> eps
1.1102230246251565e-16

Then some people actually multiply the above number by 2. In other
words (on my machine), eps is math.ldexp(1, -52). YMMV

Jan

-- 
http://mail.python.org/mailman/listinfo/python-list