pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: pg@fastcrypt.com
Cc: Kris Jurka <books@ejurka.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: getXXX methods
Date: Sat, 10 Jul 2004 09:33:04 +1200
Message-ID: <40EF0F10.9040409@opencloud.com> (raw)
In-Reply-To: <1089387924.1506.287.camel@localhost.localdomain>
References: <1088795907.1536.118.camel@localhost.localdomain>
	<Pine.BSO.4.56.0407061336560.12042@leary.csoft.net>
	<1089145387.1506.65.camel@localhost.localdomain>
	<Pine.BSO.4.56.0407061559110.373@leary.csoft.net>
	<1089154614.1508.70.camel@localhost.localdomain>
	<40EB385F.9030704@opencloud.com>
	<1089162095.1508.173.camel@localhost.localdomain>
	<40EB4D85.6080100@opencloud.com>
	<Pine.BSO.4.56.0407062020270.26570@leary.csoft.net>
	<40EB5683.90301@opencloud.com>
	<Pine.BSO.4.56.0407062054400.25870@leary.csoft.net>
	<1089230030.1506.226.camel@localhost.localdomain>
	<Pine.BSO.4.56.0407080146340.23659@leary.csoft.net>
	<1089288683.1506.235.camel@localhost.localdomain>
	<1089387924.1506.287.camel@localhost.localdomain>

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



view thread (17+ messages)

Message-ID: <40EF0F10.9040409@opencloud.com>
Permalink:  ../40EF0F10.9040409@opencloud.com/
Also on:    postgresql.org/message-id/40EF0F10.9040409@opencloud.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: oliver@opencloud.com, pg@fastcrypt.com, books@ejurka.com
  Subject: Re: getXXX methods
  In-Reply-To: <40EF0F10.9040409@opencloud.com>
  References: <1088795907.1536.118.camel@localhost.localdomain> <Pine.BSO.4.56.0407061336560.12042@leary.csoft.net> <1089145387.1506.65.camel@localhost.localdomain> <Pine.BSO.4.56.0407061559110.373@leary.csoft.net> <1089154614.1508.70.camel@localhost.localdomain> <40EB385F.9030704@opencloud.com> <1089162095.1508.173.camel@localhost.localdomain> <40EB4D85.6080100@opencloud.com> <Pine.BSO.4.56.0407062020270.26570@leary.csoft.net> <40EB5683.90301@opencloud.com> <Pine.BSO.4.56.0407062054400.25870@leary.csoft.net> <1089230030.1506.226.camel@localhost.localdomain> <Pine.BSO.4.56.0407080146340.23659@leary.csoft.net> <1089288683.1506.235.camel@localhost.localdomain> <1089387924.1506.287.camel@localhost.localdomain> <40EF0F10.9040409@opencloud.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox