1 /* gmp_errno, __gmp_exception -- exception handling and reporting. 2 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. 6 7 Copyright 2000, 2001, 2003 Free Software Foundation, Inc. 8 9 This file is part of the GNU MP Library. 10 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. 15 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. 20 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/. */ 23 24 #include <stdlib.h> 25 #include "gmp.h" 26 #include "gmp-impl.h" 27 28 int gmp_errno = 0; 29 30 31 /* The deliberate divide by zero triggers an exception on most systems. On 32 those where it doesn't, for example power and powerpc, use abort instead. 33 34 Enhancement: Perhaps raise(SIGFPE) (or the same with kill()) would be 35 better than abort. Perhaps it'd be possible to get the BSD style 36 FPE_INTDIV_TRAP parameter in there too. */ 37 38 void 39 __gmp_exception (int error_bit) 40 { 41 gmp_errno |= error_bit; 42 __gmp_junk = 10 / __gmp_0; 43 abort (); 44 } 45 46 47 /* These functions minimize the amount of code required in functions raising 48 exceptions. Since they're "noreturn" and don't take any parameters, a 49 test and call might even come out as a simple conditional jump. */ 50 void 51 __gmp_sqrt_of_negative (void) 52 { 53 __gmp_exception (GMP_ERROR_SQRT_OF_NEGATIVE); 54 } 55 void 56 __gmp_divide_by_zero (void) 57 { 58 __gmp_exception (GMP_ERROR_DIVISION_BY_ZERO); 59 } 60