Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #24091] Not OK: perl v5.8.1 on sgi6-irix-ld 6.5

0 views
Skip to first unread message

perlbug-...@perl.org

unread,
Oct 2, 2003, 8:40:39 AM10/2/03
to bugs-bi...@netlabs.develooper.com
# New Ticket Created by j...@research.att.com
# Please include the string: [perl #24091]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24091 >

This is a build failure report for perl from j...@research.att.com,
generated with the help of perlbug 1.34 running under perl v5.8.1.


-----------------------------------------------------------------
[Please enter your report here]

stable 5.8.1 fails 5 tests on SGI box with -Duselongdouble.

t/op/pow.............................
# Failed at op/pow.t line 69
# got '387420489'
# expected '387420489' (within '0')
# 387420489 - 387420489 = -3.30872245021211069948563476828e-24
# Failed at op/pow.t line 69
# got '2541865828329'
# expected '2541865828329' (within '0')
# 2541865828329 - 2541865828329 = -2.710505431213761085018632002175e-20
# Failed at op/pow.t line 69
# got '22876792454961'
# expected '22876792454961' (within '0')
# 22876792454961 - 22876792454961 = 2.16840434497100886801490560174e-19
FAILED at test 225

lib/Math/BigInt/t/bare_mbi...........
# Test 2140 got: '1' (../lib/Math/BigInt/t//bigintpm.inc at line 194 fail #1177)
# Expected: '2'
FAILED at test 2140

lib/Math/BigInt/t/bigintc............
# Test 151 got: '2' (../lib/Math/BigInt/t/bigintc.t at line 205)
# Expected: '3'
# ../lib/Math/BigInt/t/bigintc.t line 205 is: ok (${$C->_str($C->_root($x,$n))},'3');
FAILED at test 151

lib/Math/BigInt/t/bigintpm...........
# Test 2080 got: '2' (../lib/Math/BigInt/t//bigintpm.inc at line 194 fail #1147)
# Expected: '3'
FAILED at test 2080

lib/Math/BigInt/t/sub_mbi............
# Test 2080 got: '2' (../lib/Math/BigInt/t//bigintpm.inc at line 194 fail #1147)
# Expected: '3'
FAILED at test 2080

Failed 5 test scripts out of 766, 99.35% okay.

==========

The pow.t tests are somewhat surprising to me,
knowing as little as I do about floating point.
As the snippet below shows, the results are spot
on for 17 through 27 *except* for 18 and 26 (for
which they are very, very close to correct).

ok 224 - -3 ** 17 got[-129140163] expect[-129140163]
not ok 225 - -3 ** 18 got[387420489] expect[387420489]
# Failed at t/op/pow.t line 69
# got '387420489'
# expected '387420489' (within '0')
# 387420489 - 387420489 = -3.30872245021211069948563476828e-24
ok 226 - -3 ** 19 got[-1162261467] expect[-1162261467]
ok 227 - -3 ** 20 got[3486784401] expect[3486784401]
ok 228 - -3 ** 21 got[-10460353203] expect[-10460353203]
ok 229 - -3 ** 22 got[31381059609] expect[31381059609]
ok 230 - -3 ** 23 got[-94143178827] expect[-94143178827]
ok 231 - -3 ** 24 got[282429536481] expect[282429536481]
ok 232 - -3 ** 25 got[-847288609443] expect[-847288609443]
not ok 233 - -3 ** 26 got[2541865828329] expect[2541865828329]
# Failed at t/op/pow.t line 69
# got '2541865828329'
# expected '2541865828329' (within '0')
# 2541865828329 - 2541865828329 = -2.710505431213761085018632002175e-20
ok 234 - -3 ** 27 got[-7625597484987] expect[-7625597484987]

If it's of any help, adding -Dusemorebits does *not* help,
you get exactly the same errors. Without the uselongdouble,
the builds are flawless, with or without usemorebits. -- jpl

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=install
severity=none
---
Site configuration information for perl v5.8.1:

Configured by jpl at Thu Oct 2 06:37:45 EDT 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 1) configuration:
Platform:
osname=irix, osvers=6.5, archname=sgi6-irix-ld
uname='irix64 ent 6.5 07121148 ip27 '
config_args='-Duselongdouble'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=define
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc -n32', ccflags ='-D_BSD_TYPES -D_BSD_TIME -woff 1184,1552 -DHAS_LDBL_SPRINTF_BUG -I/usr/local/include -DLANGUAGE_C',
optimize='-O3 -OPT:Olimit=0:space=ON',
cppflags='-DHAS_LDBL_SPRINTF_BUG -D_BSD_TYPES -D_BSD_TIME -DHAS_LDBL_SPRINTF_BUG -I/usr/local/include -DLANGUAGE_C'
ccversion='MIPSpro Compilers: Version 7.3.1.3m', gccversion='', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=4, nvtype='long double', nvsize=16, Off_t='off_t', lseeksize=8
alignbytes=16, prototype=define
Linker and Libraries:
ld='cc -n32', ldflags =' -Wl,-woff,84 -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib32 /lib32 /lib /usr/lib
libs=-ldb -lm -lc
perllibs=-lm -lc
libc=/usr/lib32/libc.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-n32 -shared -L/usr/local/lib'

Locally applied patches:

---
@INC for perl v5.8.1:
lib
/usr/local/lib/perl5/5.8.1/sgi6-irix-ld
/usr/local/lib/perl5/5.8.1
/usr/local/lib/perl5/site_perl/5.8.1/sgi6-irix-ld
/usr/local/lib/perl5/site_perl/5.8.1
/usr/local/lib/perl5/site_perl
.

---
Environment for perl v5.8.1:
HOME=/home/jpl
LANG (unset)
LANGUAGE (unset)
LD_LIBRARYN32_PATH (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/jpl/perl/bin:/usr/common/dwb/bin:/home/jpl/IP27bin:/home/jpl/mips3bin:/home/jpl/bin:/usr/common/bin:/bin:/usr/local/bin:/usr/bin/X11:/etc:/usr/bsd:/usr/sbin:/usr/etc:.:/home/jpl/bzip
PERLIB=/home/jpl/perl/lib/site_perl
PERL_BADLANG (unset)
SHELL=/bin/ksh

Ed Allen Smith

unread,
Oct 4, 2003, 2:58:12 PM10/4/03
to perl5-...@perl.org, bugs-bi...@netlabs.develooper.com, j...@research.att.com
In message <rt-24091-65573....@rt.perl.org> (on 2 October 2003
12:40:39 -0000), perlbug-...@perl.org (j...@research.att.com (via RT))
wrote:

># New Ticket Created by j...@research.att.com
># Please include the string: [perl #24091]
># in the subject line of all future correspondence about this issue.
># <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24091 >

>

[...]

>Summary of my perl5 (revision 5.0 version 8 subversion 1) configuration:
> Platform:
> osname=irix, osvers=6.5, archname=sgi6-irix-ld
> uname='irix64 ent 6.5 07121148 ip27 '

IP27? R10000 chip, I'm guessing?

> config_args='-Duselongdouble'
> hint=recommended, useposix=true, d_sigaction=define
> usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
> useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
> use64bitint=undef use64bitall=undef uselongdouble=define
> usemymalloc=n, bincompat5005=undef
> Compiler:
> cc='cc -n32', ccflags ='-D_BSD_TYPES -D_BSD_TIME -woff 1184,1552
> -DHAS_LDBL_SPRINTF_BUG -I/usr/local/include -DLANGUAGE_C',

-DHAS_LDBL_SPRINTF_BUG but not -DHAS_LDBL_SPRINTF_BUG_LESS1?
Interesting. I've seen this here also with an R5000 machine (non-64-bit),
but hadn't had time to check things out further. I've done some
rearrangements on the local smoketest configuration files and will see what
happens; my time to work on this is likely to be limited, however (lab
reports to grade this weekend and an exam to help grade next week, plus
TAing a lab, my research work, etcetera).

-Allen

--
Allen Smith http://cesario.rutgers.edu/easmith/
February 1, 2003 Space Shuttle Columbia
Ad Astra Per Aspera To The Stars Through Asperity

John P. Linderman

unread,
Oct 5, 2003, 11:44:27 AM10/5/03
to Ed Allen Smith, perl5-...@perl.org, bugs-bi...@netlabs.develooper.com, j...@research.att.com
Allen Smith guessed:

> IP27? R10000 chip, I'm guessing?

Right on both counts.

Processor 0: 250 MHZ IP27
CPU: MIPS R10000 Processor Chip Revision: 3.4
FPU: MIPS R10010 Floating Point Chip Revision: 3.4

> -DHAS_LDBL_SPRINTF_BUG but not -DHAS_LDBL_SPRINTF_BUG_LESS1?
> Interesting. I've seen this here also with an R5000 machine (non-64-bit),
> but hadn't had time to check things out further. I've done some
> rearrangements on the local smoketest configuration files and will see what
> happens

I tried turning off -DHAS_LDBL_SPRINTF_BUG and all that did was
generate an *additional* failure from sprintf. Didn't try
-DHAS_LDBL_SPRINTF_BUG_LESS1, perhaps I'll give that a shot.

John P. Linderman

unread,
Oct 5, 2003, 1:13:00 PM10/5/03
to perlbug-...@perl.org, j...@research.att.com
Allen Smith sort of proposed...

> -DHAS_LDBL_SPRINTF_BUG but not -DHAS_LDBL_SPRINTF_BUG_LESS1?
> Interesting. I've seen this here also with an R5000 machine (non-64-bit),
> but hadn't had time to check things out further. I've done some
> rearrangements on the local smoketest configuration files and will see what
> happens; my time to work on this is likely to be limited, however (lab
> reports to grade this weekend and an exam to help grade next week, plus
> TAing a lab, my research work, etcetera).

cc='cc -n32', ccflags ='-D_BSD_TYPES -D_BSD_TIME -woff 1184,1552
-DHAS_LDBL_SPRINTF_BUG -I/usr/local/include -DLANGUAGE_C
-DHAS_LDBL_SPRINTF_BUG_LESS1',


cppflags='-DHAS_LDBL_SPRINTF_BUG -D_BSD_TYPES -D_BSD_TIME
-DHAS_LDBL_SPRINTF_BUG -I/usr/local/include -DLANGUAGE_C

-DHAS_LDBL_SPRINTF_BUG_LESS1'

No joy. Same failures, same places. -- jpl

Ed Allen Smith

unread,
Oct 5, 2003, 4:04:14 PM10/5/03
to j...@research.att.com, perl5-...@perl.org, bugs-bi...@netlabs.develooper.com
In message <2003100515...@raptor.research.att.com> (on 5 October

2003 11:44:27 -0400), j...@research.att.com (John P. Linderman) wrote:
>Allen Smith guessed:
>
>> IP27? R10000 chip, I'm guessing?
>
>Right on both counts.
>
>Processor 0: 250 MHZ IP27
>CPU: MIPS R10000 Processor Chip Revision: 3.4
>FPU: MIPS R10010 Floating Point Chip Revision: 3.4

I thought as much, and I'm duplicating the failure here with:

2 180 MHZ IP27 Processors
CPU: MIPS R10000 Processor Chip Revision: 2.6
FPU: MIPS R10010 Floating Point Chip Revision: 2.6

I'll be sending in smoketest reports on Monday morning (the automated
smoketesting on most of the machines here seems to have gotten accidentally
gonked by one thing or another, unfortunately).

>> -DHAS_LDBL_SPRINTF_BUG but not -DHAS_LDBL_SPRINTF_BUG_LESS1?
>> Interesting. I've seen this here also with an R5000 machine (non-64-bit),
>> but hadn't had time to check things out further. I've done some
>> rearrangements on the local smoketest configuration files and will see what
>> happens
>
>I tried turning off -DHAS_LDBL_SPRINTF_BUG and all that did was
>generate an *additional* failure from sprintf.

Since the library is still buggy (I'm currently bugging my dissertation
advisor to write up a Fortran test for it to see if it's also the case for
Fortran's I/O, before we send in a bug report to SGI), unsurprising.

>Didn't try -DHAS_LDBL_SPRINTF_BUG_LESS1, perhaps I'll give that a shot.

That one _should_ be getting activated (the sprintf for long doubles problem
turns out to be restricted to the range between -1 and 1, and the workaround
is inadvisable if the bug isn't present (-DHAS_LDBL_SPRINTF_BUG activates
the workaround, -DHAS_LDBL_SPRINTF_BUG_LESS1 deactivates it aside from the
range between -1 and 1)); not sure why it isn't, will have to take a look
when I have the time.

Ed Allen Smith

unread,
Oct 5, 2003, 4:15:52 PM10/5/03
to j...@research.att.com, perlbug-...@perl.org
In message <2003100517...@raptor.research.att.com> (on 5 October

Thanks!

>No joy. Same failures, same places. -- jpl

Huh. OK, there goes that theory... still weird that it isn't doing
-DHAS_LDBL_SPRINTF_BUG_LESS1, but apparently that's not the cause of the
problems. I will try to scratch up the time to look at this in more detail
this week.

Ed Allen Smith

unread,
Oct 6, 2003, 2:17:37 PM10/6/03
to perlbug-...@perl.org, perl_...@bloodgate.com

This is technically with patchlevel 21401 5.9.0. I note that there are more
failures when using -Dusemorebits (as in, including both -Duselongdouble and
-Duse64bitint). The pattern of the failures for 'pow.t' is rather
consistently that the value resulting is just _slightly_ off (more off the
larger the values being dealt with, which makes sense); it shows up at lower
numbers when using 64-bit-ints. I would think this was just a matter of the
pow.t tests needing to have an epsilon greater than 0, but the Math::BigInt
stuff indicates otherwise (this is from the first machine, with just
-Duselongdouble; -Dusemorebits gives the same results for Math::BigInt):

# Test 2140 got: '1' (../lib/Math/BigInt/t//bigintpm.inc at line 194 fail #1177)
# Expected: '2'

# Test 2146 got: '2' (../lib/Math/BigInt/t//bigintpm.inc at line 194 fail #1180)
# Expected: '3'


# Test 151 got: '2' (../lib/Math/BigInt/t/bigintc.t at line 205)
# Expected: '3'
# ../lib/Math/BigInt/t/bigintc.t line 205 is: ok (${$C->_str($C->_root($x,$n))},'3');

# Test 2080 got: '2' (../lib/Math/BigInt/t//bigintpm.inc at line 194 fail #1147)
# Expected: '3'

# Test 2140 got: '1' (../lib/Math/BigInt/t//bigintpm.inc at line 194 fail #1177)
# Expected: '2'

# Test 2146 got: '2' (../lib/Math/BigInt/t//bigintpm.inc at line 194 fail #1180)
# Expected: '3'


# Test 2080 got: '2' (../lib/Math/BigInt/t//bigintpm.inc at line 194 fail #1147)
# Expected: '3'

# Test 2140 got: '1' (../lib/Math/BigInt/t//bigintpm.inc at line 194 fail #1177)
# Expected: '2'

# Test 2146 got: '2' (../lib/Math/BigInt/t//bigintpm.inc at line 194 fail #1180)
# Expected: '3'

Tels says that this is probably because BigInt uses pow internally. Tels,
are the above failures all with _root?

2 270 MHZ IP30 Processors
CPU: MIPS R12000 Processor Chip Revision: 2.3
FPU: MIPS R12010 Floating Point Chip Revision: 0.0
uname -R: 6.5.20m

irix stdio/perlio -DDEBUGGING -Duseperlio -Duselongdouble
irix stdio/perlio -DDEBUGGING -Duseperlio -Duselongdouble -Dusethreads -Duseithreads
irix stdio/perlio -DDEBUGGING -Duseperlio -Duselongdouble -Dusethreads -Duseithreads -A append:ccflags=' -D_SGI_SOURCE -D_SGI_REENTRANT_FUNCTIONS -D_SGIAPI -D_POSIX1C -woff 1047' -A append:cppflags=' -D_SGI_SOURCE -D_SGI_REENTRANT_FUNCTIONS -D_SGIAPI -D_POSIX1C'
irix stdio/perlio -DDEBUGGING -Duseperlio -Duselongdouble -DCAST_INLINE
irix stdio/perlio -DDEBUGGING -Duseperlio -Duselongdouble -DCAST_INLINE -Dusethreads -Duseithreads
irix stdio/perlio -DDEBUGGING -Duseperlio -Duselongdouble -DCAST_INLINE -Dusethreads -Duseithreads -A append:ccflags=' -D_SGI_SOURCE -D_SGI_REENTRANT_FUNCTIONS -D_SGIAPI -D_POSIX1C -woff 1047' -A append:cppflags=' -D_SGI_SOURCE -D_SGI_REENTRANT_FUNCTIONS -D_SGIAPI -D_POSIX1C'
t/op/pow.............................FAILED at test 225
lib/Math/BigInt/t/bare_mbi...........FAILED at test 2140
lib/Math/BigInt/t/bigintc............FAILED at test 151
lib/Math/BigInt/t/bigintpm...........FAILED at test 2080
lib/Math/BigInt/t/sub_mbi............FAILED at test 2080
../lib/Math/BigInt/t/bigintc.....FAILED test 151

t/op/pow.............................FAILED at test 225

# Failed at ../t/op/pow.t line 69


# got '387420489'
# expected '387420489' (within '0')
# 387420489 - 387420489 = -3.30872245021211069948563476828e-24

# Failed at ../t/op/pow.t line 69


# got '2541865828329'
# expected '2541865828329' (within '0')
# 2541865828329 - 2541865828329 = -2.710505431213761085018632002175e-20

# Failed at ../t/op/pow.t line 69


# got '22876792454961'
# expected '22876792454961' (within '0')
# 22876792454961 - 22876792454961 = 2.16840434497100886801490560174e-19

Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
../t/op/pow.t 236 3 1.27% 225 233 235


irix stdio/perlio -DDEBUGGING -Duseperlio -Dusemorebits
irix stdio/perlio -DDEBUGGING -Duseperlio -Dusemorebits -Dusethreads -Duseithreads
irix stdio/perlio -DDEBUGGING -Duseperlio -Dusemorebits -Dusethreads -Duseithreads -A append:ccflags=' -D_SGI_SOURCE -D_SGI_REENTRANT_FUNCTIONS -D_SGIAPI -D_POSIX1C -woff 1047' -A append:cppflags=' -D_SGI_SOURCE -D_SGI_REENTRANT_FUNCTIONS -D_SGIAPI -D_POSIX1C'
irix stdio/perlio -DDEBUGGING -Duseperlio -Dusemorebits -DCAST_INLINE
irix stdio/perlio -DDEBUGGING -Duseperlio -Dusemorebits -DCAST_INLINE -Dusethreads -Duseithreads
irix stdio/perlio -DDEBUGGING -Duseperlio -Dusemorebits -DCAST_INLINE -Dusethreads -Duseithreads -A append:ccflags=' -D_SGI_SOURCE -D_SGI_REENTRANT_FUNCTIONS -D_SGIAPI -D_POSIX1C -woff 1047' -A append:cppflags=' -D_SGI_SOURCE -D_SGI_REENTRANT_FUNCTIONS -D_SGIAPI -D_POSIX1C'
irix stdio/perlio -DDEBUGGING -Duseperlio -Duse64bitall -Duselongdouble
irix stdio/perlio -DDEBUGGING -Duseperlio -Duse64bitall -Duselongdouble -Dusethreads -Duseithreads
irix stdio/perlio -DDEBUGGING -Duseperlio -Duse64bitall -Duselongdouble -Dusethreads -Duseithreads -A append:ccflags=' -D_SGI_SOURCE -D_SGI_REENTRANT_FUNCTIONS -D_SGIAPI -D_POSIX1C -woff 1047' -A append:cppflags=' -D_SGI_SOURCE -D_SGI_REENTRANT_FUNCTIONS -D_SGIAPI -D_POSIX1C'
t/op/pow.............................FAILED at test 244
lib/Math/BigInt/t/bare_mbi...........FAILED at test 2140
lib/Math/BigInt/t/bigintc............FAILED at test 151
lib/Math/BigInt/t/bigintpm...........FAILED at test 2080
lib/Math/BigInt/t/sub_mbi............FAILED at test 2080
../lib/Math/BigInt/t/bigintc.....FAILED test 151

t/op/pow.............................FAILED at test 244

# Failed at ../t/op/pow.t line 69
# got '-243'
# expected '-243' (within '0')
# -243 - -243 = -1.577721810442023610823457130566e-30
# Failed at ../t/op/pow.t line 69
# got '-19683'
# expected '-19683' (within '0')
# -19683 - -19683 = -2.019483917365790221854025127124e-28
# Failed at ../t/op/pow.t line 69


# got '387420489'
# expected '387420489' (within '0')
# 387420489 - 387420489 = -3.30872245021211069948563476828e-24

# Failed at ../t/op/pow.t line 69


# got '2541865828329'
# expected '2541865828329' (within '0')
# 2541865828329 - 2541865828329 = -2.710505431213761085018632002175e-20

# Failed at ../t/op/pow.t line 69


# got '22876792454961'
# expected '22876792454961' (within '0')
# 22876792454961 - 22876792454961 = 2.16840434497100886801490560174e-19

Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
../t/op/pow.t 268 5 1.87% 244 248 257 265
267
CPU: MIPS R5000 Processor Chip Revision: 2.1
FPU: MIPS R5000 Floating Point Coprocessor Revision: 1.0
1 200 MHZ IP32 Processor
uname -R: 6.5.20m

irix stdio/perlio -Duseperlio -Duselongdouble
irix stdio/perlio -DDEBUGGING -Duseperlio -Duselongdouble
irix stdio/perlio -Duseperlio -Duselongdouble -A define:optimize='-O3 -OPT:space=OFF:Olimit=0'
irix stdio/perlio -DDEBUGGING -Duseperlio -Duselongdouble -A define:optimize='-O3 -OPT:space=OFF:Olimit=0'
t/op/pow.............................FAILED at test 225
lib/Math/BigInt/t/bare_mbi...........FAILED at test 2140
lib/Math/BigInt/t/bigintc............FAILED at test 151
lib/Math/BigInt/t/bigintpm...........FAILED at test 2080
lib/Math/BigInt/t/sub_mbi............FAILED at test 2080
../lib/Math/BigInt/t/bigintc.....FAILED test 151

Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
../t/op/pow.t 236 3 1.27% 225 233 235

# Failed at ../t/op/pow.t line 69


# got '387420489'
# expected '387420489' (within '0')
# 387420489 - 387420489 = -3.30872245021211069948563476828e-24

# Failed at ../t/op/pow.t line 69


# got '2541865828329'
# expected '2541865828329' (within '0')
# 2541865828329 - 2541865828329 = -2.710505431213761085018632002175e-20

# Failed at ../t/op/pow.t line 69


# got '22876792454961'
# expected '22876792454961' (within '0')
# 22876792454961 - 22876792454961 = 2.16840434497100886801490560174e-19


irix stdio/perlio -Duseperlio -Dusemorebits
irix stdio/perlio -DDEBUGGING -Duseperlio -Dusemorebits
t/op/pow.............................FAILED at test 244
lib/Math/BigInt/t/bare_mbi...........FAILED at test 2140
lib/Math/BigInt/t/bigintc............FAILED at test 151
lib/Math/BigInt/t/bigintpm...........FAILED at test 2080
lib/Math/BigInt/t/sub_mbi............FAILED at test 2080
../lib/Math/BigInt/t/bigintc.....FAILED test 151

Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
../t/op/pow.t 268 5 1.87% 244 248 257 265
267

# Failed at ../t/op/pow.t line 69
# got '-243'
# expected '-243' (within '0')
# -243 - -243 = -1.577721810442023610823457130566e-30
# Failed at ../t/op/pow.t line 69
# got '-19683'
# expected '-19683' (within '0')
# -19683 - -19683 = -2.019483917365790221854025127124e-28
# Failed at ../t/op/pow.t line 69


# got '387420489'
# expected '387420489' (within '0')
# 387420489 - 387420489 = -3.30872245021211069948563476828e-24

# Failed at ../t/op/pow.t line 69


# got '2541865828329'
# expected '2541865828329' (within '0')
# 2541865828329 - 2541865828329 = -2.710505431213761085018632002175e-20

# Failed at ../t/op/pow.t line 69


# got '22876792454961'
# expected '22876792454961' (within '0')
# 22876792454961 - 22876792454961 = 2.16840434497100886801490560174e-19


irix stdio -Duseperlio -Dusemorebits -A define:optimize='-O3 -OPT:space=OFF:Olimit=0'
t/op/pow.............................FAILED at test 244
lib/Math/BigInt/t/bare_mbi...........FAILED at test 2140
lib/Math/BigInt/t/bigintc............FAILED at test 151
lib/Math/BigInt/t/bigintpm...........FAILED at test 2080
lib/Math/BigInt/t/sub_mbi............FAILED at test 2080
../lib/Math/BigInt/t/bigintc.....FAILED test 151

Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
../t/op/pow.t 268 5 1.87% 244 248 257 265
267
# Failed at ../t/op/pow.t line 69
# got '-243'
# expected '-243' (within '0')
# -243 - -243 = -1.577721810442023610823457130566e-30
# Failed at ../t/op/pow.t line 69
# got '-19683'
# expected '-19683' (within '0')
# -19683 - -19683 = -2.019483917365790221854025127124e-28
# Failed at ../t/op/pow.t line 69


# got '387420489'
# expected '387420489' (within '0')
# 387420489 - 387420489 = -3.30872245021211069948563476828e-24

# Failed at ../t/op/pow.t line 69


# got '2541865828329'
# expected '2541865828329' (within '0')
# 2541865828329 - 2541865828329 = -2.710505431213761085018632002175e-20

# Failed at ../t/op/pow.t line 69


# got '22876792454961'
# expected '22876792454961' (within '0')
# 22876792454961 - 22876792454961 = 2.16840434497100886801490560174e-19

CPU: MIPS R5000 Processor Chip Revision: 10.0
FPU: MIPS R5000 Floating Point Coprocessor Revision: 10.0
1 300 MHZ IP32 Processor
uname -R: 6.5.20m

irix stdio/perlio -Duseperlio -Duselongdouble
irix stdio/perlio -DDEBUGGING -Duseperlio -Duselongdouble
t/op/pow.............................FAILED at test 225
lib/Math/BigInt/t/bare_mbi...........FAILED at test 2140
lib/Math/BigInt/t/bigintc............FAILED at test 151
lib/Math/BigInt/t/bigintpm...........FAILED at test 2080
lib/Math/BigInt/t/sub_mbi............FAILED at test 2080
../lib/Math/BigInt/t/bigintc.....FAILED test 151

Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
../t/op/pow.t 236 3 1.27% 225 233 235

# Failed at ../t/op/pow.t line 69


# got '387420489'
# expected '387420489' (within '0')
# 387420489 - 387420489 = -3.30872245021211069948563476828e-24

# Failed at ../t/op/pow.t line 69


# got '2541865828329'
# expected '2541865828329' (within '0')
# 2541865828329 - 2541865828329 = -2.710505431213761085018632002175e-20

# Failed at ../t/op/pow.t line 69


# got '22876792454961'
# expected '22876792454961' (within '0')
# 22876792454961 - 22876792454961 = 2.16840434497100886801490560174e-19


irix stdio/perlio -Duseperlio -Dusemorebits
irix stdio/perlio -DDEBUGGING -Duseperlio -Dusemorebits
t/op/pow.............................FAILED at test 244
lib/Math/BigInt/t/bare_mbi...........FAILED at test 2140
lib/Math/BigInt/t/bigintc............FAILED at test 151
lib/Math/BigInt/t/bigintpm...........FAILED at test 2080
lib/Math/BigInt/t/sub_mbi............FAILED at test 2080
../lib/Math/BigInt/t/bigintc.....FAILED test 151

Failed Test Stat Wstat Total Fail Failed List of Failed
------------------------------------------------------------------------------
../t/op/pow.t 268 5 1.87% 244 248 257 265
267

# Failed at ../t/op/pow.t line 69
# got '-243'
# expected '-243' (within '0')
# -243 - -243 = -1.577721810442023610823457130566e-30
# Failed at ../t/op/pow.t line 69
# got '-19683'
# expected '-19683' (within '0')
# -19683 - -19683 = -2.019483917365790221854025127124e-28
# Failed at ../t/op/pow.t line 69


# got '387420489'
# expected '387420489' (within '0')
# 387420489 - 387420489 = -3.30872245021211069948563476828e-24

# Failed at ../t/op/pow.t line 69


# got '2541865828329'
# expected '2541865828329' (within '0')
# 2541865828329 - 2541865828329 = -2.710505431213761085018632002175e-20

# Failed at ../t/op/pow.t line 69


# got '22876792454961'
# expected '22876792454961' (within '0')
# 22876792454961 - 22876792454961 = 2.16840434497100886801490560174e-19


irix stdio/perlio -Dusethreads -Duseithreads -Duseperlio -Duselongdouble
irix stdio/perlio -DDEBUGGING -Dusethreads -Duseithreads -Duseperlio -Duselongdouble
t/op/pow.............................FAILED at test 225
lib/Math/BigInt/t/bare_mbi...........FAILED at test 2140
lib/Math/BigInt/t/bigintc............FAILED at test 151
lib/Math/BigInt/t/bigintpm...........FAILED at test 2080
lib/Math/BigInt/t/sub_mbi............FAILED at test 2080
../lib/Math/BigInt/t/bigintc.....FAILED test 151

Failed Test Stat Wstat Total Fail Failed List of Failed
------------------------------------------------------------------------------
../t/op/pow.t 236 3 1.27% 225 233 235

# Failed at ../t/op/pow.t line 69


# got '387420489'
# expected '387420489' (within '0')
# 387420489 - 387420489 = -3.30872245021211069948563476828e-24

# Failed at ../t/op/pow.t line 69


# got '2541865828329'
# expected '2541865828329' (within '0')
# 2541865828329 - 2541865828329 = -2.710505431213761085018632002175e-20

# Failed at ../t/op/pow.t line 69


# got '22876792454961'
# expected '22876792454961' (within '0')
# 22876792454961 - 22876792454961 = 2.16840434497100886801490560174e-19


irix stdio/perlio -Dusethreads -Duseithreads -Duseperlio -Dusemorebits
irix stdio/perlio -DDEBUGGING -Dusethreads -Duseithreads -Duseperlio -Dusemorebits
t/op/pow.............................FAILED at test 244
lib/Math/BigInt/t/bare_mbi...........FAILED at test 2140
lib/Math/BigInt/t/bigintc............FAILED at test 151
lib/Math/BigInt/t/bigintpm...........FAILED at test 2080
lib/Math/BigInt/t/sub_mbi............FAILED at test 2080
../lib/Math/BigInt/t/bigintc.....FAILED test 151

Failed Test Stat Wstat Total Fail Failed List of Failed
------------------------------------------------------------------------------
../t/op/pow.t 268 5 1.87% 244 248 257 265
267
# Failed at ../t/op/pow.t line 69
# got '-243'
# expected '-243' (within '0')
# -243 - -243 = -1.577721810442023610823457130566e-30
# Failed at ../t/op/pow.t line 69
# got '-19683'
# expected '-19683' (within '0')
# -19683 - -19683 = -2.019483917365790221854025127124e-28
# Failed at ../t/op/pow.t line 69


# got '387420489'
# expected '387420489' (within '0')
# 387420489 - 387420489 = -3.30872245021211069948563476828e-24

# Failed at ../t/op/pow.t line 69


# got '2541865828329'
# expected '2541865828329' (within '0')
# 2541865828329 - 2541865828329 = -2.710505431213761085018632002175e-20

# Failed at ../t/op/pow.t line 69


# got '22876792454961'
# expected '22876792454961' (within '0')
# 22876792454961 - 22876792454961 = 2.16840434497100886801490560174e-19

Ed Allen Smith

unread,
Oct 6, 2003, 2:39:00 PM10/6/03
to perlbug-...@perl.org, andreas...@anima.de

BTW, in regard to the pow.t tests, the following is weird:

my @pow = ([3,30,1e-14],
[4,32,0],
[5,20,1e-14],
[2.5, 10,,1e-14],
[-2, 69,0],
[-3, 30,0],
);

In the above, the test for powers of 3 has an epsilon of 1e-14 (which all of
the pow.t test failures seen are well below). But the test for powers of -3
has an epsilon of 0. This is inconsistent. Why should -3**$x be more precisely
determined than 3**$x? The above was added with change 20169, BTW.

-Allen

Abhijit Menon-Sen

unread,
Oct 7, 2003, 1:19:54 AM10/7/03
to Ed Allen Smith, perlbug-...@perl.org, perl5-...@perl.org
At 2003-10-06 14:39:00 -0400, eas...@beatrice.rutgers.edu wrote:
>
> Why should -3**$x be more precisely determined than 3**$x? The above
> was added with change 20169, BTW.

...and removed with #21419. Thanks.

-- ams

Ed Allen Smith

unread,
Oct 7, 2003, 1:54:22 AM10/7/03
to perlbug-...@perl.org, perl5-...@perl.org
In message <2003100710...@lustre.dyn.wiw.org> (on 7 October 2003

Quite welcome; thank you! Now we just need to figure out why things are
going wrong with Math::BigInt...

John P. Linderman

unread,
Oct 7, 2003, 6:20:19 AM10/7/03
to perlbug-...@perl.org
>
> BTW, in regard to the pow.t tests, the following is weird:
>
> my @pow = ([3,30,1e-14],
> [4,32,0],
> [5,20,1e-14],
> [2.5, 10,,1e-14],
> [-2, 69,0],
> [-3, 30,0],
> );
>
> In the above, the test for powers of 3 has an epsilon of 1e-14 (which all of
> the pow.t test failures seen are well below). But the test for powers of -3
> has an epsilon of 0. This is inconsistent. Why should -3**$x be more precisely

> determined than 3**$x? The above was added with change 20169, BTW.

The [2.5, 10,,1e-14] test, with its extra comma, is particularly weird :-)
-- jpl

Tels

unread,
Oct 7, 2003, 2:12:13 PM10/7/03
to Ed Allen Smith, perl5-...@perl.org
-----BEGIN PGP SIGNED MESSAGE-----

Moin,

Bingo:

I noticed that _pow() is not tested in bigintc.t at all, and added some tests
for it, and also some more tests with _root(). Which promptly fail, even on
my 32 bit system/perl:

# _pow (and _root)
$x = $C->_new(\"81"); $n = $C->_new(\"3"); # 81 ** 3 == 531441
ok (${$C->_str($C->_pow($x,$n))},81 ** 3);
ok (${$C->_str($C->_root($x,$n))},81); # (81 ** 3) ** 1/3 == 81
ok (${$C->_str($C->_pow($x,$n))},81 ** 3);
ok (${$C->_str($C->_pow($x,$n))},'150094635296999121'); # 531441 ** 3 ==

This produces:

not ok 153
# Test 153 got: '80' (t/bigintc.t at line 219)
# Expected: '81'
not ok 154
# Test 154 got: '512000' (t/bigintc.t at line 220)
# Expected: '531441'
not ok 155
# Test 155 got: '134217728000000000' (t/bigintc.t at line 221)
# Expected: '150094635296999121'

Damn, and I was so proud that v1.67 would be (probably) the first BigInt
release with no bugfixes over the last version *sigh*

Oh, something fishy is going on:

print $x->[0] ** (1 / $n->[0]), "\n";
$x->[0] = int( $x->[0] ** (1 / $n->[0]) );
print $x->[0],"\n";

This produces for $x == [ 81 **3 ] and $n == [3] the following output:

81
80

Huh?!? This is with Perl v5.8.0...

Best wishes,

Tels

- --
Signed on Tue Oct 7 20:06:36 2003 with key 0x93B84C15.
Visit my photo gallery at http://bloodgate.com/photos/
PGP key on http://bloodgate.com/tels.asc or per email.

"Remember: If the game let's you do it, it's not cheating." -- Xarax

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
Comment: When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.

iQEVAwUBP4MB/XcLPEOTuEwVAQF1ogf/S4MeQIvUDcYDIIK9CTPbfETse1sLZ1fV
I2Cxb4CVrqor/z+/nBLtIz5o9qSp2gpgWUPMPlWj/tcsi8glNzj/ZXpNkmLjC4ID
FFfPaZPMTAOjybg9jovcw2BrSqy0Uo4/L5f8Yxyf7t8q4uC+dJEJuUPVJbOEKdr4
+RU5qYKppQ7ktoW0wth+9bEAPSuV/seRrO2cm7HVQ7MaZAMM7WLBiD9fEJnU8I7c
JcVX5Y45qKyt6Q+CJdiV7qi+kenxaU0psGmcch0PgksjsnxL+fzS+7hs3NAj4iBB
IVtUo9tXgVwcidzg0b9xV9/KVFqwBMJjWR9I8zYnzGP0/IImFf9PMQ==
=8Z0M
-----END PGP SIGNATURE-----

Tels

unread,
Oct 7, 2003, 2:20:00 PM10/7/03
to Ed Allen Smith, perl5-...@perl.org
-----BEGIN PGP SIGNED MESSAGE-----

Moin,

On Tuesday 07 October 2003 20:12, Tels wrote:

This is very wierd:

# perl -MPOSIX -le '$a = (81 ** 3) ** (1/3); print join(" ", $a, int ($a),
POSIX::floor($a), sprintf("%f",$a), sprintf ("%.0f",$a))'
81 80 80 81.000000 81

Why is $a sometimes 81, and sometimes 80? Why does int(81) produce 80?

This is with perl v5.8.1, not v5.8.0 as I claimed:

te@null:~/perl/math/Math-BigInt-1.67> perl -V


Summary of my perl5 (revision 5.0 version 8 subversion 1) configuration:
Platform:

osname=linux, osvers=2.4.20-4gb-athlon, archname=i686-linux
uname='linux null 2.4.20-4gb-athlon #1 wed aug 6 18:27:52 utc 2003 i686
unknown unknown gnulinux '
config_args='-ds -e'


hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef

use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include
- -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O3',
cppflags='-fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='3.3 20030226 (prerelease) (SuSE Linux)',
gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.3.2'
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):
Compile-time options: USE_LARGE_FILES
Built under linux
Compiled at Sep 27 2003 20:55:34
@INC:
/usr/local/lib/perl5/5.8.1/i686-linux
/usr/local/lib/perl5/5.8.1
/usr/local/lib/perl5/site_perl/5.8.1/i686-linux
/usr/local/lib/perl5/site_perl/5.8.1
/usr/local/lib/perl5/site_perl
.

Best wishes,

Tels

- --
Signed on Tue Oct 7 20:17:51 2003 with key 0x93B84C15.


Visit my photo gallery at http://bloodgate.com/photos/
PGP key on http://bloodgate.com/tels.asc or per email.

"Wo die Schononen schön wohnen."

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
Comment: When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.

iQEVAwUBP4MD0HcLPEOTuEwVAQGC1wf+OvQvGY27qhV+vrbzkrOA4RA/3EKlUIpa
MXcMjcqQjh91aOoEAkWLKeFlZOVZ7oBmTJcoYz0tGbgWMYPUthYape/Weo95+Rp9
4CbxCcuX12iYK9gsXVxa+vMvRdNa9+Wyyt7Dc1oapWj9+cokIqo/G86eaD/yJ5+M
liEhFXQScv3rz4w4rOZLroMiOXVPd+/BQhZF0XHNMIxV1qx6brLMO7m3pTdg5r1X
/QA9Tt0yNQ3B131/Mr7NpCuCKQLyGAxx6AKae3/22s8iuHt8smWJgqkW/8cxwuvN
EEyZjAX/f5g/YUqwEhTSzTYYWiQi0S8tra6Y4VIZMXKBWvEsBM8Sog==
=2V7I
-----END PGP SIGNATURE-----

Paul Johnson

unread,
Oct 7, 2003, 2:37:54 PM10/7/03
to Tels, Ed Allen Smith, perl5-...@perl.org
On Tue, Oct 07, 2003 at 08:20:00PM +0200, Tels wrote:

> On Tuesday 07 October 2003 20:12, Tels wrote:
>
> This is very wierd:
>
> # perl -MPOSIX -le '$a = (81 ** 3) ** (1/3); print join(" ", $a, int ($a),
> POSIX::floor($a), sprintf("%f",$a), sprintf ("%.0f",$a))'
> 81 80 80 81.000000 81
>
> Why is $a sometimes 81, and sometimes 80? Why does int(81) produce 80?

Because (81 ** 3) ** (1/3) != 81

$ perl -le 'print ((81 ** 3) ** (1/3) != 81)'
1

$ perl -MPOSIX -le '$a = (81 ** 3) ** (1/3); print join(" ", $a, int ($a), POSIX::floor($a), sprintf("%f",$a), sprintf("%.20f",$a), sprintf ("%.0f",$a))'
81 80 80 81.000000 80.99999999999998578915 81

--
Paul Johnson - pa...@pjcj.net
http://www.pjcj.net

Yitzchak Scott-Thoennes

unread,
Oct 7, 2003, 2:42:09 PM10/7/03
to Tels, perl-p...@perl.org
On Tue, Oct 07, 2003 at 08:12:13PM +0200, Tels <perl_...@bloodgate.com> wrote:
> Oh, something fishy is going on:
>
> print $x->[0] ** (1 / $n->[0]), "\n";
> $x->[0] = int( $x->[0] ** (1 / $n->[0]) );
> print $x->[0],"\n";
>
> This produces for $x == [ 81 **3 ] and $n == [3] the following output:
>
> 81
> 80
>
> Huh?!? This is with Perl v5.8.0...

$ perl -we'printf "%.16g\n", (81**3)**(1/3)'
80.99999999999999

Tels

unread,
Oct 7, 2003, 2:53:06 PM10/7/03
to Ed Allen Smith, perl5-...@perl.org, Paul Johnson, Yitzchak Scott-Thoennes
-----BEGIN PGP SIGNED MESSAGE-----

Moin all,

I am now between a rock and a hard place:

POSIX::floor () converts the 81 as result to 80, as does int().
sprinf("%.0f"), OTOH, converts this fine to 81, but it
fails for things like 9.91234 - this should be truncated to 9, but sprintf
rounds it to 10.

Here is a case where the new sprintf("%.0f") fails, but the former int()
works:

# perl -Mbigint -le 'print 9999->broot()'
99
# perl -Ilib -Mbigint -le 'print 9999->broot()'
100

And here is one where the old one fails, but the new one works:

# perl -Mbigint -le 'print +(81 ** 3)->broot(3)'
80
# perl -Ilib -Mbigint -le 'print +(81 ** 3)->broot(3)'
81

:-(

Hm, Paul Johnson <pa...@pjcj.net> wrote:

>Because (81 ** 3) ** (1/3) != 81
>
>$ perl -le 'print ((81 ** 3) ** (1/3) != 81)'
>1
>
>$ perl -MPOSIX -le '$a = (81 ** 3) ** (1/3); print join(" ", $a, int ($a),
>POSIX::floor($a), sprintf("%f",$a), sprintf("%.20f",$a), sprintf
>("%.0f",$a))'
>81 80 80 81.000000 80.99999999999998578915 81

Argl.

So, if I first round the result to 8 digits after the ".", I get rid of the
small variances, and can the truncate the result properly? Or should I just
add 0.5? Decisions....

$x->[0] = int ( sprintf ("%.8f", $x->[0] ** (1 / $n->[0]) ) );

This seems to work for both cases on my system.....

Best wishes,

Tels


- --
Signed on Tue Oct 7 20:25:12 2003 with key 0x93B84C15.


Visit my photo gallery at http://bloodgate.com/photos/
PGP key on http://bloodgate.com/tels.asc or per email.

"My glasses, my glasses. I cannot see without my glasses." - "My glasses,
my glasses. I cannot be seen without my glasses."

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
Comment: When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.

iQEVAwUBP4MLkncLPEOTuEwVAQEzdAf+LvKuV3zbxYOSvJYBrb0PBs29Jo70UTdl
hKVlIK8aJnslvkWXiusnnApFpxMgby17HgE96KiRLq7Iz9RK+9XOVXq0XQhrmhmL
UVE634ZGMlhBiwidyzFz82j5ngO/2wuzxHHBDI2W6w811ItEs7e0tpSC1cx4cIH/
HI1gNVhzZ77QtUEZtJsI1Vsw+q5dEHnVV2R2MPagxl1reO1vcLVS2ehW2tHLAZW3
+bN3YGU9x4j1xNZvejcVgP4PpECl7b1ywb5dJfO0kZ1U3HKcdzX5TAV2ZQbgybiR
DIwcompM7k6AZqYO6PD4kP1iFCH4l3UOUpTtjAh1SIVsxJWYKfeoNQ==
=MjYf
-----END PGP SIGNATURE-----

Yitzchak Scott-Thoennes

unread,
Oct 7, 2003, 3:20:17 PM10/7/03
to Tels, perl-p...@perl.org, Paul Johnson
On Tue, Oct 07, 2003 at 08:53:06PM +0200, Tels <perl_...@bloodgate.com> wrote:
> POSIX::floor () converts the 81 as result to 80, as does int().
> sprinf("%.0f"), OTOH, converts this fine to 81, but it
> fails for things like 9.91234 - this should be truncated to 9, but sprintf
> rounds it to 10.

sprintf is supposed to round, not truncate (though "in an
implementation-defined manner").

> Here is a case where the new sprintf("%.0f") fails, but the former int()
> works:
>
> # perl -Mbigint -le 'print 9999->broot()'
> 99
> # perl -Ilib -Mbigint -le 'print 9999->broot()'
> 100
>
> And here is one where the old one fails, but the new one works:
>
> # perl -Mbigint -le 'print +(81 ** 3)->broot(3)'
> 80
> # perl -Ilib -Mbigint -le 'print +(81 ** 3)->broot(3)'
> 81

If you want to truncate, but allow slight wiggle-room for error in the
lowest 1-3 bits, try something like:

$result = "$result" if $result !~ /./;

or use an explicit ratio-to-nearest-integer check:

$result = floor($result+.5) if abs($result/floor($result+.5)) < 1e-14

Yitzchak Scott-Thoennes

unread,
Oct 7, 2003, 3:25:07 PM10/7/03
to Tels, perl-p...@perl.org, Paul Johnson
On Tue, Oct 07, 2003 at 12:20:17PM -0700, Yitzchak Scott-Thoennes <stho...@efn.org> wrote:
> $result = floor($result+.5) if abs($result/floor($result+.5)) < 1e-14

That should have been:

$result = floor($result+.5) if $result != 0 &&
abs(floor($result+.5)/$result) < 1e-14;

Ed Allen Smith

unread,
Oct 7, 2003, 4:04:30 PM10/7/03
to perl_...@bloodgate.com, perl5-...@perl.org, pa...@pjcj.net, stho...@efn.org
In message <200310072...@bloodgate.com> (on 7 October 2003 20:53:06

+0200), perl_...@bloodgate.com (Tels) wrote:
>I am now between a rock and a hard place:

Sigh... yeah.

>POSIX::floor () converts the 81 as result to 80, as does int().
>sprinf("%.0f"), OTOH, converts this fine to 81, but it
>fails for things like 9.91234 - this should be truncated to 9, but sprintf
>rounds it to 10.
>
>Here is a case where the new sprintf("%.0f") fails, but the former int()
>works:
>
> # perl -Mbigint -le 'print 9999->broot()'
> 99
> # perl -Ilib -Mbigint -le 'print 9999->broot()'
> 100
>
>And here is one where the old one fails, but the new one works:
>
> # perl -Mbigint -le 'print +(81 ** 3)->broot(3)'
> 80
> # perl -Ilib -Mbigint -le 'print +(81 ** 3)->broot(3)'
> 81
>
>:-(

Yes.

>Hm, Paul Johnson <pa...@pjcj.net> wrote:
>
>>Because (81 ** 3) ** (1/3) != 81
>>
>>$ perl -le 'print ((81 ** 3) ** (1/3) != 81)'
>>1
>>
>>$ perl -MPOSIX -le '$a = (81 ** 3) ** (1/3); print join(" ", $a, int ($a),
>>POSIX::floor($a), sprintf("%f",$a), sprintf("%.20f",$a), sprintf
>>("%.0f",$a))'
>>81 80 80 81.000000 80.99999999999998578915 81
>
>Argl.

Quite.

>So, if I first round the result to 8 digits after the ".", I get rid of the
>small variances, and can the truncate the result properly? Or should I just
>add 0.5?

I wouldn't add a full 0.5, if one wants consistency with previous results
when said previous results were correct or when said previous results were
for cases where using algebra wouldn't give you integers anyway. Some
smaller epsilon seems preferable.

>Decisions....
>
> $x->[0] = int ( sprintf ("%.8f", $x->[0] ** (1 / $n->[0]) ) );
>
>This seems to work for both cases on my system.....

Although there are problems with sprintf rounding with long doubles on some
systems (irix and others; there's a check for this in the irix hints file
that turns on a workaround via -DHAS_LDBL_SPRINTF_BUG, but it's not a 100%
fix by any means). I'm thinking the epsilon addition I mentioned in my email
to you, or the method that Yitzchak Scott-Thoennes mentioned, would be
better.

Tels

unread,
Oct 7, 2003, 5:41:46 PM10/7/03
to Yitzchak Scott-Thoennes, perl5-...@perl.org, Ed Allen Smith
-----BEGIN PGP SIGNED MESSAGE-----

Moin,

But why does

perl -le "print +(81**3)**(1/3)"

print 81 and not 80.99999999999999? perldoc print only says that it will print
"a string or list of strings" but doesn't mention how print creates the
strings. I guess it uses sprintf ("%.0f") or something internally when it
sees a scalar containing a float, but I couldn't find the place where is
documented how print converts floats to a string. (I am not saying that it
isn't in the doc - I just don't know where to look for it. Where is
perlgoogle when you need it...) At least the print surprised me. But it is
not hard to suprise simpletons like me :)

Also interesting to note is:

te@null:~> perl -Mbignum -le 'print +(81 ** 3) ** (1/3)'
80.99999999999999999999999999999999999996
te@null:~> perl -Mbignum=a,50 -le 'print +(81 ** 3) ** (1/3)'
81.000000000000000000000000000000000000000000000002

Bevor I blame Perl's math returning wonky results, I should check my own
code :-)

Thank you again for your time and bearing with me,

Tels

- --
Signed on Tue Oct 7 23:31:35 2003 with key 0x93B84C15.


Visit my photo gallery at http://bloodgate.com/photos/
PGP key on http://bloodgate.com/tels.asc or per email.

"Where shall I put you? Under H, like Hot, Sexy Mama?"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
Comment: When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.

iQEVAwUBP4MzGncLPEOTuEwVAQGUtgf8CaT4r2bbqVPvgZHJXCNXOLss9O2VoQXf
QdDZvA7KQDLkcIzsjdaQcGUXteuCwTqB7kScEUrd877RUpm0rZBCdP67ys5Y3j0s
QW4Pz1oB/961bjj4htIgIK6+LHm9L2AMeXm73CxiwYyBwd98iEvpBjEqLBAdJhas
IvSMXb9wg66cnXGvDx8fKbgofIi34eTMvn4ZQYMQu3ohxO15HdTl9fOXerSv3hFo
sH5l9XwmTL4wYfKvnqxjwxwW1hhaio02qpWrAf7ubliCZBlZVgnTa+fN4LrISP6d
x5KtrOliiPiiTUdLH6kvN4UVOyNwnidohmf6Wlg8qsjYicfxfq9ipg==
=gFmb
-----END PGP SIGNATURE-----

Yitzchak Scott-Thoennes

unread,
Oct 7, 2003, 6:31:06 PM10/7/03
to Tels, perl5-...@perl.org, Ed Allen Smith
On Tue, Oct 07, 2003 at 11:41:46PM +0200, Tels <perl_...@bloodgate.com> wrote:
> But why does
>
> perl -le "print +(81**3)**(1/3)"
>
> print 81 and not 80.99999999999999? perldoc print only says that it will print

See $# in perlvar.pod (admittedly a hard-to-find piece of documentation).

IEEE doubles have 53 bits of precision. This works out to just shy of
15.9+ digits, and perl will use 15 digits when stringizing an NV
(actually something like sprintf "%.15g"). If perl tried to round up
to 16 digits, there would be many test failures, since e.g. print 8.2
would give 8.199999999999999.

Ed Allen Smith

unread,
Oct 7, 2003, 6:33:45 PM10/7/03
to perl_...@bloodgate.com, stho...@efn.org, perl5-...@perl.org
In message <200310072...@bloodgate.com> (on 7 October 2003 23:41:46

+0200), perl_...@bloodgate.com (Tels) wrote:
>But why does
>
> perl -le "print +(81**3)**(1/3)"
>
>print 81 and not 80.99999999999999? perldoc print only says that it will
>print "a string or list of strings" but doesn't mention how print creates
>the strings. I guess it uses sprintf ("%.0f") or something internally when
>it sees a scalar containing a float, but I couldn't find the place where is
>documented how print converts floats to a string. (I am not saying that it
>isn't in the doc - I just don't know where to look for it. Where is
>perlgoogle when you need it...)

Quite. It's buried in one of the deprecated variables in perlvar:

$# The output format for printed numbers. This variable is a
half-hearted attempt to emulate awk's OFMT variable. There are
times, however, when awk and Perl have differing notions of
what is in fact numeric. The initial value is %.ng, where n is
the value of the macro DBL_DIG from your system's float.h.
This is different from awk's default OFMT setting of %.6g, so
you need to set "$#" explicitly to get awk's value. (Mnemonic:
# is the number sign.)

Ed Allen Smith

unread,
Oct 7, 2003, 6:33:33 PM10/7/03
to perl_...@bloodgate.com, perl5-...@perl.org, pa...@pjcj.net, stho...@efn.org

I'll change my earlier suggestion of how to handle this in Math::BigInt. I
suggest changing the current code in _root from:

# fit's into one Perl scalar, so result can be computed directly
$x->[0] = int( $x->[0] ** (1 / $n->[0]) );

to:

if ($x->[0] == 0) {
return 0;
}
# fits into one Perl scalar, so result can be computed directly
my $temp = $x->[0] ** (1 / $n->[0]);
my $a = int($temp);
my $b = int($temp + (($temp > 0) ? 0.5 : -0.5));
if ($a == $b) {
$x->[0] = $a;
} elsif (abs(($a**$n->[0]) - $x->[0]) > abs(($b**$n->[0]) - $x->[0])) {
$x->[0] = $b;
} else {
$x->[0] = $a;
}
return $x;

In other words, if adding 0.5 (equivalently, subtracting, if the result is
negative) will give a more arithmetically correct result after truncating, do
it; otherwise, don't. (It's likely that the same sort of thing would be
helpful for the _sqrt function.)

Alex Vandiver

unread,
Oct 7, 2003, 6:41:05 PM10/7/03
to Tels, p5p
On Tue, 2003-10-07 at 17:41, Tels wrote:
> But why does
>
> perl -le "print +(81**3)**(1/3)"
>
> print 81 and not 80.99999999999999?

$ perl -le '$#="%.16g"; print +(81**3)**(1/3)'
80.99999999999999

perldoc perlvar says:

$OFMT
$# The output format for printed numbers. This vari-


able is a half-hearted attempt to emulate awk's
OFMT variable. There are times, however, when awk

and Perl have differing notions of what counts as
numeric. The initial value is "%.ng", where n is


the value of the macro DBL_DIG from your system's
float.h. This is different from awk's default

OFMT setting of "%.6g", so you need to set $#


explicitly to get awk's value. (Mnemonic: # is
the number sign.)

Use of $# is deprecated.

- Alex V.

--
Networking -- only one letter away from not working.

Yitzchak Scott-Thoennes

unread,
Oct 7, 2003, 6:55:03 PM10/7/03
to Ed Allen Smith, perl_...@bloodgate.com, perl5-...@perl.org, pa...@pjcj.net
On Tue, Oct 07, 2003 at 06:33:33PM -0400, Ed Allen Smith <eas...@beatrice.rutgers.edu> wrote:
>
> I'll change my earlier suggestion of how to handle this in Math::BigInt. I
> suggest changing the current code in _root from:
>
> # fit's into one Perl scalar, so result can be computed directly
> $x->[0] = int( $x->[0] ** (1 / $n->[0]) );
>
> to:
>
> if ($x->[0] == 0) {
> return 0;
> }
> # fits into one Perl scalar, so result can be computed directly
> my $temp = $x->[0] ** (1 / $n->[0]);
> my $a = int($temp);
> my $b = int($temp + (($temp > 0) ? 0.5 : -0.5));
> if ($a == $b) {
> $x->[0] = $a;
> } elsif (abs(($a**$n->[0]) - $x->[0]) > abs(($b**$n->[0]) - $x->[0])) {
> $x->[0] = $b;
> } else {
> $x->[0] = $a;
> }
> return $x;
>
> In other words, if adding 0.5 (equivalently, subtracting, if the result is
> negative) will give a more arithmetically correct result after truncating, do
> it; otherwise, don't. (It's likely that the same sort of thing would be
> helpful for the _sqrt function.)

That's basically just a form of rounding, only not based on just
rounding the result. It looks more to me as if the goal here is to
come up with the greatest result $a such that $a**$n->[0] <= $x->[0]
(not sure if that "greatest" or "<=" is meant to apply to absolute
values or not).

But your general method certainly works for that.

Ed Allen Smith

unread,
Oct 7, 2003, 7:17:12 PM10/7/03
to stho...@efn.org, perl_...@bloodgate.com, perl5-...@perl.org, pa...@pjcj.net
In message <2003100722...@efn.org> (on 7 October 2003 15:55:03

-0700), stho...@efn.org (Yitzchak Scott-Thoennes) wrote:
>On Tue, Oct 07, 2003 at 06:33:33PM -0400, Ed Allen Smith
><eas...@beatrice.rutgers.edu> wrote:
>>
>> I'll change my earlier suggestion of how to handle this in Math::BigInt. I
>> suggest changing the current code in _root from:
>>
>> # fit's into one Perl scalar, so result can be computed directly
>> $x->[0] = int( $x->[0] ** (1 / $n->[0]) );
>>
>> to:
>>
>> if ($x->[0] == 0) {
>> return 0;
>> }
>> # fits into one Perl scalar, so result can be computed directly
>> my $temp = $x->[0] ** (1 / $n->[0]);
>> my $a = int($temp);
>> my $b = int($temp + (($temp > 0) ? 0.5 : -0.5));

The (($temp > 0) ? 0.5 : -0.5) isn't necessary if Calc.pm is always fed
positive integers as $x->[0], BTW.

>> if ($a == $b) {
>> $x->[0] = $a;
>> } elsif (abs(($a**$n->[0]) - $x->[0]) > abs(($b**$n->[0]) - $x->[0])) {
>> $x->[0] = $b;
>> } else {
>> $x->[0] = $a;
>> }
>> return $x;
>>
>> In other words, if adding 0.5 (equivalently, subtracting, if the result
>>is negative) will give a more arithmetically correct result after
>>truncating, do it; otherwise, don't. (It's likely that the same sort of
>>thing would be helpful for the _sqrt function.)
>
>That's basically just a form of rounding, only not based on just
>rounding the result.

Correct. It's choosing whether to truncate, or to round .5 and up upward.

>It looks more to me as if the goal here is to
>come up with the greatest result $a such that $a**$n->[0] <= $x->[0]

I can see that argument; it depends on whether one wishes to stick with
Calc.pm always truncating to int in _root or not.

>(not sure if that "greatest" or "<=" is meant to apply to absolute
>values or not).
>
>But your general method certainly works for that.

There are some cases in which the above would be different (none for what
"should be integers", but if the result before truncating has a .5 or higher
after the decimal point, it could round up instead of truncating, if that
gives a more arithmetically correct result). I can see arguments for going
either way.

-Allen

September 11, 2001 A Day That Shall Live In Infamy II
"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety." - Benjamin Franklin

Yitzchak Scott-Thoennes

unread,
Oct 8, 2003, 9:11:03 PM10/8/03
to perl_...@bloodgate.com, Ed Allen Smith, perl5-...@perl.org, pa...@pjcj.net
On Tue, Oct 07, 2003 at 07:17:12PM -0400, Ed Allen Smith <eas...@beatrice.rutgers.edu> wrote:
> In message <2003100722...@efn.org> (on 7 October 2003 15:55:03
> -0700), stho...@efn.org (Yitzchak Scott-Thoennes) wrote:
> >On Tue, Oct 07, 2003 at 06:33:33PM -0400, Ed Allen Smith
> ><eas...@beatrice.rutgers.edu> wrote:
> >> if ($a == $b) {
> >> $x->[0] = $a;
> >> } elsif (abs(($a**$n->[0]) - $x->[0]) > abs(($b**$n->[0]) - $x->[0])) {
> >> $x->[0] = $b;
> >> } else {
> >> $x->[0] = $a;
> >> }
> >> return $x;
> >>
> >> In other words, if adding 0.5 (equivalently, subtracting, if the result
> >>is negative) will give a more arithmetically correct result after
> >>truncating, do it; otherwise, don't. (It's likely that the same sort of
> >>thing would be helpful for the _sqrt function.)
> >
> >That's basically just a form of rounding, only not based on just
> >rounding the result.
>
> Correct. It's choosing whether to truncate, or to round .5 and up upward.
>
> >It looks more to me as if the goal here is to
> >come up with the greatest result $a such that $a**$n->[0] <= $x->[0]
>
> I can see that argument; it depends on whether one wishes to stick with
> Calc.pm always truncating to int in _root or not.

It should be consistent, and the rest of it seems to want to truncate.
(This should be documented.)

> >(not sure if that "greatest" or "<=" is meant to apply to absolute
> >values or not).
> >
> >But your general method certainly works for that.

How about this:

--- lib/Math/BigInt/Calc.pm.orig 2003-10-08 15:31:26.583782400 -0700
+++ lib/Math/BigInt/Calc.pm 2003-10-08 15:43:00.251227200 -0700
@@ -1423,7 +1423,10 @@
else
{


# fit's into one Perl scalar, so result can be computed directly

- $x->[0] = int( $x->[0] ** (1 / $n->[0]) );
+ my $result = int( $x->[0] ** (1 / $n->[0]) + .5);
+ # see if we rounded up inappropriately
+ --$result if $result ** $n->[0] > $x->[0];
+ $x->[0] = $result;
}
return $x;
}
End of Patch.

By the way, just a bit lower down, I see a /0b1(0+)/ that looks as
if it should be /0b1(0+)\z/, but I'm not sure exactly what it is doing.

Ed Allen Smith

unread,
Oct 8, 2003, 10:09:28 PM10/8/03
to stho...@efn.org, perl_...@bloodgate.com, perl5-...@perl.org, pa...@pjcj.net
In message <2003100901...@efn.org> (on 8 October 2003 18:11:03

-0700), stho...@efn.org (Yitzchak Scott-Thoennes) wrote:

>How about this:
>
>--- lib/Math/BigInt/Calc.pm.orig 2003-10-08 15:31:26.583782400 -0700
>+++ lib/Math/BigInt/Calc.pm 2003-10-08 15:43:00.251227200 -0700
>@@ -1423,7 +1423,10 @@
> else
> {
> # fit's into one Perl scalar, so result can be computed directly
>- $x->[0] = int( $x->[0] ** (1 / $n->[0]) );
>+ my $result = int( $x->[0] ** (1 / $n->[0]) + .5);
>+ # see if we rounded up inappropriately
>+ --$result if $result ** $n->[0] > $x->[0];
>+ $x->[0] = $result;
> }
> return $x;
> }
>End of Patch.

I like it overall, except that I'm wondering given rounding wierdnesses
whether it might be best to check specifically what the result is without
the +.5. That way, if something goes wrong with the $result**$n->[0] check
(say it's 0.000000001 greater than $x->[0]), it'll just revert to the
behavior without the +0.5.

-Allen

Yitzchak Scott-Thoennes

unread,
Oct 8, 2003, 10:19:27 PM10/8/03
to Ed Allen Smith, perl_...@bloodgate.com, perl5-...@perl.org, pa...@pjcj.net
On Wed, Oct 08, 2003 at 10:09:28PM -0400, Ed Allen Smith <eas...@beatrice.rutgers.edu> wrote:
> In message <2003100901...@efn.org> (on 8 October 2003 18:11:03
> -0700), stho...@efn.org (Yitzchak Scott-Thoennes) wrote:
>
> >How about this:
> >
> >--- lib/Math/BigInt/Calc.pm.orig 2003-10-08 15:31:26.583782400 -0700
> >+++ lib/Math/BigInt/Calc.pm 2003-10-08 15:43:00.251227200 -0700
> >@@ -1423,7 +1423,10 @@
> > else
> > {
> > # fit's into one Perl scalar, so result can be computed directly
> >- $x->[0] = int( $x->[0] ** (1 / $n->[0]) );
> >+ my $result = int( $x->[0] ** (1 / $n->[0]) + .5);
> >+ # see if we rounded up inappropriately
> >+ --$result if $result ** $n->[0] > $x->[0];
> >+ $x->[0] = $result;
> > }
> > return $x;
> > }
> >End of Patch.
>
> I like it overall, except that I'm wondering given rounding wierdnesses
> whether it might be best to check specifically what the result is without
> the +.5.

Not sure exactly what you mean. The rounded value will either be
the truncated result or one more than it.

That way, if something goes wrong with the $result**$n->[0] check
> (say it's 0.000000001 greater than $x->[0]), it'll just revert to the
> behavior without the +0.5.

You shouldn't get that kind of inaccuracy with an integer ** integer
calculation. Nevertheless, I guess you could say:
--$result if int($result ** $n->[0] + .5) > $x->[0];

0 new messages