beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / errno.c
blobd3c02ef4b82e8a370bc9a10f1cbba7736e710576
1 /* gmp_errno, __gmp_exception -- exception handling and reporting.
3 THE FUNCTIONS IN THIS FILE, APART FROM gmp_errno, ARE FOR INTERNAL USE
4 ONLY. THEY'RE ALMOST CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR
5 DISAPPEAR COMPLETELY IN FUTURE GNU MP RELEASES.
7 Copyright 2000, 2001, 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 <stdlib.h>
36 #include "gmp.h"
37 #include "gmp-impl.h"
39 int gmp_errno = 0;
42 /* The deliberate divide by zero triggers an exception on most systems. On
43 those where it doesn't, for example power and powerpc, use abort instead.
45 Enhancement: Perhaps raise(SIGFPE) (or the same with kill()) would be
46 better than abort. Perhaps it'd be possible to get the BSD style
47 FPE_INTDIV_TRAP parameter in there too. */
49 void
50 __gmp_exception (int error_bit)
52 gmp_errno |= error_bit;
53 __gmp_junk = 10 / __gmp_0;
54 abort ();
58 /* These functions minimize the amount of code required in functions raising
59 exceptions. Since they're "noreturn" and don't take any parameters, a
60 test and call might even come out as a simple conditional jump. */
61 void
62 __gmp_sqrt_of_negative (void)
64 __gmp_exception (GMP_ERROR_SQRT_OF_NEGATIVE);
66 void
67 __gmp_divide_by_zero (void)
69 __gmp_exception (GMP_ERROR_DIVISION_BY_ZERO);