Re: float bug? perl 5.8, DBI and oracle 10.2.0



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."


Relevant Pages

  • Re: float bug? perl 5.8, DBI and oracle 10.2.0
    ... use DBI; ... This code simply opens a connection toward an oracle database. ... When I run it with perl 5.6.2, DBI 1.38 and DBD::Oracle 1.17, it says: ... bin: 0011111111111011110010101001011010010001101001110101110011010001 ...
    (perl.dbi.users)
  • Re: DBD::Sybase context allocation routine failed
    ... DBI will take care of loading and initialising the module. ... attempting a DB connection using a brand new installation of perl ... perl -MDBI -e 'print DBI- ... The context allocation routine failed. ...
    (perl.dbi.users)
  • Re: Perl 6 DBI API ideas
    ... Though I didn't raise my hand when you asked for people to contribute to a DBI module for Perl 6, I've had some ideas that I thought about sharing. ... I would also love to see some standardization on the driver names ("mysql" when it's normally written ... DBI is supposed to be query language agnostic, even if SQL is the most commonly used group of languages, and if a user can declare this explicitly, it saves the driver from having to guess what they were given, which might be ambiguous. ...
    (perl.dbi.users)
  • Re: Can anyone program perl and fix a script?
    ... you would find lots of perl code to look at for examples of a perl commands. ... that is a huge list of ports and services. ... grep torrent /etc/services and see what you can see. ... Sounds like you need a filter rule in iptables to throttle torrent connection. ...
    (alt.os.linux)
  • Problem of DBI build
    ... I installed Oracle Application Server 4.0.8.2 included perl module. ... I need to installe DBI and DBD::Oracle module. ... You can install them any time after installing the DBI. ... line 318: error 1705: Function prototypes are an ANSI feature. ...
    (perl.dbi.users)