resource manager: add optional resource id.
[dragonfly.git] / contrib / gmp / invalid.c
blob24c6f131c1fe621bb418c1d106476aeaf1349e63
1 /* __gmp_invalid_operation -- invalid floating point operation.
3 THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST
4 CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
5 FUTURE GNU MP RELEASES.
7 Copyright 2003 Free Software Foundation, Inc.
9 This file is part of the GNU MP Library.
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 The GNU MP Library is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 License for more details.
21 You should have received a copy of the GNU Lesser General Public License
22 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
24 #include "config.h"
26 #include <signal.h>
27 #include <stdlib.h>
29 #if HAVE_UNISTD_H
30 #include <unistd.h> /* for getpid */
31 #endif
33 #include "gmp.h"
34 #include "gmp-impl.h"
37 /* Incidentally, kill is not available on mingw, but that's ok, it has raise
38 and we'll be using that. */
39 #if ! HAVE_RAISE
40 #define raise(sig) kill (getpid(), sig)
41 #endif
44 /* __gmp_invalid_operation is for an invalid floating point operation, like
45 mpz_set_d on a NaN or Inf. It's done as a subroutine to minimize code in
46 places raising an exception.
48 feraiseexcept(FE_INVALID) is not used here, since unfortunately on most
49 systems it would require libm.
51 Alternatives:
53 It might be possible to check whether a hardware "invalid operation" trap
54 is enabled or not before raising a signal. This would require all
55 callers to be prepared to continue with some bogus result. Bogus returns
56 are bad, but presumably an application disabling the trap is prepared for
57 that.
59 On some systems (eg. BSD) the signal handler can find out the reason for
60 a SIGFPE (overflow, invalid, div-by-zero, etc). Perhaps we could get
61 that into our raise too.
63 i386 GLIBC implements feraiseexcept(FE_INVALID) with an asm fdiv 0/0.
64 That would both respect the exceptions mask and give a reason code in a
65 BSD signal. */
67 void
68 __gmp_invalid_operation (void)
70 raise (SIGFPE);
71 abort ();