Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.9k stars 540 forks source link

NaN returned when raising integer value to negative power #8702

Closed p5pRT closed 16 years ago

p5pRT commented 17 years ago

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

Searchable as RT41050$

p5pRT commented 17 years ago

From ECulver@scarborough.com

To​: perlbug@​perl.org Subject​: NaN returned when raising integer value to negative power Reply-To​: eculver@​scarborough.com Message-Id​: \5\.8\.8\_2892\_1165333655@​nycscr\-culvere1\.us\.enterprisenet\.org

This is a bug report for perl from eculver@​scarborough.com\, generated with the help of perlbug 1.35 running under perl v5.8.8.

#!perl use warnings; use strict;

use bignum;

my $n = -1;

print "10 ** $n = " . 10 ** $n . "\n";


Flags​:   category=core   severity=high


Site configuration information for perl v5.8.8​:

Configured by SYSTEM at Tue Aug 29 12​:39​:43 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration​:   Platform​:   osname=MSWin32\, osvers=5.0\, archname=MSWin32-x86-multi-thread   uname=''   config_args='undef'   hint=recommended\, useposix=true\, d_sigaction=undef   usethreads=define use5005threads=undef useithreads=define usemultiplicity=define   useperlio=define d_sfio=undef uselargefiles=define usesocks=undef   use64bitint=undef use64bitall=undef uselongdouble=undef   usemymalloc=n\, bincompat5005=undef   Compiler​:   cc='cl'\, ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DNO_HASH_SEED -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX'\,   optimize='-MD -Zi -DNDEBUG -O1'\,   cppflags='-DWIN32'   ccversion='12.00.8804'\, gccversion=''\, gccosandvers=''   intsize=4\, longsize=4\, ptrsize=4\, doublesize=8\, byteorder=1234   d_longlong=undef\, longlongsize=8\, d_longdbl=define\, longdblsize=10   ivtype='long'\, ivsize=4\, nvtype='double'\, nvsize=8\, Off_t='__int64'\, lseeksize=8   alignbytes=8\, prototype=define   Linker and Libraries​:   ld='link'\, ldflags ='-nologo -nodefaultlib -debug -opt​:ref\,icf -libpath​:"C​:\Perl\lib\CORE" -machine​:x86'   libpth=\lib   libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib   perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib   libc=msvcrt.lib\, so=dll\, useshrplib=yes\, libperl=perl58.lib   gnulibc_version=''   Dynamic Linking​:   dlsrc=dl_win32.xs\, dlext=dll\, d_dlsymun=undef\, ccdlflags=' '   cccdlflags=' '\, lddlflags='-dll -nologo -nodefaultlib -debug -opt​:ref\,icf -libpath​:"C​:\Perl\lib\CORE" -machine​:x86'

Locally applied patches​:   ACTIVEPERL_LOCAL_PATCHES_ENTRY   Iin_load_module moved for compatibility with build 806   Avoid signal flag SA_RESTART for older versions of HP-UX   PerlEx support in CGI​::Carp   Less verbose ExtUtils​::Install and Pod​::Find   Patch for CAN-2005-0448 from Debian with modifications   Rearrange @​INC so that 'site' is searched before 'perl'   Partly reverted 24733 to preserve binary compatibility   28671 Define PERL_NO_DEV_RANDOM on Windows   28376 Add error checks after execing PL_cshname or PL_sh_path   28305 Pod​::Html should not convert \"foo\" into ``foo''   27736 Make perl_fini() run with Sun WorkShop compiler   27619 Bug in Term​::ReadKey being triggered by a bug in Term​::ReadLine   27549 Move DynaLoader.o into libperl.so   27528 win32_pclose() error exit doesn't unlock mutex   27527 win32_async_check() can loop indefinitely   27515 ignore directories when searching @​INC   27359 Fix -d​:Foo=bar syntax   27210 Fix quote typo in c2ph   27203 Allow compiling swigged C++ code   27200 Make stat() on Windows handle trailing slashes correctly   27194 Get perl_fini() running on HP-UX again   27133 Initialise lastparen in the regexp structure   27034 Avoid \"Prototype mismatch\" warnings with autouse   26970 Make Passive mode the default for Net​::FTP   26921 Avoid getprotobyname/number calls in IO​::Socket​::INET   26897\,26903 Make common IPPROTO_* constants always available   26670 Make '-s' on the shebang line parse -foo=bar switches   26536 INSTALLSCRIPT versus INSTALLDIRS   26379 Fix alarm() for Windows 2003   26087 Storable 0.1 compatibility   25861 IO​::File performace issue   25084 long groups entry could cause memory exhaustion   24699 ICMP_UNREACHABLE handling in Net​::Ping


@​INC for perl v5.8.8​:   C​:/Perl/site/lib   C​:/Perl/lib   .


Environment for perl v5.8.8​:   HOME=C​:/Documents and Settings/culvered01   LANG (unset)   LANGUAGE (unset)   LD_LIBRARY_PATH (unset)   LOGDIR (unset)

PATH=C​:\Perl\Bin\;C​:\PROGRA~1\MKSTOO~1\Bin;C​:\PROGRA~1\MKSTOO~1\Bin\x11;C​:\PROGRA~1\MKSTOO~1\mksnt;C​:\WINDOWS\system32;C​:\WINDOWS;C​:\WINDOWS\System32\Wbem;C​:\Program Files\Intel\IDB\9.1\IA32\Script;C​:\Program Files\Intel\Compiler\Fortran\9.1\IA32\Bin;C​:\Program Files\Intel\Compiler\Fortran\9.1\EM64T\Bin;C​:\Program Files\Microsoft Visual Studio\VC98\BIN;C​:\Program Files\Microsoft Visual Studio\DF98\BIN;C​:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C​:\Program Files\Microsoft Visual Studio\Common\Msdev98\BIN;C​:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C​:\Program Files\Microsoft Visual Studio\Common\Tools;C​:\utility\Bin\;C​:\emacs\Bin;C​:\ruby\bin;C​:\program files\GNU\Bin\Bin;C​:\program files\OptTech;C​:\qtime\Bin;C​:\Bc4q\Bin;C​:\Program Files\InstallShield\InstallShield 5.5 Professional Edition\Program;C​:\Program Files\InstallShield\PackageForTheWeb 2;C​:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C​:\Program Files\Microsoft SQL Server\90\Tools\Binn\;C​:\Program Files\Microsoft Visual Studio\Common\Tools;C​:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C​:\Program Files\Subversion\Bin;C​:\Tcl\Bin;.;C​:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C​:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C​:\Program Files\Microsoft Visual Studio\Common\Tools;C​:\Program Files\Microsoft Visual Studio\VC98\bin;.;C​:\g95\bin;C​:\gfortran\bin   PERL_BADLANG (unset)   PERL_RL=Perl o=0   SHELL=C​:/PROGRA~1/MKSTOO~1/mksnt/ksh.exe

p5pRT commented 17 years ago

From culvere@acm.org

I've replicated this (with the same source) on FreeBSD​:

This is perl\, v5.8.8 built for i386-freebsd-64int (with 1 registered patch\, see perl -V for more detail)

O/S Version​: (from uname -a) FreeBSD PCBSD.localhost 6.1-RELEASE-p2 FreeBSD 6.1-RELEASE-p2 #1​: Thu Jul 6 11​:31​:02 PDT 2006
root@​PCBSD.localhost​:/usr/obj/usr/src/sys/PCBSDv1.2 i386

p5pRT commented 17 years ago

From culvere@acm.org

On Tue Dec 05 20​:22​:12 2006\, swampyankee wrote​:

I've replicated this (with the same source) on FreeBSD​:

This is perl\, v5.8.8 built for i386-freebsd-64int (with 1 registered patch\, see perl -V for more detail)

O/S Version​: (from uname -a) FreeBSD PCBSD.localhost 6.1-RELEASE-p2 FreeBSD 6.1-RELEASE-p2 #1​: Thu Jul 6 11​:31​:02 PDT 2006
root@​PCBSD.localhost​:/usr/obj/usr/src/sys/PCBSDv1.2 i386

To add some clarification​:

1) 10 ** (-1) returns NaN only when the bignum pragma is used; it returns 0.10 (the correct answer) if the "use bignum" line in the sample code is comment out or if "use bignum" is replaced by "use Math​::BigFloat".

2) 10.0 ** (-1) also returns NaN when the bignum pragma is used.

3) While this may be correct behavior for integers (integers are not closed under division\, which is essentially what raising a value to a negative power is doing)\, it is inconsistent with the results for other integer division; 1/10 does not return NaN with the bignum pragma (it returns\, 0.1). It is also inconsistent with both the bignum docs (the samples in the docs include sqrt(33) and "2 ** 0.5"; both return values which are approximately correct (it's impossible for either to be exactly correct; if bignum returns NaN for 10**(-1)\, it should return NaN for both these cases\, too).

p5pRT commented 17 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 16 years ago

From p5p@spam.wizbit.be

This was fixed in Math​::Bigint v1.78 and in bignum v0.18. (released on 27 January 2007)

p5pRT commented 16 years ago

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'