finding out the precision of floats

John Machin sjmachin at lexicon.net
Thu Mar 1 11:18:12 EST 2007


On Mar 1, 9:33 pm, "Bart Ogryczak" <B.Ogryc... at gmail.com> wrote:
> On Feb 28, 10:29 pm, "John Machin" <sjmac... at lexicon.net> wrote:
>
>
>
> > On Mar 1, 4:19 am, "BartOgryczak" <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%
>
> You're assuming that I'd store annual rate as 0.1, while actually it'd
> stored as 1.1.
> Which is logical and applicable directly.

Storing 1.1 and using it in calculations may save you a few
microseconds a day in your real-time apps. However the annual rate of
interest is 10% aka 0.1; naming 1.1 as "anualRate" (sic) is utterly
ludicrous.




More information about the Python-list mailing list