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 2.1 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; see the file COPYING.LIB. If not, write to
23
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24
MA 02110-1301, USA. */
32
#include <unistd.h> /* for getpid */
39
/* Incidentally, kill is not available on mingw, but that's ok, it has raise
40
and we'll be using that. */
42
#define raise(sig) kill (getpid(), sig)
46
/* __gmp_invalid_operation is for an invalid floating point operation, like
47
mpz_set_d on a NaN or Inf. It's done as a subroutine to minimize code in
48
places raising an exception.
50
feraiseexcept(FE_INVALID) is not used here, since unfortunately on most
51
systems it would require libm.
55
It might be possible to check whether a hardware "invalid operation" trap
56
is enabled or not before raising a signal. This would require all
57
callers to be prepared to continue with some bogus result. Bogus returns
58
are bad, but presumably an application disabling the trap is prepared for
61
On some systems (eg. BSD) the signal handler can find out the reason for
62
a SIGFPE (overflow, invalid, div-by-zero, etc). Perhaps we could get
63
that into our raise too.
65
i386 GLIBC implements feraiseexcept(FE_INVALID) with an asm fdiv 0/0.
66
That would both respect the exceptions mask and give a reason code in a
70
__gmp_invalid_operation (void)