Re: float bug? perl 5.8, DBI and oracle 10.2.0
- From: jonathan.leffler@xxxxxxxxx (Jonathan Leffler)
- Date: Wed, 18 Jul 2007 07:27:54 -0700
On 7/18/07, Erwan Lemonnier <erwan@xxxxxxxxxxxx> wrote:
Hello folk!
Now I think I got a clean shot at what's troubling me 8-)
Consider the following code:
---------------------<snip>--------------------------
use strict;
use warnings;
use DBI;
my $ORASID = $ENV{ORACLE_SID};
my $ORAUSR = 'username';
my $ORAPWD = 'password';
sub showbin {
print "bin: ".unpack("B70",reverse pack("d",$_[0]))."\n";
}
my $v1 = "1.73696";
showbin($v1);
print "connecting\n";
my $DBC = DBI->connect("dbi:Oracle:$ORASID",$ORAUSR,$ORAPWD,
{ PrintError=>0, AutoCommit=>0 } );
my $v2 = "1.73696";
showbin($v2);
---------------------<snip>--------------------------
This code simply opens a connection toward an oracle database. And
shows the binary representation of the string "1.73696" converted into
a native float (NV) before and after we opened the connection.
When I run it with perl 5.6.2, DBI 1.38 and DBD::Oracle 1.17, it says:
[HEAD] ~/HEAD/test/t> !967$ /opt/perl-5.6.2/bin/perl 04_test1.t
bin: 0011111111111011110010101001011010010001101001110101110011010001
connecting
bin: 0011111111111011110010101001011010010001101001110101110011010001
When I run it with perl 5.8.8, DBI 1.58 and DBD::Oracle 1.19, it says:
[HEAD] ~/HEAD/test/t> !969$ /opt/perl-5.8.8/bin/perl 04_test1.t
bin: 0011111111111011110010101001011010010001101001110101110011010001
connecting
bin: 0011111111111011110010101001011010010001101001110101110011010000
See how the least significant bit (last one on the right) changes in
the last run?
There we have it. It is what caused the problems I have been spamming
you all with for the last few days :)
Conclusion: on my host (perl 5.8 etc.), the line:
my $DBC = DBI->connect("dbi:Oracle:$ORASID",$ORAUSR,$ORAPWD,
{ PrintError=>0, AutoCommit=>0 } );
seems to alter the way perl parses the string "1.73696". This later
resulted in arithmetic errors that looked like floating point related
issues but were not.
Has anyone any idea of what's happening here????
Silly question time - I assume that if you don't includes the DBI->connect
line, then the two invocations of showbin produce the same output in both
versions of Perl.
Somewhere in "Elements of Programming Style" by Kernighan & Plauger, it says
words to the effect that:
A wise programmer once said 'moving floating point numbers is like moving
sand piles; every time you do, you lose a little sand and you pick up a
little dirt'.
--
Jonathan Leffler <jonathan.leffler@xxxxxxxxx> #include <disclaimer.h>
Guardian of DBD::Informix - v2007.0226 - http://dbi.perl.org
"Blessed are we who can laugh at ourselves, for we shall never cease to be
amused."
- References:
- Re: Re: float bug? perl 5.8, DBI and oracle 10.2.0
- From: Erwan Lemonnier
- Re: float bug? perl 5.8, DBI and oracle 10.2.0
- From: Christopher Sarnowski
- Re: float bug? perl 5.8, DBI and oracle 10.2.0
- From: Tim Bunce
- Re: float bug? perl 5.8, DBI and oracle 10.2.0
- From: Erwan Lemonnier
- Re: float bug? perl 5.8, DBI and oracle 10.2.0
- From: Erwan Lemonnier
- Re: Re: float bug? perl 5.8, DBI and oracle 10.2.0
- Prev by Date: Re: float bug? perl 5.8, DBI and oracle 10.2.0
- Next by Date: RE: float bug? perl 5.8, DBI and oracle 10.2.0
- Previous by thread: Re: float bug? perl 5.8, DBI and oracle 10.2.0
- Next by thread: Re: float bug? perl 5.8, DBI and oracle 10.2.0
- Index(es):
Relevant Pages
|