Re: [PATCH] - was: Re: Cylinder limits ...

From: Andries.Brouwer@cwi.nl
Date: Tue Apr 04 2000 - 17:22:12 EST


    From: thospel@mail.dma.be (Ton Hospel)

    ...
> (capacity - capacity/625 + 974)/1950
    ...
> [Yes, the strange expression above really computes
> (512*capacity+500000)/1000000 exactly.]

    Well, almost :-)

    (512*capacity+500000)/1000000
    (512*624*capacity)/624*1000000+1/2
    (512*624*capacity)/512*625*1950+1/2
    (624*capacity)/625*1950+1/2
    (capacity-capacity/625)/1950+975/1950
    (capacity-capacity/625+975)/1950

    so your formula is wrong by 1 a whopping 0.2% of the time :-)
    (By thinking of capacity as a dimensional value it was obvious your
    formula was wrong)

Now why are you mistaken? Because you misunderstand
the meaning of the `/' operator in C.
For example, take capacity=20507. We find
  (512*capacity+500000)/1000000 = 10
  (capacity - capacity/625 + 974)/1950 = 10
  (capacity - capacity/625 + 975)/1950 = 11
so replacing 974 by 975 is wrong.

On the other hand, as I claimed,
        (capacity - capacity/625 + 974)/1950
and
        (512*capacity+500000)/1000000
give precisely the same answers for all values of capacity,
when computed in a sufficiently large integral type.
(Exercise: prove this!)

No, my formula is perfect.

Andries

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Apr 07 2000 - 21:00:13 EST