🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sun
Article #14043

Re: Fortran bug

#14043
From: Ray Bovet
Date: Fri, 02 Mar 1990 17:48
95 lines
3611 bytes
In article <5401@brazos.Rice.edu> verena@vuse.vanderbilt.edu (Verena Meiser Umar) writes:
>X-Sun-Spots-Digest: Volume 9, Issue 63, message 3
>
>We are having a problem with division by zero when running  Fortran
>programs.  The Sun3 architecture does not report the occurrence of such a
>division at all, and the Sun4 architecture gives the following warning  -
>BUT not until the end of the run:
>Verena Umar
>verena@vuse.vanderbilt.edu

I wrote the following routine to solve this problem (at least on Sun4s).
The routine causes a crash as soon as the "nasty" IEEE errors like divide
by zero occur.  You just need to call the routine once at the beginning of
your program.  It should be fairly straightforward to modify the routine
if you want to ignore some errors I thought were fatal or vice versa.

				Ray


#include <floatingpoint.h>
#include <signal.h>
#include <stdio.h>
extern catch_div_by_zero(), catch_overflow(), catch_invalid();
/* extern catch_inexact(), catch_underflow(); */

fp_abort_()
/*
  This routine exists to force a program to abort when it encounters
  a floating point error such as a divide by zero, an overflow, or
  an invalid operation.  This used to be standard behavior until IEEE
  came along.  Unfortunately, this code is entirely Sun specific!
  It used to flush away inexact and underflow errors.  We have disabled
  the feature of flushing away inexact and underflow both because it
  slows the program down tremendously and because of philosophical
  questions about whether that is a good idea!  As far as I can tell,
  SIGFPE_IGNORE is the default action on underflow and inexact and is
  included here only for completeness' sake.
*/

{
/*  if (ieee_handler ("set", "inexact", catch_inexact))
    printf ("Can't set inexact.\n"); */
  if (ieee_handler ("set", "inexact", SIGFPE_IGNORE))
    printf ("Can't set inexact.\n");
  if (ieee_handler ("set", "division", catch_div_by_zero))
    printf ("Can't set division.\n");
/*  if (ieee_handler ("set", "underflow", catch_underflow))
    printf ("Can't set underflow.\n"); */
  if (ieee_handler ("set", "underflow", SIGFPE_IGNORE))
    printf ("Can't set underflow.\n");
  if (ieee_handler ("set", "overflow", catch_overflow))
    printf ("Can't set overflow.\n");
  if (ieee_handler ("set", "invalid", catch_invalid))
    printf ("Can't set invalid.\n");
}

catch_div_by_zero (sig, code, scp)
int sig, code;
struct sigcontext *scp;
{
  printf ("Divide by zero occurred at pc %X\n", scp->sc_pc);
  abort();
}

catch_overflow (sig, code, scp)
int sig, code;
struct sigcontext *scp;
{
  printf ("Floating-point overflow occurred at pc %X\n", scp->sc_pc);
  abort();
}

catch_invalid (sig, code, scp)
int sig, code;
struct sigcontext *scp;
{
  printf ("Invalid floating-point operation at pc %X\n", scp->sc_pc);
  abort();
}

catch_inexact (sig, code, scp)
int sig, code;
struct sigcontext *scp;
{
  char *to;
  ieee_flags ("clear", "exception", "inexact", &to);
}

catch_underflow (sig, code, scp)
int sig, code;
struct sigcontext *scp;
{
  char *to;
  ieee_flags ("clear", "exception", "underflow", &to);
}
Technical Details
Message-ID: <5426@brazos.Rice.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!rice!sun-spots-request

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!rice!sun-spots-request
From: bovet@hao.ucar.edu (Ray Bovet)
Newsgroups: comp.sys.sun
Subject: Re: Fortran bug
Keywords: SunOS
Message-ID: <5426@brazos.Rice.edu>
Date: 2 Mar 90 17:48:24 GMT
Sender: root@rice.edu
Organization: Sun-Spots
Lines: 95
Approved: Sun-Spots@rice.edu
X-Refs:  Original: v9n63
X-Sun-Spots-Digest: Volume 9, Issue 63, message 5