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

[ID 20010824.010] Alpha error writing exceptional math value

Thread Next
From:
Andrew Dalke
Date:
August 24, 2001 15:07
Subject:
[ID 20010824.010] Alpha error writing exceptional math value
Message ID:
200108242100.f7OL0iO16424@pw600a.bioperl.org

This is a bug report for perl from dalke@dalkescientific.com,
generated with the help of perlbug 1.33 running under perl v5.6.1.


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

There is a problem with Perl 5.005_03 and 5.6.1  when printing
the IEEE 754 NaN exception value.

Here's the reproducible, with the first to show that non-exceptional
values really do work.

 ===============
[dalke@pw600a perl-5.6.1]$ ./perl -Ilib -e 'use POSIX; print acos(0.5), "\n"'
1.0471975511966
[dalke@pw600a perl-5.6.1]$ ./perl -Ilib -e 'use POSIX; print acos(3.7), "\n"'
Floating exception (core dumped)
[dalke@pw600a perl-5.6.1]$ ./perl -version

This is perl, v5.6.1 built for alpha-linux

Copyright 1987-2001, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
  ===============

I recompiled Perl with -g support to get a full stack trace.

 [...]
Reading symbols from /tmp/apd/perl-5.6.1/lib/auto/POSIX/POSIX.so...done.
#0  0x12009a4ac in Perl_cast_iv (f=NaN(0x8000000000000)) at util.c:2828
2828        if (f >= IV_MAX) {
(gdb) where
#0  0x12009a4ac in Perl_cast_iv (f=NaN(0x8000000000000)) at util.c:2828
#1  0x1200c36d0 in Perl_sv_upgrade (sv=0x120292a00, mt=6) at sv.c:957
#2  0x1200c8c48 in Perl_sv_2pv (sv=0x120292a00, lp=0x11ffff928) at sv.c:2209
#3  0x1201416e4 in Perl_do_print (sv=0x120292a00, fp=0x200006a08a8)
    at doio.c:1155
#4  0x1200b3e90 in Perl_pp_print () at pp_hot.c:407
#5  0x1200b0a8c in Perl_runops_debug () at run.c:53
#6  0x12001d0cc in S_run_body (oldscope=1) at perl.c:1471
#7  0x12001ca70 in perl_run (my_perl=0x120286b30) at perl.c:1393
#8  0x120017668 in main (argc=4, argv=0x11ffffbc8, env=0x11ffffbf0)
    at perlmain.c:52

(gdb) print f
$1 = NaN(0x8000000000000)
(gdb) list
2823    }
2824
2825    IV
2826    Perl_cast_iv(pTHX_ NV f)
2827    {
2828        if (f >= IV_MAX) {
2829            UV uv;
2830
2831            if (f >= (NV)UV_MAX)
2832                return (IV) UV_MAX;

I can reproduce this problem in C, as

lke@pw600a perl-5.6.1]$ cat q.c
#include <stdio.h>
#include <math.h>
#include <stdint.h>

#define IV_MAX INT64_MAX
main() {
  double f = acos(4.7);
  if (f >= IV_MAX) {
    printf("Yep.\n");
  } else {
    printf("Nope.\n");
  }
}
[dalke@pw600a perl-5.6.1]$ cc q.c -lm -g
[dalke@pw600a perl-5.6.1]$ ./a.out
Floating exception (core dumped)
[dalke@pw600a perl-5.6.1]$ gdb a.out core
GNU gdb 19991004
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "alpha-redhat-linux"...

warning: "/tmp/apd/perl-5.6.1/core": ambiguous core format, 2 handlers match
Core was generated by `./a.out'.
Program terminated with signal 8, Floating point exception.
Reading symbols from /lib/libm.so.6.1...done.
Reading symbols from /lib/libc.so.6.1...done.
Reading symbols from /lib/ld-linux.so.2...done.
#0  0x1200004c8 in main () at q.c:8
8         if (f >= IV_MAX) {
(gdb)

Here's the assembly dump of that code:

0x120000480 <main>:     ldah    gp,17(t12)
0x120000484 <main+4>:   lda     gp,-32296(gp)
0x120000488 <main+8>:   subq    sp,0x20,sp
0x12000048c <main+12>:  stq     ra,0(sp)
0x120000490 <main+16>:  stq     fp,8(sp)
0x120000494 <main+20>:  mov     sp,fp
0x120000498 <main+24>:  ldq     t0,-32672(gp)
0x12000049c <main+28>:  ldt     $f16,0(t0)
0x1200004a0 <main+32>:  ldq     t12,-32728(gp)
0x1200004a4 <main+36>:  jsr     ra,(t12),0x120000000
0x1200004a8 <main+40>:  ldah    gp,17(ra)
0x1200004ac <main+44>:  lda     gp,-32336(gp)
0x1200004b0 <main+48>:  fmov    $f0,$f10
0x1200004b4 <main+52>:  stt     $f10,16(fp)
0x1200004b8 <main+56>:  ldt     $f10,16(fp)
0x1200004bc <main+60>:  ldq     t0,-32680(gp)
0x1200004c0 <main+64>:  ldt     $f11,0(t0)
0x1200004c4 <main+68>:  cmptle  $f11,$f10,$f10
0x1200004c8 <main+72>:  fbeq    $f10,0x1200004e4 <main+100>
0x1200004cc <main+76>:  ldq     a0,-32688(gp)
0x1200004b8 <main+56>:  ldt     $f10,16(fp)
0x1200004bc <main+60>:  ldq     t0,-32680(gp)
0x1200004c0 <main+64>:  ldt     $f11,0(t0)
0x1200004c4 <main+68>:  cmptle  $f11,$f10,$f10   <--- SIGFPE occurs here
0x1200004c8 <main+72>:  fbeq    $f10,0x1200004e4 <main+100>
0x1200004cc <main+76>:  ldq     a0,-32688(gp)
0x1200004d0 <main+80>:  ldq     t12,-32744(gp)
0x1200004d4 <main+84>:  jsr     ra,(t12),0x12000063c
0x1200004d8 <main+88>:  ldah    gp,17(ra)
0x1200004dc <main+92>:  lda     gp,-32384(gp)
0x1200004e0 <main+96>:  br      0x1200004f8 <main+120>
0x1200004e4 <main+100>: ldq     a0,-32696(gp)
0x1200004e8 <main+104>: ldq     t12,-32744(gp)
0x1200004ec <main+108>: jsr     ra,(t12),0x12000063c
0x1200004f0 <main+112>: ldah    gp,17(ra)
0x1200004f4 <main+116>: lda     gp,-32408(gp)
0x1200004f8 <main+120>: mov     fp,sp
0x1200004fc <main+124>: ldq     ra,0(sp)
0x120000500 <main+128>: ldq     fp,8(sp)
0x120000504 <main+132>: addq    sp,0x20,sp
0x120000508 <main+136>: ret     zero,(ra),0x1

Whe running it assembly step by assembly step in the debugger:
(gdb) nexti
0x1200004ac     7         double f = acos(4.7);
(gdb) nexti
0x1200004b0     7         double f = acos(4.7);
(gdb) nexti
0x1200004b4     7         double f = acos(4.7);
(gdb) nexti
8         if (f >= IV_MAX) {
(gdb) nexti
0x1200004bc     8         if (f >= IV_MAX) {
(gdb) nexti
0x1200004c0     8         if (f >= IV_MAX) {
(gdb) nexti
0x1200004c4     8         if (f >= IV_MAX) {
(gdb) nexti

Program received signal SIGFPE, Arithmetic exception.
0x1200004c8 in main () at q.c:8
8         if (f >= IV_MAX) {

which is this line of the assembly
0x1200004c4 <main+68>:  cmptle  $f11,$f10,$f10   <--- SIGFPE occurs here

I don't know enough about the Perl internals, Alphas or 64 bit
programming to aid any more than this.

					Andrew Dalke
					dalke@dalkescientific.com
P.S.
  This occured because the Perl Cookbook uses acos(3.7) in an
example.  This number is out of range and I've informed the authors.
It will be updated to use 0.37 but in the meanwhile my testing for
the PLEAC (see pleac.sf.net) translation of the cookbook to Python
found this problem.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=low
---
Site configuration information for perl v5.6.1:

Configured by dalke at Fri Aug 24 12:20:56 EDT 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.2.14-6.0, archname=alpha-linux
    uname='linux pw600a.bioperl.org 2.2.14-6.0 #1 tue mar 28 16:56:56 est 2000 alpha unknown '
    config_args='-de'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=define uselongdouble=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /usr/shlib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lposix -lcrypt -lutil
    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'

Locally applied patches:
    

---
@INC for perl v5.6.1:
    lib
    /usr/local/lib/perl5/5.6.1/alpha-linux
    /usr/local/lib/perl5/5.6.1
    /usr/local/lib/perl5/site_perl/5.6.1/alpha-linux
    /usr/local/lib/perl5/site_perl/5.6.1
    /usr/local/lib/perl5/site_perl
    .

---
Environment for perl v5.6.1:
    HOME=/home/dalke
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/dalke/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11R6/bin:/home/biopython/bin
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh


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