Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point error #683

Closed
p5pRT opened this issue Oct 5, 1999 · 10 comments
Closed

Floating point error #683

p5pRT opened this issue Oct 5, 1999 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 5, 1999

Migrated from rt.perl.org#1573 (status was 'resolved')

Searchable as RT1573$

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From stevenl@concentric.net

$ cat float.pl
#!/usr/local/bin/perl

my $t = 101.1 - 100.2;
print "value=$t\n";

$ float.pl
value=0.899999999999991

$ perl -V
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration​:
  Platform​:
  osname=linux, osvers=2.2.1-ac1, archname=i386-linux
  uname='linux porky.devel.redhat.com 2.2.1-ac1 #1 smp mon feb 1 17​:44​:44 est 1999 i686 unknown '
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef useperlio=undef d_sfio=undef
  Compiler​:
  cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
  cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
  ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
  stdchar='char', d_stdstdio=undef, usevfork=false
  intsize=4, longsize=4, ptrsize=4, doublesize=8
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib
  libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
  libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
  cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Characteristics of this binary (from libperl)​:
  Built under linux
  Compiled at Apr 6 1999 23​:34​:07
  @​INC​:
  /usr/lib/perl5/5.00503/i386-linux
  /usr/lib/perl5/5.00503
  /usr/lib/perl5/site_perl/5.005/i386-linux
  /usr/lib/perl5/site_perl/5.005
  .

-Steven

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From [Unknown Contact. See original ticket]

I found a very basic arithmetic error in Perl (tested on Linux, Sun, and
Windows 95). What am I missing here?

$ cat float.pl
#!/usr/local/bin/perl

my $t = 101.1 - 100.2;
print "value=$t\n";

$ float.pl
value=0.899999999999991

$ perl -V
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration​:
  Platform​:
  osname=linux, osvers=2.2.1-ac1, archname=i386-linux
  uname='linux porky.devel.redhat.com 2.2.1-ac1 #1 smp mon feb 1 17​:44​:44 est 1999 i686 unknown '
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef useperlio=undef d_sfio=undef
  Compiler​:
  cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
  cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
  ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
  stdchar='char', d_stdstdio=undef, usevfork=false
  intsize=4, longsize=4, ptrsize=4, doublesize=8
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib
  libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
  libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
  cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Characteristics of this binary (from libperl)​:
  Built under linux
  Compiled at Apr 6 1999 23​:34​:07
  @​INC​:
  /usr/lib/perl5/5.00503/i386-linux
  /usr/lib/perl5/5.00503
  /usr/lib/perl5/site_perl/5.005/i386-linux
  /usr/lib/perl5/site_perl/5.005
  .

-Steven

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From @samtregar

On 5 Oct 1999 richard@​tmtowtdi.perl.org wrote​:

I found a very basic arithmetic error in Perl (tested on Linux, Sun, and
Windows 95). What am I missing here?

You're missing the inherent uncertainty-factor of floating point
arithmatic on computers. Any basic CS text with a section on floating
point processing should be able to explain the problems to you in hideous
detail.

Summary​: it's pretty difficult to do floating point right, and it's a lot
faster just to do it wrong. In fact, it's not even totally clear what
"right" would be in some situations!

-sam

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From [Unknown Contact. See original ticket]

Aaaarrgh!!

Sam Tregar <sam@​tregar.com> wrote

On 5 Oct 1999 richard@​tmtowtdi.perl.org wrote​:

Oh no he didn't. The bug report came from someone else, but we don't
know who. So your message won't have reached the originator.

And it would probably have been a good idea to point him at the
relevant FAQ entries.

Richard​:

Is there some way of finding the originator of these reports, e.g.
from the bug database? Without this info, they can't usefully be
replied to.

And if it's a choice between flattened From​: fields and getting duplicated
messages, I'd vote for duplication. But of course I'd prefer neither.

Mike Guy

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From [Unknown Contact. See original ticket]

Aaaarrgh!!
Oops.

Sam Tregar <sam@​tregar.com> wrote

On 5 Oct 1999 richard@​tmtowtdi.perl.org wrote​:
Yuk.

Oh no he didn't. The bug report came from someone else, but we don't
know who. So your message won't have reached the originator.
You're right, there is also the problem of the non-reachable domain
names that appear to be reachable enough to send mail, but not to
recieve it from qmail...

And it would probably have been a good idea to point him at the
relevant FAQ entries.
It's a thought.

Is there some way of finding the originator of these reports, e.g.
from the bug database? Without this info, they can't usefully be
replied to.
Yup, I think they all went in the database OK, it's just the replies
getting stuffed.

And if it's a choice between flattened From​: fields and getting duplicated
messages, I'd vote for duplication. But of course I'd prefer neither.
Me too, believe me.

Sigh...
--
Richard Foley
+49 (0) 8121 988920 -> richard@​rfi.net

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From [Unknown Contact. See original ticket]

Steven Lee <stevenl@​concentric.net> wrote

I found a very basic arithmetic error in Perl (tested on Linux, Sun, and
Windows 95). What am I missing here?

You need to understand the basic facts about floating point arithmetic.
You would get the same results with C.

See the section "Floating-point Arithmetic" in the perlop manpage,
and the first entry in perlfaq4 for more explanation​:

  Why am I getting long decimals (eg, 19.9499999999999)
  instead of the numbers I should be getting (eg, 19.95)?

Mike Guy

@p5pRT
Copy link
Author

p5pRT commented Oct 8, 1999

From [Unknown Contact. See original ticket]

Date​: Tue, 28 Aug 1956 08​:37​:41 +0000
  To​: mjtg@​cus.cam.ac.uk (M.J.T. Guy)
  Cc​: perl5-porters@​perl.org
  Subject​: Re​: [ID 19991005.003] Floating point error
  From​: richard@​rfi.net (Richard Foley)
  Message-ID​: <195608280837412609968@​slip139-92-4-218.mu.de.ibm.net>

Amazing. This must be a really early version of perl. No wonder it took
so long to get here.

<chaim>
--
Chaim Frenkel Nonlinear Knowledge, Inc.
chaimf@​pobox.com +1-718-236-0183

@p5pRT
Copy link
Author

p5pRT commented Oct 8, 1999

From [Unknown Contact. See original ticket]

Date​: Tue, 28 Aug 1956 08​:37​:41 +0000
To​: mjtg@​cus.cam.ac.uk (M.J.T. Guy)
Cc​: perl5-porters@​perl.org
Subject​: Re​: [ID 19991005.003] Floating point error
From​: richard@​rfi.net (Richard Foley)
Message-ID​:
<195608280837412609968@​slip139-92-4-218.mu.de.ibm.net>

Amazing. This must be a really early version of perl. No wonder it took
so long to get here.

<chaim>

Yeah, well, I guess I have to go change the battery in my computer...

:-)

Ciao
Richard Foley


richard@​rfi.net
"Ciao" - (shorter than 'Aufwiedersehen' :-)

@p5pRT
Copy link
Author

p5pRT commented Oct 8, 1999

From @jhi

Chaim Frenkel writes​:

Date​: Tue, 28 Aug 1956 08​:37​:41 +0000
To​: mjtg@​cus.cam.ac.uk (M.J.T. Guy)
Cc​: perl5-porters@​perl.org
Subject​: Re​: [ID 19991005.003] Floating point error
From​: richard@​rfi.net (Richard Foley)
Message-ID​: <195608280837412609968@​slip139-92-4-218.mu.de.ibm.net>

Amazing. This must be a really early version of perl. No wonder it took
so long to get here.

Richard no doubt had to copy it in from a paper tape.

--
$jhi++; # http​://www.iki.fi/jhi/
  # There is this special biologist word we use for 'stable'.
  # It is 'dead'. -- Jack Cohen

@p5pRT
Copy link
Author

p5pRT commented Oct 8, 1999

From [Unknown Contact. See original ticket]

Chaim Frenkel writes​:

Date​: Tue, 28 Aug 1956 08​:37​:41 +0000
To​: mjtg@​cus.cam.ac.uk (M.J.T. Guy)
Cc​: perl5-porters@​perl.org
Subject​: Re​: [ID 19991005.003] Floating point error
From​: richard@​rfi.net (Richard Foley)
Message-ID​:
<195608280837412609968@​slip139-92-4-218.mu.de.ibm.net>

Amazing. This must be a really early version of perl. No
wonder it took
so long to get here.

Richard no doubt had to copy it in from a paper tape.

--
$jhi++; # http​://www.iki.fi/jhi/

Actually it took a while to scan, and OCR, it from the slate it was
originally carved on to.

Ciao
Richard Foley


richard@​rfi.net
"Ciao" - (shorter than 'Aufwiedersehen' :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant