Floating point bug?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carl Banks

    #106
    Re: How about adding rational fraction to Python?

    On Feb 28, 9:36 am, Grant Edwards <gra...@visi.co mwrote:
    On 2008-02-28, Carl Banks <pavlovevide... @gmail.comwrote :
    >
    Automatic conversions, okay... but converting a result when
    all inputs are of one time, NO...
    >
    People, this is so cognitive dissonance it's not even funny.
    >
    There is absolutely nothing obvious about 1/2 returning a number that
    isn't at least approximately equal to one half.
    >
    I guess obviousness is in the eye of the beholder. To me it's
    obvious that "1" and "2" are integers, and it's also obvious
    that 2 goes into 1 zero times.
    2 goes into 1 0.5 times.
    There is nothing self-evident about operations maintaining
    types.
    >
    By that logic, there's no reason for 1 + "two" shouldn't
    convert one operand or the other.
    False dilemma, chief. That preserving type is not self-evident
    doesn't make all operations that don't preserve type a good idea.

    You people can't tell the difference between "obvious" and "learned
    conventions that came about because in limitations in the hardware at
    the time".
    >
    It seems to me that the expectation that 1/2 yield 0.5 is just
    as much a convention as that it yield 0 or a true rational.
    Sure it is, but unlike the old convention, it's the obvious one.


    Carl Banks

    Comment

    • D'Arcy J.M. Cain

      #107
      Re: How about adding rational fraction to Python?

      On Thu, 28 Feb 2008 06:10:13 -0800 (PST)
      Carl Banks <pavlovevidence @gmail.comwrote :
      On Feb 28, 3:30 am, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
      Automatic conversions, okay... but converting a result when all
      inputs are of one time, NO...
      >
      People, this is so cognitive dissonance it's not even funny.
      I'll say.
      There is absolutely nothing obvious about 1/2 returning a number that
      isn't at least approximately equal to one half. There is nothing self-
      evident about operations maintaining types.
      Not obvious to you. You are using subjective perception as if it was a
      law of nature. If "obvious" was the criteria then I would argue that
      the only proper result of integer division is (int, int). Give me the
      result and the remainder and let me figure it out.
      You people can't tell the difference between "obvious" and "learned
      conventions that came about because in limitations in the hardware at
      the time". Nobody would have come up with a silly rule like "x op y
      must always have the same type as x and y" if computer hardware had
      been up to the task when these languages were created.
      What makes you say they weren't? Calculating machines that handled
      floating point are older than Python by far.

      --
      D'Arcy J.M. Cain <darcy@druid.ne t | Democracy is three wolves
      http://www.druid.net/darcy/ | and a sheep voting on
      +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

      Comment

      • J. Cliff Dyer

        #108
        Re: How about adding rational fraction to Python?

        On Thu, 2008-02-28 at 11:22 -0500, D'Arcy J.M. Cain wrote:
        Not obvious to you. You are using subjective perception as if it was
        a
        law of nature. If "obvious" was the criteria then I would argue that
        the only proper result of integer division is (int, int). Give me the
        result and the remainder and let me figure it out.
        I'd like to point out that now you are talking about int OP int
        returning a tuple, not an int.



        Comment

        • Ross Ridge

          #109
          Re: How about adding rational fraction to Python?

          D'Arcy J.M. Cain wrote:
          Not obvious to you. You are using subjective perception as if it was
          a law of nature. If "obvious" was the criteria then I would argue that
          the only proper result of integer division is (int, int). Give me the
          result and the remainder and let me figure it out.
          J. Cliff Dyer <jcd@sdf.lonest ar.orgwrote:
          I'd like to point out that now you are talking about int OP int
          returning a tuple, not an int.
          No, D'Arcy's point was that "obvious" isn't the criteria because it
          would lead to behaviour that no one wants.

          No one is going to win this argument by using words like "natural" or
          "obvious". You're just going to have to accept that there that there
          is no concensus on this issue and there never was. In the end only one
          person's opinion of what was natural and obvious really matters.

          Ross Ridge

          --
          l/ // Ross Ridge -- The Great HTMU
          [oo][oo] rridge@csclub.u waterloo.ca
          -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
          db //

          Comment

          • D'Arcy J.M. Cain

            #110
            Re: How about adding rational fraction to Python?

            On Thu, 28 Feb 2008 13:32:06 -0500
            "J. Cliff Dyer" <jcd@sdf.lonest ar.orgwrote:
            On Thu, 2008-02-28 at 11:22 -0500, D'Arcy J.M. Cain wrote:
            Not obvious to you. You are using subjective perception as if it was
            a
            law of nature. If "obvious" was the criteria then I would argue that
            the only proper result of integer division is (int, int). Give me the
            result and the remainder and let me figure it out.
            >
            I'd like to point out that now you are talking about int OP int
            returning a tuple, not an int.
            Which would be stupid. Good thing I don't think that "obvious" should
            be the criteria.

            --
            D'Arcy J.M. Cain <darcy@druid.ne t | Democracy is three wolves
            http://www.druid.net/darcy/ | and a sheep voting on
            +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

            Comment

            • Paul Rubin

              #111
              Re: How about adding rational fraction to Python?

              "D'Arcy J.M. Cain" <darcy@druid.ne twrites:
              I'd like to point out that now you are talking about int OP int
              returning a tuple, not an int.
              >
              Which would be stupid. Good thing I don't think that "obvious" should
              be the criteria.
              We already have that function (divmod) and it is very useful.

              Comment

              • D'Arcy J.M. Cain

                #112
                Re: How about adding rational fraction to Python?

                On 28 Feb 2008 12:25:14 -0800
                Paul Rubin <"http://phr.cx"@NOSPAM. invalidwrote:
                "D'Arcy J.M. Cain" <darcy@druid.ne twrites:
                I'd like to point out that now you are talking about int OP int
                returning a tuple, not an int.
                Which would be stupid. Good thing I don't think that "obvious" should
                be the criteria.
                >
                We already have that function (divmod) and it is very useful.
                Yes it is and has nothing to do with this discussion. I don't think
                that anyone here has suggested that methods should return the type of
                their arguments although there have been a few suggestions that the
                suggestions were made.

                --
                D'Arcy J.M. Cain <darcy@druid.ne t | Democracy is three wolves
                http://www.druid.net/darcy/ | and a sheep voting on
                +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

                Comment

                • Steven D'Aprano

                  #113
                  Re: How about adding rational fraction to Python?

                  On Thu, 28 Feb 2008 11:22:43 -0500, D'Arcy J.M. Cain wrote:
                  Calculating machines that handled
                  floating point are older than Python by far.
                  Yes, and they almost universally give the result 1/2 -0.5.

                  --
                  Steven

                  Comment

                  • Steven D'Aprano

                    #114
                    Re: How about adding rational fraction to Python?

                    On Thu, 28 Feb 2008 14:41:56 -0500, Ross Ridge wrote:
                    You're just going to have to accept that there that there is no
                    concensus on this issue and there never was.
                    But that's not true. The consensus, across the majority of people (both
                    programmers and non-programmers alike) is that 1/2 should return 0.5.
                    There's a small minority that argue for a rational result, and a bigger
                    minority who argue for 0.

                    The interesting case is -1/2. According to the argument that "2 doesn't
                    go into 1", -1/2 should also return 0. But that's not what Python
                    returns, so it looks like the "int division" camp is screwed no matter
                    whether Python keeps the status quo or the other status quo.


                    --
                    Steven

                    Comment

                    • Paul Rubin

                      #115
                      Re: How about adding rational fraction to Python?

                      Steven D'Aprano <steve@REMOVE-THIS-cybersource.com .auwrites:
                      any restriction that functions must return the same
                      type as all its arguments is just crazy.
                      I don't think anyone is saying that they should necessarily do that
                      in general. Just in some specific cases.

                      Comment

                      • Paul Rubin

                        #116
                        Re: How about adding rational fraction to Python?

                        Steven D'Aprano <steve@REMOVE-THIS-cybersource.com .auwrites:
                        Calculating machines that handled
                        floating point are older than Python by far.
                        >
                        Yes, and they almost universally give the result 1/2 -0.5.
                        Can you name an example of a calculating machine that both:
                        1) represents the integer 1 and the real number 1.0 as distinct objects;
                        and
                        2) says 1/2 = 0.5 ?

                        Comment

                        • Arnaud Delobelle

                          #117
                          Re: How about adding rational fraction to Python?

                          On Feb 28, 10:41 pm, Steven D'Aprano <st...@REMOVE-THIS-
                          cybersource.com .auwrote:
                          [...]
                          The interesting case is -1/2. According to the argument that "2 doesn't
                          go into 1", -1/2 should also return 0. But that's not what Python
                          returns, so it looks like the "int division" camp is screwed no matter
                          whether Python keeps the status quo or the other status quo.
                          I'm in the "int division camp" and I like that -1 / 2 is -1. It's
                          nice because I can be sure that for any p and q:

                          * 0 <= p%q < q
                          * p = q*(p/q) + p%q

                          In other words, p/q is the largest r such that rq <= p.

                          It ensures that / and % are well behaved in a lot of situations, e.g:

                          * (x - y)%n == 0 if and only if x%n == y%n
                          * if a/n == b/n then abs(a - b) < n
                          ...

                          So that doesn't screw me, on the contrary I find it a mathematically
                          very sound decision. What screws me is that I'm going to have to type
                          p//q in the future.

                          --
                          Arnaud

                          Comment

                          • Terry Reedy

                            #118
                            Re: How about adding rational fraction to Python?


                            "Ross Ridge" <rridge@caffein e.csclub.uwater loo.cawrote in message
                            news:fq7voj$6v6 $1@rumours.uwat erloo.ca...
                            | Ross Ridge wrote:
                            | You're just going to have to accept that there that there is no
                            | concensus on this issue and there never was.
                            |
                            | Steven D'Aprano <steve@REMOVE-THIS-cybersource.com .auwrote:
                            | >But that's not true. The consensus, across the majority of people (both
                            | >programmers and non-programmers alike) is that 1/2 should return 0.5.
                            |
                            | You're deluding yourself.

                            As a major participant in the discussion, who initially opposed the change,
                            I think Steven is right.

                            | If there were a concensus then this issue then
                            | it wouldn't be so controversial.

                            The controversy was initially inflamed by issues that did not directly bear
                            on the merit of the proposal. Worst was its cloaking it in a metaphysical
                            argument about the nature of integers. It also did not help that Guido
                            initially had trouble articulating the *practical*, Pythonic reason for the
                            proposal.

                            To me, the key is this (very briefly): The current overloading of '/' was
                            copied from C. But Python is crucially different from C in that
                            expressions can generally be generic, with run-time rather than compile
                            time typing of variables. But there are no practical use cases that anyone
                            ever presented for expr_a / expr_b having two different numerical values,
                            giving fixed numerical values for expr_a and expr_b, depending on the
                            number types of the two expressions.

                            Beyond the change itself, another issue was its timing. When I proposed
                            that the version making 1/2=.5 the default be called 3.0, and Guido agreed,
                            many who agreed with the change in theory but were concerned with stability
                            of the 2.x series agreed that that would make it more palatable.

                            A third issue was the work required to make the change. The future
                            mechanism eased that, and the 2to3 conversion program will also issue
                            warnings.

                            Terry Jan Reedy



                            Comment

                            • Terry Reedy

                              #119
                              Re: How about adding rational fraction to Python?


                              "Arnaud Delobelle" <arnodel@google mail.comwrote in message

                              | What screws me is that I'm going to have to type p//q in the future.

                              When I compare that pain to the gain of not having to type an otherwise
                              extraneous 'float(...)', and the gain of disambiguating the meaning of a/b
                              (for builtin numbers at least), I think there will be a net gain for the
                              majority.

                              tjr



                              Comment

                              • Arnaud Delobelle

                                #120
                                Re: How about adding rational fraction to Python?

                                On Feb 29, 10:10 pm, "Terry Reedy" <tjre...@udel.e duwrote:
                                "Arnaud Delobelle" <arno...@google mail.comwrote in message
                                >
                                | What screws me is that I'm going to have to type p//q in the future.
                                >
                                When I compare that pain to the gain of not having to type an otherwise
                                extraneous 'float(...)', and the gain of disambiguating the meaning of a/b
                                (for builtin numbers at least), I think there will be a net gain for the
                                majority.
                                You may be right. I can see the rationale for this change (although
                                many aspects feel funny, such as doing integral arithmetic with
                                floats, i.e. 3.0//2.0).

                                Perhaps it'll be like when I quit smoking six years ago. I didn't
                                enjoy it although I knew it was good for me... And now I don't regret
                                it even though I still have the occasional craving.

                                --
                                Arnaud

                                Comment

                                Working...