[18190] | 1 | /* gmp_errno, __gmp_exception -- exception handling and reporting. |
---|

[15293] | 2 | |
---|

[18190] | 3 | Copyright 2000, 2001 Free Software Foundation, Inc. |
---|

[15293] | 4 | |
---|

| 5 | This file is part of the GNU MP Library. |
---|

| 6 | |
---|

| 7 | The GNU MP Library is free software; you can redistribute it and/or modify |
---|

| 8 | it under the terms of the GNU Lesser General Public License as published by |
---|

| 9 | the Free Software Foundation; either version 2.1 of the License, or (at your |
---|

| 10 | option) any later version. |
---|

| 11 | |
---|

| 12 | The GNU MP Library is distributed in the hope that it will be useful, but |
---|

| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
---|

| 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
---|

| 15 | License for more details. |
---|

| 16 | |
---|

| 17 | You should have received a copy of the GNU Lesser General Public License |
---|

| 18 | along with the GNU MP Library; see the file COPYING.LIB. If not, write to |
---|

| 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
---|

| 20 | MA 02111-1307, USA. */ |
---|

| 21 | |
---|

[18190] | 22 | #include <stdlib.h> |
---|

[15293] | 23 | #include "gmp.h" |
---|

| 24 | #include "gmp-impl.h" |
---|

| 25 | |
---|

| 26 | int gmp_errno = 0; |
---|

[18190] | 27 | |
---|

| 28 | |
---|

| 29 | /* The deliberate divide by zero triggers an exception on most systems. On |
---|

| 30 | those where it doesn't, for example power and powerpc, use abort instead. |
---|

| 31 | |
---|

| 32 | Enhancement: Perhaps raise(SIGFPE) (or the same with kill()) would be |
---|

| 33 | better than abort. Perhaps it'd be possible to get the BSD style |
---|

| 34 | FPE_INTDIV_TRAP parameter in there too. */ |
---|

| 35 | |
---|

| 36 | void |
---|

| 37 | __gmp_exception (int error_bit) |
---|

| 38 | { |
---|

| 39 | gmp_errno |= error_bit; |
---|

| 40 | __gmp_junk = 10 / __gmp_0; |
---|

| 41 | abort (); |
---|

| 42 | } |
---|

| 43 | |
---|

| 44 | |
---|

| 45 | /* These functions minimize the amount of code required in functions raising |
---|

| 46 | exceptions. Since they're "noreturn" and don't take any parameters, a |
---|

| 47 | test and call might even come out as a simple conditional jump. */ |
---|

| 48 | void |
---|

| 49 | __gmp_sqrt_of_negative (void) |
---|

| 50 | { |
---|

| 51 | __gmp_exception (GMP_ERROR_SQRT_OF_NEGATIVE); |
---|

| 52 | } |
---|

| 53 | void |
---|

| 54 | __gmp_divide_by_zero (void) |
---|

| 55 | { |
---|

| 56 | __gmp_exception (GMP_ERROR_DIVISION_BY_ZERO); |
---|

| 57 | } |
---|