Limit or Bug?

From: Jared Still <jkstill_at_gmail.com>
Date: Thu, 3 Jul 2008 13:44:59 -0700
Message-ID: <bf46380807031344v4d13ad5ar364cb65b626dd5bb@mail.gmail.com>


The following bit of SQL uses the mod() function to determine modulus 2 of two large numbers

13:37:20 SQL>set echo on
13:37:24 SQL>@mod_test
13:37:25 SQL>
13:37:25 SQL>
13:37:25 SQL>
13:37:25 SQL>select mod(power(2,127)-1,2) from dual
13:37:25   2  /

MOD(POWER(2,127)-1,2)


                    1

1 row selected.

13:37:25 SQL>
13:37:25 SQL>select mod(power(2,128)-1,2) from dual
13:37:25   2  /

MOD(POWER(2,128)-1,2)


                   -1

1 row selected.

13:37:25 SQL>


Notice that mod(power(2,128)-1,2) returns an incorrect answer, while the answer for mod(power(2,127)-1,2) is correct.

Does someone here know why?

Is it a limit?

Or is it a bug?

Please supply an explanation and/or URL for your answer. :)

My guess (yes Alex, it's a guess, or rather, a hunch) is that this is related to two's complement binary numbers, but I haven't been able to (yet) find any explanation for this.

--

Jared Still
Certifiable Oracle DBA and Part Time Perl Evangelist

--

http://www.freelists.org/webpage/oracle-l Received on Thu Jul 03 2008 - 15:44:59 CDT

Original text of this message