summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-02-21 01:22:47 (GMT)
committerGuido van Rossum <guido@python.org>1997-02-21 01:22:47 (GMT)
commit05bc4af47d86ac2d2b69f1884c5f2f3e929c3cb3 (patch)
tree421423f87032b9fffa5a62b85c9152778fa7314d /Modules
parentad183bbfe669a5ebcdabe6c383e66e5e931ddb69 (diff)
downloadcpython-05bc4af47d86ac2d2b69f1884c5f2f3e929c3cb3.zip
cpython-05bc4af47d86ac2d2b69f1884c5f2f3e929c3cb3.tar.gz
cpython-05bc4af47d86ac2d2b69f1884c5f2f3e929c3cb3.tar.bz2
Lee's next version. Careful: this now dumps core for me on SGI IRIX 5.3.
Lee is wondering whether to withdraw his patchs. Sigh.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/fpetestmodule.c194
1 files changed, 76 insertions, 118 deletions
diff --git a/Modules/fpetestmodule.c b/Modules/fpetestmodule.c
index 2156afb..475bd7e 100644
--- a/Modules/fpetestmodule.c
+++ b/Modules/fpetestmodule.c
@@ -46,11 +46,12 @@
static PyObject *fpe_error;
void initfpetest(void);
static PyObject *test(PyObject *self,PyObject *args);
-static int db0(void);
-static int overflow(void);
-static int nest1(double);
-static int nest2(double);
+static double db0(double);
+static double overflow(double);
+static double nest1(int, double);
+static double nest2(int, double);
static double nest3(double);
+static void printerr(double);
static PyMethodDef fpetest_methods[] = {
{"test", (PyCFunction) test, 1},
@@ -59,159 +60,116 @@ static PyMethodDef fpetest_methods[] = {
static PyObject *test(PyObject *self,PyObject *args)
{
- int i = 0, r;
+ double r;
- fprintf(stderr,"Test trapping overflow\n");
- r = overflow();
- if(r){
- fprintf(stderr,"(Note: No exception was raised.)\n");
- PyErr_Clear();
- }else{
- fprintf(stderr,"Trapped:: ");
- PyErr_Print();
- PyErr_Clear();
- }
- i += r;
+ fprintf(stderr,"overflow");
+ r = overflow(1.e160);
+ printerr(r);
- fprintf(stderr,"Test trapping division by zero\n");
- r = db0();
- if(r){
- fprintf(stderr,"(Note: No exception was raised.)\n");
- PyErr_Clear();
- }else{
- fprintf(stderr,"Trapped:: ");
- PyErr_Print();
- PyErr_Clear();
- }
- i += r;
+ fprintf(stderr,"\ndiv by 0");
+ r = db0(0.0);
+ printerr(r);
- fprintf(stderr,"Test nested protection zones, outer zone\n");
- r = nest1(0.0);
- if(r){
- fprintf(stderr,"(Note: No exception was raised.)\n");
- PyErr_Clear();
- }else{
- fprintf(stderr,"Trapped:: ");
- PyErr_Print();
- PyErr_Clear();
- }
- i += r;
-
- fprintf(stderr,"Test nested protection zones, inner zone\n");
- fprintf(stderr,"(Note: Return will apparently come from outer zone.)\n");
- r = nest1(1.0);
- if(r){
- fprintf(stderr,"(Note: No exception was raised.)\n");
- PyErr_Clear();
- }else{
- fprintf(stderr,"Trapped:: ");
- PyErr_Print();
- PyErr_Clear();
- }
- i += r;
+ fprintf(stderr,"\nnested outer");
+ r = nest1(0, 0.0);
+ printerr(r);
- fprintf(stderr,"Test nested protection zones, trailing outer zone\n");
- r = nest1(2.0);
- if(r){
- fprintf(stderr,"(Note: No exception was raised.)\n");
- PyErr_Clear();
- }else{
- fprintf(stderr,"Trapped:: ");
- PyErr_Print();
- PyErr_Clear();
- }
- i += r;
+ fprintf(stderr,"\nnested inner");
+ r = nest1(1, 1.0);
+ printerr(r);
- fprintf(stderr,"Test nested function calls, prior error\n");
- r = nest2(0.0);
- if(r){
- fprintf(stderr,"(Note: No exception was raised.)\n");
- PyErr_Clear();
- }else{
- fprintf(stderr,"Trapped:: ");
- PyErr_Print();
- PyErr_Clear();
- }
- i += r;
+ fprintf(stderr,"\ntrailing outer");
+ r = nest1(2, 2.0);
+ printerr(r);
- fprintf(stderr,"Test nested function calls, interior error\n");
- r = nest2(1.0);
- if(r){
- fprintf(stderr,"(Note: No exception was raised.)\n");
- PyErr_Clear();
- }else{
- fprintf(stderr,"Trapped:: ");
- PyErr_Print();
- PyErr_Clear();
- }
- i += r;
+ fprintf(stderr,"\nnested prior");
+ r = nest2(0, 0.0);
+ printerr(r);
- fprintf(stderr,"Test nested function calls, trailing error\n");
- r = nest2(2.0);
- if(r){
- fprintf(stderr,"(Note: No exception was raised.)\n");
- PyErr_Clear();
- }else{
- fprintf(stderr,"Trapped:: ");
- PyErr_Print();
- PyErr_Clear();
- }
- i += r;
+ fprintf(stderr,"\nnested interior");
+ r = nest2(1, 1.0);
+ printerr(r);
+
+ fprintf(stderr,"\nnested trailing");
+ r = nest2(2, 2.0);
+ printerr(r);
- fprintf(stderr,"Number of tests failed: %d\n", i);
Py_INCREF (Py_None);
return Py_None;
}
-static int nest1(double x)
+static void printerr(double r)
+{
+ if(r == 3.1416){
+ fprintf(stderr,"\tPASS\n");
+ PyErr_Print();
+ }else{
+ fprintf(stderr,"\tFAIL\n");
+ }
+ PyErr_Clear();
+}
+
+static double nest1(int i, double x)
{
double a = 1.0;
- PyFPE_START_PROTECT("Division by zero, outer zone", return 0)
- a = 1./x;
- PyFPE_START_PROTECT("Division by zero, inner zone", return 0)
+
+ PyFPE_START_PROTECT("Division by zero, outer zone", return 3.1416)
+ if(i == 0){
+ a = 1./x;
+ }else if(i == 1){
+ /* This (following) message is never seen. */
+ PyFPE_START_PROTECT("Division by zero, inner zone", return 3.1416)
a = 1./(1. - x);
PyFPE_END_PROTECT
- a = 1./(2. - x);
+ }else if(i == 2){
+ a = 1./(2. - x);
+ }
PyFPE_END_PROTECT
- return(1);
+
+ return a;
}
-static int nest2(double x)
+static double nest2(int i, double x)
{
double a = 1.0;
- PyFPE_START_PROTECT("Division by zero, prior error", return 0)
- a = 1./x;
- a = nest3(x);
- a = 1./(2. - x);
+ PyFPE_START_PROTECT("Division by zero, prior error", return 3.1416)
+ if(i == 0){
+ a = 1./x;
+ }else if(i == 1){
+ a = nest3(x);
+ }else if(i == 2){
+ a = 1./(2. - x);
+ }
PyFPE_END_PROTECT
- return(1);
+ return a;
}
static double nest3(double x)
{
double result;
- PyFPE_START_PROTECT("Division by zero, nest3 error", return 0)
+ /* This (following) message is never seen. */
+ PyFPE_START_PROTECT("Division by zero, nest3 error", return 3.1416)
result = 1./(1. - x);
PyFPE_END_PROTECT
return result;
}
-static int db0(void)
+static double db0(double x)
{
- double a = 1.0;
- PyFPE_START_PROTECT("Division by zero", return 0)
- a = 1./(a - 1.);
+ double a;
+ PyFPE_START_PROTECT("Division by zero", return 3.1416)
+ a = 1./x;
PyFPE_END_PROTECT
- return(1);
+ return a;
}
-static int overflow(void)
+static double overflow(double b)
{
- double a, b = 1.e200;
- PyFPE_START_PROTECT("Overflow", return 0)
+ double a;
+ PyFPE_START_PROTECT("Overflow", return 3.1416)
a = b*b;
PyFPE_END_PROTECT
- return(1);
+ return a;
}
void initfpetest(void)