beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / invalid.c
blob81d6720c0ddc5e1e0667a3bb9c998aaef43a2bd7
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 either:
14 * the GNU Lesser General Public License as published by the Free
15 Software Foundation; either version 3 of the License, or (at your
16 option) any later version.
20 * the GNU General Public License as published by the Free Software
21 Foundation; either version 2 of the License, or (at your option) any
22 later version.
24 or both in parallel, as here.
26 The GNU MP Library is distributed in the hope that it will be useful, but
27 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
28 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29 for more details.
31 You should have received copies of the GNU General Public License and the
32 GNU Lesser General Public License along with the GNU MP Library. If not,
33 see https://www.gnu.org/licenses/. */
35 #include "config.h"
37 #include <signal.h>
38 #include <stdlib.h>
40 #if HAVE_UNISTD_H
41 #include <unistd.h> /* for getpid */
42 #endif
44 #include "gmp.h"
45 #include "gmp-impl.h"
48 /* Incidentally, kill is not available on mingw, but that's ok, it has raise
49 and we'll be using that. */
50 #if ! HAVE_RAISE
51 #define raise(sig) kill (getpid(), sig)
52 #endif
55 /* __gmp_invalid_operation is for an invalid floating point operation, like
56 mpz_set_d on a NaN or Inf. It's done as a subroutine to minimize code in
57 places raising an exception.
59 feraiseexcept(FE_INVALID) is not used here, since unfortunately on most
60 systems it would require libm.
62 Alternatives:
64 It might be possible to check whether a hardware "invalid operation" trap
65 is enabled or not before raising a signal. This would require all
66 callers to be prepared to continue with some bogus result. Bogus returns
67 are bad, but presumably an application disabling the trap is prepared for
68 that.
70 On some systems (eg. BSD) the signal handler can find out the reason for
71 a SIGFPE (overflow, invalid, div-by-zero, etc). Perhaps we could get
72 that into our raise too.
74 i386 GLIBC implements feraiseexcept(FE_INVALID) with an asm fdiv 0/0.
75 That would both respect the exceptions mask and give a reason code in a
76 BSD signal. */
78 void
79 __gmp_invalid_operation (void)
81 raise (SIGFPE);
82 abort ();