* FP signals fubar under Ultrix 4.1
@ 1991-04-11 16:36 Hascall John Paul
1991-04-11 20:12 ` Mike Iglesias
0 siblings, 1 reply; 2+ messages in thread
From: Hascall John Paul @ 1991-04-11 16:36 UTC (permalink / raw)
The following program attempts various "undefined" mathematical operations
and attempts to catch the resulting signal. I compile with:
cc -O0 bug.c -o bug -lm
(and answer the prompt with, say, 512);
and I get the following results:
Ultrix 3.1D (Rev. 54) SIGFPE (8)
Ultrix 4.1 (Rev. 40) SIGFPE (8)
Ultrix 4.1 (Rev. 55) SIGILL (4)
What's going on here? I am stumped. This doesn't seem at all right.
--------------- cut here, file bug.c ------------------------------------------
#include <stdio.h>
#include <signal.h>
#include <mips/fpu.h>
#include <mips/cpu.h>
int main(argc, argv)
int argc;
char ** argv;
{
int csr_val;
void fpx_handler();
float x,y,z; /* or double, if e+-30 replaced with e+-300 */
int i,j,k;
/* zero or more of (2048 1024 512 256 128) + (one of 0,1,2,3) */
(void)printf("csr <INV, DIV0, OVER, UNDER, INEX, <6-0 = near,0,+,-> :");
(void)scanf("%d", &csr_val);
do {} while (getchar() != '\n');
(void)signal(SIGILL, fpx_handler); /* sig 4 ? */
(void)signal(SIGTRAP, fpx_handler); /* sig 5 ??? */
(void)signal(SIGFPE, fpx_handler); /* sig 8 */
(void)set_fpc_csr(csr_val);
printf("Try a floating overflow (1.0e+30 x 1.0e+30)\n");
x = 1.0e30; y = x * x;
printf("Result is %f\n\n", y);
printf("Try a floating underflow (1.0e-30 x 1.0e-30)\n");
x = 1.0e-30; y = x * x;
printf("Result is %f\n\n", y);
printf("Try a floating divide by zero (1.0 / 0.0)\n");
x = 1.0; y = 0.0; z = x / y;
printf("Result is %f\n\n", z);
printf("Try a negative square root (sqrt(-1.0))\n");
x = -1.0; y = sqrt(x);
printf("Result is %f\n\n", y);
printf("Try an integer overflow (100000 * 100000)\n");
i = 100000; j = i * i;
printf("Result is %f\n\n", j);
printf("Try an integer divide by zero (1 / 0)\n");
i = 1; j = 0; k = i / j;
printf("Result is %f\n\n", k);
return(0);
}
void fpx_handler(sig, code, scp)
int sig;
int code;
struct sigcontext * scp;
{
union fpc_csr csr;
csr.fc_word = scp->sc_fpc_csr;
fprintf(stderr,"caught signal %d, code %d\n", sig, code);
if (csr.fc_struct.ex_invalid) {
fprintf(stderr,"floating point error: invalid operation\n");
fprintf(stderr,"at or near location %x\n",scp->sc_pc);
exit(1);
}
if (csr.fc_struct.ex_divide0) {
fprintf(stderr,"floating point error: division by zero\n");
fprintf(stderr,"at or near location %x\n",scp->sc_pc);
exit(1);
}
if (csr.fc_struct.ex_underflow) {
fprintf(stderr,"floating point error: underflow\n");
fprintf(stderr,"at or near location %x\n",scp->sc_pc);
exit(1);
}
if (csr.fc_struct.ex_overflow) {
fprintf(stderr,"floating point error: overflow\n");
fprintf(stderr,"at or near location %x\n",scp->sc_pc);
exit(1);
}
if (csr.fc_struct.ex_inexact) {
fprintf(stderr,"floating point error: inexact operation\n");
fprintf(stderr,"at or near location %x\n",scp->sc_pc);
exit(1);
}
if (csr.fc_struct.ex_unimplemented) {
fprintf(stderr,"floating point error: unimplemented operation\n");
fprintf(stderr,"at or near location %x\n",scp->sc_pc);
exit(1);
}
if (code == BRK_DIVZERO) {
fprintf(stderr,"integer error: division by zero\n");
fprintf(stderr,"at or near location %x\n",scp->sc_pc);
exit(1);
}
fprintf(stderr,"floating point error: unknown exception code\n");
fprintf(stderr,"at or near location %x\n",scp->sc_pc);
fprintf(stderr,"fp status word %lx\n",csr);
exit(1);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: FP signals fubar under Ultrix 4.1
1991-04-11 16:36 FP signals fubar under Ultrix 4.1 Hascall John Paul
@ 1991-04-11 20:12 ` Mike Iglesias
0 siblings, 0 replies; 2+ messages in thread
From: Mike Iglesias @ 1991-04-11 20:12 UTC (permalink / raw)
In article <1991Apr11.163618.6626@news.iastate.edu> john@iastate.edu (Hascall John Paul) writes:
>The following program attempts various "undefined" mathematical operations
>and attempts to catch the resulting signal. I compile with:
>
> cc -O0 bug.c -o bug -lm
>
>(and answer the prompt with, say, 512);
>and I get the following results:
>
> Ultrix 3.1D (Rev. 54) SIGFPE (8)
> Ultrix 4.1 (Rev. 40) SIGFPE (8)
> Ultrix 4.1 (Rev. 55) SIGILL (4)
There's a patch available from DEC to fix problems with incorrect signals
on floating point exceptions. From what I've heard, you need it to run
the new DEC Fortran also. I don't have a patch number - it came on a
tape of patches we got from DEC in February.
Mike Iglesias
University of California, Irvine
Internet: iglesias@draco.acs.uci.edu
BITNET: iglesias@uci
uucp: ...!ucbvax!ucivax!iglesias
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1991-04-11 20:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1991-04-11 16:36 FP signals fubar under Ultrix 4.1 Hascall John Paul
1991-04-11 20:12 ` Mike Iglesias
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox