Re: getXXX methods

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: pg(at)fastcrypt(dot)com
Cc: Kris Jurka <books(at)ejurka(dot)com>, "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: getXXX methods
Date: 2004-07-09 21:33:04
Message-ID: 40EF0F10.9040409@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Dave Cramer wrote:
> Well, I have an interesting problem...
>
> Detecting that a value is greater than MaxLong?
>
> If I parse it using Double.parseDouble, and it is greater than LongMax
> by 1 or so, the value ends up actually being less due to rounding ?
>
> Any suggestions?

The problem is that you're going via a double, you're going to lose
precision there regardless of what you do (you don't have 64 bits of
mantissa+sign to play with).

If you want to retain precision, don't use a double as your intermediate
value. Perhaps extract everything before the first '.' and use
parseLong? That will truncate rather than round the value though.

I don't like the whole idea of silently losing data anyway..

-O

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Bill Chandler 2004-07-09 21:41:26 Re: Cursors performance (was: Re: [PERFORM] Terrible performance after deleting/recreating indexes)
Previous Message Bill Chandler 2004-07-09 21:20:24 Re: Cursors performance (was: Re: [PERFORM] Terrible performance after deleting/recreating indexes)