Thread: Math Huh?

Math Huh?

From
Josh Berkus
Date:
Folks,

I'll let this session speak for itself:

jwnet=> select version();                           version
---------------------------------------------------------------PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC
2.95.3
(1 row)

jwnet=> select (255 * 255 * 255 * 255);?column?
------------66716671
(1 row)

So, a bug, or what?


--
-Josh Berkus



Re: Math Huh?

From
Tom Lane
Date:
Josh Berkus <josh@agliodbs.com> writes:
> jwnet=> select (255 * 255 * 255 * 255);
>  ?column?
> -----------
>  -66716671
> (1 row)

> So, a bug, or what?

(yawn) int4 overflow.  Use float or numeric if you want overflow
robustness...
        regards, tom lane


Re: Math Huh?

From
Larry Rosenman
Date:
On Thu, 2002-05-30 at 18:29, Josh Berkus wrote:
> Folks,
> 
> I'll let this session speak for itself:
> 
> jwnet=> select version();
>                             version
> ---------------------------------------------------------------
>  PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.95.3
> (1 row)
> 
> jwnet=> select (255 * 255 * 255 * 255);
>  ?column?
> -----------
>  -66716671
> (1 row)
> 
> So, a bug, or what?
> 
You exceeded a SIGNED int4.. 
ler=# select (255*255*255*255)
ler-# ;?column?  
------------66716671
(1 row)

ler=# select (255::int8*255::int8*255::int8*255::int8); ?column?  
------------4228250625
(1 row)

ler=# select version();                              version                               
---------------------------------------------------------------------PostgreSQL 7.2.1 on i386-portbld-freebsd4.6,
compiledby GCC 2.95.3
 
(1 row)

ler=# 



> 
> -- 
> -Josh Berkus
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> 
-- 
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 972-414-9812                 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749



Re: Math Huh?

From
David Stanaway
Date:
On Thu, 2002-05-30 at 18:29, Josh Berkus wrote:
> Folks,
>
> I'll let this session speak for itself:
>
> jwnet=> select version();
>                             version
> ---------------------------------------------------------------
>  PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.95.3
> (1 row)
>
> jwnet=> select (255 * 255 * 255 * 255);
>  ?column?
> -----------
>  -66716671
> (1 row)
scratch=# select (255 * 255 * 255 * 255::int8); ?column?
------------4228250625
(1 row)

$ bc -l
obase=16
4228250625
FC05FC01
^

You have overflowed a signed integer as the most significant bit is set.

--
David Stanaway


Re: Math Huh?

From
Josh Berkus
Date:
Tom,

> (yawn) int4 overflow.  Use float or numeric if you want overflow
> robustness...

Shouldn't it give me an error?  This does:

SELECT (255^4)::INT4


--
-Josh Berkus

______AGLIO DATABASE SOLUTIONS___________________________                                       Josh Berkus  Complete
informationtechnology     josh@agliodbs.com   and data management solutions     (415) 565-7293  for law firms, small
businesses     fax 621-2533   and non-profit organizations.     San Francisco 



Re: Math Huh?

From
Larry Rosenman
Date:
On Thu, 2002-05-30 at 18:59, Josh Berkus wrote:
> 
> Tom,
> 
> > (yawn) int4 overflow.  Use float or numeric if you want overflow
> > robustness...
> 
> Shouldn't it give me an error?  This does:
> 
> SELECT (255^4)::INT4
Why?  You're doing 3 multiplications, instead of one power.  It has no
idea what the number is. 


> 
> 
> -- 
> -Josh Berkus
> 
> ______AGLIO DATABASE SOLUTIONS___________________________
>                                         Josh Berkus
>    Complete information technology     josh@agliodbs.com
>     and data management solutions     (415) 565-7293
>    for law firms, small businesses      fax 621-2533
>     and non-profit organizations.     San Francisco
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> 
-- 
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 972-414-9812                 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749



Re: Math Huh?

From
Achilleus Mantzios
Date:
On Thu, 30 May 2002, Josh Berkus wrote:

> Folks,
> 
> I'll let this session speak for itself:
> 
> jwnet=> select version();
>                             version
> ---------------------------------------------------------------
>  PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.95.3
> (1 row)
> 
> jwnet=> select (255 * 255 * 255 * 255);
>  ?column?
> -----------
>  -66716671
> (1 row)
> 
> So, a bug, or what?

Dear Josh, i686-pc-linux-gnu           ^^^
the 686 arch is the answer.

dynacom=# select (255::int8 * 255 * 255 * 255); ?column?
------------4228250625
(1 row)
dynacom=#

> 
> 
> 

-- 
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
tel:    +30-10-8981112
fax:    +30-10-8981877
email:  achill@matrix.gatewaynet.com       mantzios@softlab.ece.ntua.gr