Re: Why don't we accept exponential format for integers? - Mailing list pgsql-hackers

From Marti Raudsepp
Subject Re: Why don't we accept exponential format for integers?
Date
Msg-id AANLkTin1aB49XKAUTAXpkPE=C1u888kvVqPHjF-8qUQf@mail.gmail.com
Whole thread Raw
In response to Re: Why don't we accept exponential format for integers?  (Josh Berkus <josh@agliodbs.com>)
List pgsql-hackers
On Sat, Dec 18, 2010 at 00:05, Josh Berkus <josh@agliodbs.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


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Why don't we accept exponential format for integers?
Next
From:
Date:
Subject: Re: Why don't we accept exponential format for integers?