Re: Why don't we accept exponential format for integers?

From: Marti Raudsepp <marti(at)juffo(dot)org>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Bill Moran <wmoran(at)potentialtech(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Why don't we accept exponential format for integers?
Date: 2010-12-17 22:27:23
Message-ID: AANLkTin1aB49XKAUTAXpkPE=C1u888kvVqPHjF-8qUQf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Dec 18, 2010 at 00:05, Josh Berkus <josh(at)agliodbs(dot)com> wrote:
> Well, that's stupidly arbitrary.  If we're not going to accept
> '1.234e+01'::Integer, then we shouldn't accept 1.234e+01::Integer either.

Not surprising to me. This is how many languages implement type conversion.

Python:
>>> int(1.234e+01)
12
>>> int('1.234e+01')
ValueError: invalid literal for int() with base 10: '1.234e+01'

PHP:
print intval(1.234e+01) . "\n";
print intval('1.234e+01') . "\n";
gives:
12
1
Because PHP's int->string cast terminates parsing when it sees an
unrecognized character.

Java makes the difference quite explicit and obvious:
int a = (int)1.234e+01;
int a = Integer.parseInt("1.234e+01);

Regards,
Marti

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Charles.McDevitt 2010-12-17 22:29:44 Re: Why don't we accept exponential format for integers?
Previous Message Tom Lane 2010-12-17 22:22:17 Re: Why don't we accept exponential format for integers?