| [3225] | 1 | /*
|
|---|
| 2 | ---------------------------------------------------------------------
|
|---|
| 3 | / Copyright (c) 1996. \
|
|---|
| 4 | | The Regents of the University of California. |
|
|---|
| 5 | | All rights reserved. |
|
|---|
| 6 | | |
|
|---|
| 7 | | Permission to use, copy, modify, and distribute this software for |
|
|---|
| 8 | | any purpose without fee is hereby granted, provided that this en- |
|
|---|
| 9 | | tire notice is included in all copies of any software which is or |
|
|---|
| 10 | | includes a copy or modification of this software and in all |
|
|---|
| 11 | | copies of the supporting documentation for such software. |
|
|---|
| 12 | | |
|
|---|
| 13 | | This work was produced at the University of California, Lawrence |
|
|---|
| 14 | | Livermore National Laboratory under contract no. W-7405-ENG-48 |
|
|---|
| 15 | | between the U.S. Department of Energy and The Regents of the |
|
|---|
| 16 | | University of California for the operation of UC LLNL. |
|
|---|
| 17 | | |
|
|---|
| 18 | | DISCLAIMER |
|
|---|
| 19 | | |
|
|---|
| 20 | | This software was prepared as an account of work sponsored by an |
|
|---|
| 21 | | agency of the United States Government. Neither the United States |
|
|---|
| 22 | | Government nor the University of California nor any of their em- |
|
|---|
| 23 | | ployees, makes any warranty, express or implied, or assumes any |
|
|---|
| 24 | | liability or responsibility for the accuracy, completeness, or |
|
|---|
| 25 | | usefulness of any information, apparatus, product, or process |
|
|---|
| 26 | | disclosed, or represents that its use would not infringe |
|
|---|
| 27 | | privately-owned rights. Reference herein to any specific commer- |
|
|---|
| 28 | | cial products, process, or service by trade name, trademark, |
|
|---|
| 29 | | manufacturer, or otherwise, does not necessarily constitute or |
|
|---|
| 30 | | imply its endorsement, recommendation, or favoring by the United |
|
|---|
| 31 | | States Government or the University of California. The views and |
|
|---|
| 32 | | opinions of authors expressed herein do not necessarily state or |
|
|---|
| 33 | | reflect those of the United States Government or the University |
|
|---|
| 34 | | of California, and shall not be used for advertising or product |
|
|---|
| 35 | \ endorsement purposes. /
|
|---|
| 36 | ---------------------------------------------------------------------
|
|---|
| 37 | */
|
|---|
| 38 |
|
|---|
| 39 | /*
|
|---|
| 40 | Floating point exception test module.
|
|---|
| 41 |
|
|---|
| 42 | */
|
|---|
| 43 |
|
|---|
| 44 | #include "Python.h"
|
|---|
| 45 |
|
|---|
| 46 | static PyObject *fpe_error;
|
|---|
| 47 | PyMODINIT_FUNC initfpetest(void);
|
|---|
| 48 | static PyObject *test(PyObject *self,PyObject *args);
|
|---|
| 49 | static double db0(double);
|
|---|
| 50 | static double overflow(double);
|
|---|
| 51 | static double nest1(int, double);
|
|---|
| 52 | static double nest2(int, double);
|
|---|
| 53 | static double nest3(double);
|
|---|
| 54 | static void printerr(double);
|
|---|
| 55 |
|
|---|
| 56 | static PyMethodDef fpetest_methods[] = {
|
|---|
| 57 | {"test", (PyCFunction) test, METH_VARARGS},
|
|---|
| 58 | {0,0}
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | static PyObject *test(PyObject *self,PyObject *args)
|
|---|
| 62 | {
|
|---|
| 63 | double r;
|
|---|
| 64 |
|
|---|
| 65 | fprintf(stderr,"overflow");
|
|---|
| 66 | r = overflow(1.e160);
|
|---|
| 67 | printerr(r);
|
|---|
| 68 |
|
|---|
| 69 | fprintf(stderr,"\ndiv by 0");
|
|---|
| 70 | r = db0(0.0);
|
|---|
| 71 | printerr(r);
|
|---|
| 72 |
|
|---|
| 73 | fprintf(stderr,"\nnested outer");
|
|---|
| 74 | r = nest1(0, 0.0);
|
|---|
| 75 | printerr(r);
|
|---|
| 76 |
|
|---|
| 77 | fprintf(stderr,"\nnested inner");
|
|---|
| |
|---|