finding out the precision of floats

John Machin sjmachin at lexicon.net
Wed Feb 28 16:29:59 EST 2007


On Mar 1, 4:19 am, "Bart Ogryczak" <B.Ogryc... at gmail.com> wrote:
> On Feb 28, 3:53 pm, "John Machin" <sjmac... at lexicon.net> wrote:
>
> > On Feb 28, 10:38 pm, "BartOgryczak" <B.Ogryc... at gmail.com> wrote:
>
> > > [1] eg. consider calculating interests rate, which often is defined as
> > > math.pow(anualRate,days/365.0).
>
>
> > More importantly, the formula you give is dead wrong. The correct
> > formula for converting an annual rate of interest to the rate of
> > interest to be used for n days (on the basis of 365 days per year) is:
>
> > (1 + annual_rate) ** (n / 365.0) - 1.0
> > or
> > math.pow(1 + annual_rate, n / 365.0) - 1.0
> > if you prefer.
>
> YPB? Anyone with half a brain knows, that you can either express rate
> as 0.07 and do all those ridiculous conversions above, or express it
> as 1.07 and apply it directly.
>

A conversion involving an exponentiation is necessary. "All those"?? I
see only two.

Please re-read your original post, and note that there are *TWO* plus-
or-minus 1.0 differences between your formula and mine. For an annual
rate of 10%, yours would calculate the rate for 6 months (expressed as
182.5 days) as:
math.pow(0.10, 0.5) = 0.316... i.e. 31.6%

My formula produces:
math.pow(1.10, 0.5) - 1.0 = 0.0488... i.e. 4.88%.

Which answer is ridiculous?




More information about the Python-list mailing list