Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73897

Re: 1-0.95

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: 1-0.95
Date 2014-07-03 14:17 +0300
Organization A noiseless patient Spider
Message-ID <87d2dmitdd.fsf@elektro.pacujo.net> (permalink)
References (3 earlier) <53b4509a$0$29985$c3e8da3$5496439d@news.astraweb.com> <878uobpm40.fsf@elektro.pacujo.net> <53b4bdb2$0$29985$c3e8da3$5496439d@news.astraweb.com> <87zjgrdjew.fsf@elektro.pacujo.net> <53b5242e$0$11121$c3e8da3@news.astraweb.com>

Show all headers | View raw


Steven D'Aprano <steve@pearwood.info>:

> If you don't think Fraction counts as "arbitrary precision rational 
> number", what do you think does?

I was assuming you were referring to an idealized datatype.

Fraction() doesn't have a square root method. Let's make one:

   def newton(x, n):
       guess = Fraction(1)
       for i in range(n):
           guess = (guess + x / guess) / 2
       return guess

   >>> newton(Fraction(2), 3)
   Fraction(577, 408)
   >>> newton(Fraction(2), 8)
   Fraction(489266466344238819545868088398566945584921822586685371455477\
   00898547222910968507268117381704646657,
   345963636159190997653185453890148615173898600719883426481871047662465\
   65694525469768325292176831232)
   >>> newton(Fraction(2), 18)

   ... keeps going and going and going ...

Point being, if you have trouble with floats, you will likely have it
with Decimal(), Fraction(), super-duper Rational(), Algebraic(),
Expressible(), you name it. You'll just have to develop an understanding
of numeric computation.

BTW, the same thing applies to integers, also. While Python has
abstracted out many of the 2's-complement arithmetic details, the bits
shine through.

>> The point is, regular floating point numbers will likely the optimal
>> choice for your numeric calculation needs. They are compact, fast and
>> readily supported by hardware and numeric software. Switching to
>> Decimal might give you a false sense of security.
>
> Ah, now this is a much more reasonable thing to say. Why didn't you
> say so in the first place? :-)

That's all I've been saying all along.


Marko

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

1-0.95 Pedro Izecksohn <izecksohn@yahoo.com> - 2014-07-01 14:17 -0700
  Re: 1-0.95 pecore@pascolo.net - 2014-07-02 01:13 +0200
  Re: 1-0.95 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-02 15:27 +0000
    Re: 1-0.95 Marko Rauhamaa <marko@pacujo.net> - 2014-07-02 19:59 +0300
      Re: 1-0.95 Skip Montanaro <skip@pobox.com> - 2014-07-02 12:34 -0500
      Re: 1-0.95 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-02 18:34 +0000
        Re: 1-0.95 Marko Rauhamaa <marko@pacujo.net> - 2014-07-02 23:00 +0300
          Re: 1-0.95 Chris Angelico <rosuav@gmail.com> - 2014-07-03 10:16 +1000
          Re: 1-0.95 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-03 02:19 +0000
            Re: 1-0.95 Rustom Mody <rustompmody@gmail.com> - 2014-07-02 21:06 -0700
              Re: 1-0.95 Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-07-03 16:55 +1200
                Re: 1-0.95 Rustom Mody <rustompmody@gmail.com> - 2014-07-02 22:21 -0700
                Re: 1-0.95 Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-02 23:50 -0600
              OT: speeds (physical, not computing) [was Re: 1-0.95] Steven D'Aprano <steve@pearwood.info> - 2014-07-03 09:15 +0000
            Re: 1-0.95 Marko Rauhamaa <marko@pacujo.net> - 2014-07-03 09:51 +0300
              Re: 1-0.95 Steven D'Aprano <steve@pearwood.info> - 2014-07-03 09:36 +0000
                Re: 1-0.95 Marko Rauhamaa <marko@pacujo.net> - 2014-07-03 14:17 +0300

csiph-web