Fri Jul 25 15:52:12 CEST 2008 Arjan Wekking arjan@streamtech.nl * Correct rational (double-float) formatting
On Clozure CL (PPC32), (format "~f" (coerce 1/123 'double-float)) returns "0.008130081300813009D0" which is not a number syntax PostgreSQL understands.
In order to be sure that a format is used that is always supported, the formatting string was changed to generate the number in exponential notation which is accepted by PostgreSQL and which can be reliably generated by at least SBCL and Clozure CL (only CLs I've tested).
The modified control string in this patch ("~,,,,,,'EE") will generate for the rational 1/123 "8.130081300813009E-3" which is accepted and interpreted properly by PostgreSQL.
On 25 jul 2008, at 17:14, Marijn Haverbeke wrote:
The modified control string in this patch ("~,,,,,,'EE")
Well. that has to be the freakiest format string I've seen all week. Thanks for the patch, it has been applied.
Thanks, sorry for the rather blunt way my patch got send with Darcs; I'm still trying to get a grip on how it sends patches through e-mail (like; trying add a custom subject and/or introduction). Another idea I had was to simply represent rationals as a division (something like "(1/123::float)" but I'm not sure whether this has any precision loss or other disadvantages.
-Arjan
sorry for the rather blunt way my patch got send with Darcs;
No problem, your detailed patch message made it quite clear what it was about. I usually do 'darcs send -o filename.patch' and then attach the resulting file to an e-mail.
Another idea I had was to simply represent rationals as a division (something like "(1/123::float)" but I'm not sure whether this has any precision loss or other disadvantages.
I'm not sure Postgres allows expressions in every place where it allows constants -- but maybe it does. The current approach seems okay though, since Postgres numerics always use decimal digits, so as long as the numeric type on the Postgres side has less digits precision than the writer writes out, we aren't losing any information that wouldn't be lost anyway.
Best, Marijn
postmodern-devel@common-lisp.net