develooper Front page | perl.perl5.porters | Postings from June 2001

Re: Report /pro/3gl/CPAN/perl-5.7.1

Thread Previous | Thread Next
From:
Mike Guy
Date:
June 27, 2001 08:24
Subject:
Re: Report /pro/3gl/CPAN/perl-5.7.1
Message ID:
E15FHAf-0003mY-00@draco.cus.cam.ac.uk
Nicholas Clark <nick@ccl4.org> wrote
> On Mon, Jun 25, 2001 at 05:27:44PM -0500, Jarkko Hietaniemi wrote:
> >   NV = 4745162525730
> >   NV = 4745162525730
>
> This is crazy. They appear to be the same.

Not necessarily.    Sneaky stuff, float-to-string conversion.   Watch:

  DB<1> $x = 4745162525730; $y = $x + 2**-10
 
  DB<2> Dump $x; Dump $y; Dump $y-$x;
SV = NV(0x115fc0) at 0x24a68c
  REFCNT = 1
  FLAGS = (NOK,pNOK)
  NV = 4745162525730
SV = NV(0x115fd0) at 0x24a6b0
  REFCNT = 1
  FLAGS = (NOK,pNOK)
  NV = 4745162525730
SV = NV(0x115fc0) at 0x24a7f4
  REFCNT = 1
  FLAGS = (PADTMP,NOK,pNOK)
  NV = 0.0009765625
 
  DB<3>


If you want to know reliably the value of an NV, you have to look at more
that its printed form.    If you know a quantity which is near to the
expected value, and which is exactly representable, the simplest
trick is to display the difference from that quantity, e.g.
displaying  $y-4745162525730  in the above example.


Mike Guy

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About