diff options
author | Kevin Ryde <user42@zip.com.au> | 2003-04-23 23:37:57 +0200 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2003-04-23 23:37:57 +0200 |
commit | e4e7264b13c13c3eeca33c50912c8df0a8ce8090 (patch) | |
tree | 00aa199fc3710719353c2c8f0203279a07ea2a0d /invalid.c | |
parent | 420559b640a4d13ef06c8d15a7f4f50856ba2bfe (diff) | |
download | gmp-e4e7264b13c13c3eeca33c50912c8df0a8ce8090.tar.gz |
* invalid.c: New file.
Diffstat (limited to 'invalid.c')
-rw-r--r-- | invalid.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/invalid.c b/invalid.c new file mode 100644 index 000000000..45ec4ca5d --- /dev/null +++ b/invalid.c @@ -0,0 +1,73 @@ +/* __gmp_invalid_operation -- invalid floating point operation. + + THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST + CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN + FUTURE GNU MP RELEASES. + +Copyright 2003 Free Software Foundation, Inc. + +This file is part of the GNU MP Library. + +The GNU MP Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The GNU MP Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MP Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. */ + +#include "config.h" + +#include <signal.h> +#include <stdlib.h> + +#if HAVE_UNISTD_H +#include <unistd.h> /* for getpid */ +#endif + +#include "gmp.h" +#include "gmp-impl.h" + + +/* kill is not available on mingw, but that's ok since it has raise */ +#if ! HAVE_RAISE +#define raise(sig) kill (getpid(), sig) +#endif + + +/* __gmp_invalid_operation is for an invalid floating point operation, like + mpz_set_d on a NaN or Inf. It's done as a subroutine to minimize code in + places raising an exception. + + feraiseexcept(FE_INVALID) is not used here, since unfortunately on most + systems it would require libm. + + Alternatives: + + It might be possible to check whether a hardware "invalid operation" trap + is enabled or not before raising a signal. This would require all + callers to be prepared to continue with some bogus result. Bogus returns + are bad, but presumably an application disabling the trap is prepared for + that. + + On some systems (eg. BSD) the signal handler can find out the reason for + a SIGFPE (overflow, invalid, div-by-zero, etc). Perhaps we could get + that into our raise too. + + i386 GLIBC implements feraiseexcept(FE_INVALID) with an asm fdiv 0/0. + That would both respect the exceptions mask and give a reason code in a + BSD signal. */ + +void +__gmp_invalid_operation (void) +{ + raise (SIGFPE); + abort (); +} |