Thread

  1. 123.45 - 123 = 0.45

    jose' soares <sferac@bo.nettuno.it> — 1998-12-15T12:41:26Z

    Hi all,
    
    I tried to divide 123.45 by 123.00 but PostgreSQL gives me a wrong
    result:
    
    hygea=> select 123.45 - 123.00;
             ?column?
    -----------------
    0.450000000000003
    (1 row)
    
    -Jose'-
    
    
    
    
  2. Re: [HACKERS] 123.45 - 123 = 0.45

    Oleg Broytmann <phd@sun.med.ru> — 1998-12-15T13:08:48Z

    Hello!
    
    On Tue, 15 Dec 1998, Sferacarta Software wrote:
    > I tried to divide 123.45 by 123.00 but PostgreSQL gives me a wrong
    > result:
    > 
    > hygea=> select 123.45 - 123.00;
    >          ?column?
    > -----------------
    > 0.450000000000003
    > (1 row)
    
       I cannot understand anything. You said "to divide" and then "123.45 - 123.00".
    Are you trying to divide or to substract?
    
    Oleg.
    ---- 
        Oleg Broytmann  National Research Surgery Centre  http://sun.med.ru/~phd/
               Programmers don't die, they just GOSUB without RETURN.
    
    
    
  3. Re: [HACKERS] 123.45 - 123 = 0.45

    Bruce Momjian <maillist@candle.pha.pa.us> — 1998-12-15T14:27:03Z

    > Hi all,
    > 
    > I tried to divide 123.45 by 123.00 but PostgreSQL gives me a wrong
    > result:
    > 
    > hygea=> select 123.45 - 123.00;
    >          ?column?
    > -----------------
    > 0.450000000000003
    > (1 row)
    > 
    
    Wow, I get the same thing here.
    
    Even this doesn't work:
    
    	test=> select float8(123.45) - float8(123.00);
    	         ?column?
    	-----------------
    	0.450000000000003
    	(1 row)
    
    Now constants are automatically promoted to float8, so I expected the
    same results, but what is going on here?
    
    -- 
      Bruce Momjian                        |  http://www.op.net/~candle
      maillist@candle.pha.pa.us            |  (610) 853-3000
      +  If your life is a hard drive,     |  830 Blythe Avenue
      +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
    
    
  4. Re: [HACKERS] 123.45 - 123 = 0.45

    David Hartwig <daveh@insightdist.com> — 1998-12-15T15:18:21Z

    Try this:
    
    #include <stdio.h>
    
    main()
    {
    double f1 = 123.45;
    double f2 = 123.00;
    double r;
    
        r = f1 - f2;
        printf("%0.15f  %0.15f  %0.15f\n", f1, f2, r);
    }
    
    Internal representation of 123.45 is not exact.   In the conversion to
    binary, an irrational number is created which is truncated to 64 bits.
    
    
    Bruce Momjian wrote:
    
    > > Hi all,
    > >
    > > I tried to divide 123.45 by 123.00 but PostgreSQL gives me a wrong
    > > result:
    > >
    > > hygea=> select 123.45 - 123.00;
    > >          ?column?
    > > -----------------
    > > 0.450000000000003
    > > (1 row)
    > >
    >
    > Wow, I get the same thing here.
    >
    > Even this doesn't work:
    >
    >         test=> select float8(123.45) - float8(123.00);
    >                  ?column?
    >         -----------------
    >         0.450000000000003
    >         (1 row)
    >
    > Now constants are automatically promoted to float8, so I expected the
    > same results, but what is going on here?
    >
    > --
    >   Bruce Momjian                        |  http://www.op.net/~candle
    >   maillist@candle.pha.pa.us            |  (610) 853-3000
    >   +  If your life is a hard drive,     |  830 Blythe Avenue
    >   +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
    
    
    
  5. Re: [HACKERS] 123.45 - 123 = 0.45

    Vince Vielhaber <vev@michvhf.com> — 1998-12-15T15:34:42Z

    On Tue, 15 Dec 1998, Sferacarta Software wrote:
    
    > Hi all,
    > 
    > I tried to divide 123.45 by 123.00 but PostgreSQL gives me a wrong
    > result:
    > 
    > hygea=> select 123.45 - 123.00;
    >          ?column?
    > -----------------
    > 0.450000000000003
    > (1 row)
    
    Are you trying to subtract or divide?   Your select is subtraction,
    your question was division.
    
    Vince.
    -- 
    ==========================================================================
    Vince Vielhaber -- KA8CSH   email: vev@michvhf.com   flame-mail: /dev/null
           # include <std/disclaimers.h>                   TEAM-OS2
       Online Searchable Campground Listings    http://www.camping-usa.com
           "There is no outfit less entitled to lecture me about bloat
                   than the federal government"  -- Tony Snow
    ==========================================================================
    
    
    
    
    
    
  6. Re[2]: [HACKERS] 123.45 - 123 = 0.45

    jose' soares <sferac@bo.nettuno.it> — 1998-12-15T15:35:04Z

    Hello Oleg,
    
    martedì, 15 dicembre 98, you wrote:
    
    OB> Hello!
    
    OB> On Tue, 15 Dec 1998, Sferacarta Software wrote:
    >> I tried to divide 123.45 by 123.00 but PostgreSQL gives me a wrong
    >> result:
    >> 
    >> hygea=> select 123.45 - 123.00;
    >>          ?column?
    >> -----------------
    >> 0.450000000000003
    >> (1 row)
    
    OB>    I cannot understand anything. You said "to divide" and then "123.45 - 123.00".
    OB> Are you trying to divide or to substract?
    
    Sorry I want to say subtract.
    
    -Jose'-
    
    
    
    
  7. Re: [HACKERS] 123.45 - 123 = 0.45

    Bruce Momjian <maillist@candle.pha.pa.us> — 1998-12-15T16:20:15Z

    > Try this:
    > 
    > #include <stdio.h>
    > 
    > main()
    > {
    > double f1 = 123.45;
    > double f2 = 123.00;
    > double r;
    > 
    >     r = f1 - f2;
    >     printf("%0.15f  %0.15f  %0.15f\n", f1, f2, r);
    > }
    > 
    > Internal representation of 123.45 is not exact.   In the conversion to
    > binary, an irrational number is created which is truncated to 64 bits.
    
    Yes, someone pointed this out to me in private e-mail, and I wrote a C
    program to confirm it.  I just had never seen such rounding on such
    small non-irrational numbers.
    
    -- 
      Bruce Momjian                        |  http://www.op.net/~candle
      maillist@candle.pha.pa.us            |  (610) 853-3000
      +  If your life is a hard drive,     |  830 Blythe Avenue
      +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026