X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A3F65D1B1CB for ; Mon, 12 Jul 2004 08:58:27 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92763-06 for ; Mon, 12 Jul 2004 11:58:31 +0000 (GMT) Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by svr1.postgresql.org (Postfix) with SMTP id 6AFB1D1B1A5 for ; Mon, 12 Jul 2004 08:58:21 -0300 (ADT) Received: (qmail 32457 invoked from network); 12 Jul 2004 11:58:27 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.36?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 12 Jul 2004 11:58:27 -0000 Subject: Re: patch for getXXX methods From: Dave Cramer Reply-To: pg@fastcrypt.com To: Oliver Jowett Cc: "pgsql-jdbc@postgresql.org" In-Reply-To: <40F1CF54.1040606@opencloud.com> References: <1089407362.1508.292.camel@localhost.localdomain> <40EF1D5D.2050509@opencloud.com> <1089416849.1515.298.camel@localhost.localdomain> <40F15718.7000302@opencloud.com> <1089577486.1508.316.camel@localhost.localdomain> <40F1CF54.1040606@opencloud.com> Content-Type: text/plain Organization: Cramer Consulting Message-Id: <1089633531.11544.318.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Mon, 12 Jul 2004 07:58:51 -0400 Content-Transfer-Encoding: 7bit X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/107 X-Sequence-Number: 10491 Oliver, Yes, and this is why I needed to do it for getLong, but I don't think it's necessary for getInt, getByte, as it is really just to test to see if it is greater than the max allowed value. Dave On Sun, 2004-07-11 at 19:37, Oliver Jowett wrote: > Dave Cramer wrote: > > Oliver, > > > > I don't believe you will lose precision if the number is below MAX_LONG > > ? When I tested it on my system, I was able to retrieve a double that > > was equal to MAX_LONG without losing precision. > > The attached testcase says otherwise. It produces this output: > > > Mismatch: 9223372036854775806 => 9.223372036854776E18 => 9223372036854775807 > > Mismatch: 9223372036854775805 => 9.223372036854776E18 => 9223372036854775807 > > Mismatch: 9223372036854775804 => 9.223372036854776E18 => 9223372036854775807 > > Mismatch: 9223372036854775803 => 9.223372036854776E18 => 9223372036854775807 > > Mismatch: 9223372036854775802 => 9.223372036854776E18 => 9223372036854775807 > > Mismatch: 9223372036854775801 => 9.223372036854776E18 => 9223372036854775807 > > Mismatch: 9223372036854775800 => 9.223372036854776E18 => 9223372036854775807 > > Mismatch: 9223372036854775799 => 9.223372036854776E18 => 9223372036854775807 > [...] > > Mismatch: 9223372036854775296 => 9.223372036854776E18 => 9223372036854775807 > > Mismatch: 9223372036854775295 => 9.2233720368547748E18 => 9223372036854774784 > > Mismatch: 9223372036854775294 => 9.2233720368547748E18 => 9223372036854774784 > > and so on. > > The problem is that near MAX_LONG you need almost 64 bits of mantissa to > exactly represent the value -- but a double is only a 64-bit value > including space for the exponent. I can't remember the exact split but > from the above it looks like there is around 10 bits of exponent so you > only have ~54 bits for the mantissa -- so you only get a precision of > about +/- 512 when you're dealing with numbers of a magnitude around > MAX_LONG. > > -O > > > !DSPAM:40f1cf8080747915514021! > > ______________________________________________________________________ > public class TestDoublePrecision { > public static void main(String[] args) { > for (long l = Long.MAX_VALUE; l != Long.MIN_VALUE; --l) { > double d = (double)l; > long check = (long)d; > > if (check != l) > System.out.println("Mismatch: " + l + " => " + d + " => " + check); > } > } > } > > > !DSPAM:40f1cf8080747915514021! -- Dave Cramer 519 939 0336 ICQ # 14675561