+++ /dev/null
-/*\r
- --------------------------------------------------------------------- \r
- / Copyright (c) 1996. \ \r
- | The Regents of the University of California. |\r
- | All rights reserved. |\r
- | |\r
- | Permission to use, copy, modify, and distribute this software for |\r
- | any purpose without fee is hereby granted, provided that this en- |\r
- | tire notice is included in all copies of any software which is or |\r
- | includes a copy or modification of this software and in all |\r
- | copies of the supporting documentation for such software. |\r
- | |\r
- | This work was produced at the University of California, Lawrence |\r
- | Livermore National Laboratory under contract no. W-7405-ENG-48 |\r
- | between the U.S. Department of Energy and The Regents of the |\r
- | University of California for the operation of UC LLNL. |\r
- | |\r
- | DISCLAIMER |\r
- | |\r
- | This software was prepared as an account of work sponsored by an |\r
- | agency of the United States Government. Neither the United States |\r
- | Government nor the University of California nor any of their em- |\r
- | ployees, makes any warranty, express or implied, or assumes any |\r
- | liability or responsibility for the accuracy, completeness, or |\r
- | usefulness of any information, apparatus, product, or process |\r
- | disclosed, or represents that its use would not infringe |\r
- | privately-owned rights. Reference herein to any specific commer- |\r
- | cial products, process, or service by trade name, trademark, |\r
- | manufacturer, or otherwise, does not necessarily constitute or |\r
- | imply its endorsement, recommendation, or favoring by the United |\r
- | States Government or the University of California. The views and |\r
- | opinions of authors expressed herein do not necessarily state or |\r
- | reflect those of the United States Government or the University |\r
- | of California, and shall not be used for advertising or product |\r
- \ endorsement purposes. / \r
- --------------------------------------------------------------------- \r
-*/\r
-\r
-/*\r
- Floating point exception test module.\r
-\r
- */\r
-\r
-#include "Python.h"\r
-\r
-static PyObject *fpe_error;\r
-PyMODINIT_FUNC initfpetest(void);\r
-static PyObject *test(PyObject *self,PyObject *args);\r
-static double db0(double);\r
-static double overflow(double);\r
-static double nest1(int, double);\r
-static double nest2(int, double);\r
-static double nest3(double);\r
-static void printerr(double);\r
-\r
-static PyMethodDef fpetest_methods[] = {\r
- {"test", (PyCFunction) test, METH_VARARGS},\r
- {0,0}\r
-};\r
-\r
-static PyObject *test(PyObject *self,PyObject *args)\r
-{\r
- double r;\r
-\r
- fprintf(stderr,"overflow");\r
- r = overflow(1.e160);\r
- printerr(r);\r
-\r
- fprintf(stderr,"\ndiv by 0");\r
- r = db0(0.0);\r
- printerr(r);\r
-\r
- fprintf(stderr,"\nnested outer");\r
- r = nest1(0, 0.0);\r
- printerr(r);\r
-\r
- fprintf(stderr,"\nnested inner");\r
- r = nest1(1, 1.0);\r
- printerr(r);\r
-\r
- fprintf(stderr,"\ntrailing outer");\r
- r = nest1(2, 2.0);\r
- printerr(r);\r
-\r
- fprintf(stderr,"\nnested prior");\r
- r = nest2(0, 0.0);\r
- printerr(r);\r
-\r
- fprintf(stderr,"\nnested interior");\r
- r = nest2(1, 1.0);\r
- printerr(r);\r
-\r
- fprintf(stderr,"\nnested trailing");\r
- r = nest2(2, 2.0);\r
- printerr(r);\r
-\r
- Py_INCREF (Py_None);\r
- return Py_None;\r
-}\r
-\r
-static void printerr(double r)\r
-{\r
- if(r == 3.1416){\r
- fprintf(stderr,"\tPASS\n");\r
- PyErr_Print();\r
- }else{\r
- fprintf(stderr,"\tFAIL\n");\r
- }\r
- PyErr_Clear();\r
-}\r
-\r
-static double nest1(int i, double x)\r
-{\r
- double a = 1.0;\r
-\r
- PyFPE_START_PROTECT("Division by zero, outer zone", return 3.1416)\r
- if(i == 0){\r
- a = 1./x;\r
- }else if(i == 1){\r
- /* This (following) message is never seen. */\r
- PyFPE_START_PROTECT("Division by zero, inner zone", return 3.1416)\r
- a = 1./(1. - x);\r
- PyFPE_END_PROTECT(a)\r
- }else if(i == 2){\r
- a = 1./(2. - x);\r
- }\r
- PyFPE_END_PROTECT(a)\r
-\r
- return a;\r
-}\r
-\r
-static double nest2(int i, double x)\r
-{\r
- double a = 1.0;\r
- PyFPE_START_PROTECT("Division by zero, prior error", return 3.1416)\r
- if(i == 0){\r
- a = 1./x;\r
- }else if(i == 1){\r
- a = nest3(x);\r
- }else if(i == 2){\r
- a = 1./(2. - x);\r
- }\r
- PyFPE_END_PROTECT(a)\r
- return a;\r
-}\r
-\r
-static double nest3(double x)\r
-{\r
- double result;\r
- /* This (following) message is never seen. */\r
- PyFPE_START_PROTECT("Division by zero, nest3 error", return 3.1416)\r
- result = 1./(1. - x);\r
- PyFPE_END_PROTECT(result)\r
- return result;\r
-}\r
-\r
-static double db0(double x)\r
-{\r
- double a;\r
- PyFPE_START_PROTECT("Division by zero", return 3.1416)\r
- a = 1./x;\r
- PyFPE_END_PROTECT(a)\r
- return a;\r
-}\r
-\r
-static double overflow(double b)\r
-{\r
- double a;\r
- PyFPE_START_PROTECT("Overflow", return 3.1416)\r
- a = b*b;\r
- PyFPE_END_PROTECT(a)\r
- return a;\r
-}\r
-\r
-PyMODINIT_FUNC initfpetest(void)\r
-{\r
- PyObject *m, *d;\r
-\r
- m = Py_InitModule("fpetest", fpetest_methods);\r
- if (m == NULL)\r
- return;\r
- d = PyModule_GetDict(m);\r
- fpe_error = PyErr_NewException("fpetest.error", NULL, NULL);\r
- if (fpe_error != NULL)\r
- PyDict_SetItemString(d, "error", fpe_error);\r
-}\r