186d7f5d3SJohn Marino /* gmp_errno, __gmp_exception -- exception handling and reporting.
286d7f5d3SJohn Marino
386d7f5d3SJohn Marino THE FUNCTIONS IN THIS FILE, APART FROM gmp_errno, ARE FOR INTERNAL USE
486d7f5d3SJohn Marino ONLY. THEY'RE ALMOST CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR
586d7f5d3SJohn Marino DISAPPEAR COMPLETELY IN FUTURE GNU MP RELEASES.
686d7f5d3SJohn Marino
786d7f5d3SJohn Marino Copyright 2000, 2001, 2003 Free Software Foundation, Inc.
886d7f5d3SJohn Marino
986d7f5d3SJohn Marino This file is part of the GNU MP Library.
1086d7f5d3SJohn Marino
1186d7f5d3SJohn Marino The GNU MP Library is free software; you can redistribute it and/or modify
1286d7f5d3SJohn Marino it under the terms of the GNU Lesser General Public License as published by
1386d7f5d3SJohn Marino the Free Software Foundation; either version 3 of the License, or (at your
1486d7f5d3SJohn Marino option) any later version.
1586d7f5d3SJohn Marino
1686d7f5d3SJohn Marino The GNU MP Library is distributed in the hope that it will be useful, but
1786d7f5d3SJohn Marino WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1886d7f5d3SJohn Marino or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
1986d7f5d3SJohn Marino License for more details.
2086d7f5d3SJohn Marino
2186d7f5d3SJohn Marino You should have received a copy of the GNU Lesser General Public License
2286d7f5d3SJohn Marino along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
2386d7f5d3SJohn Marino
2486d7f5d3SJohn Marino #include <stdlib.h>
2586d7f5d3SJohn Marino #include "gmp.h"
2686d7f5d3SJohn Marino #include "gmp-impl.h"
2786d7f5d3SJohn Marino
2886d7f5d3SJohn Marino int gmp_errno = 0;
2986d7f5d3SJohn Marino
3086d7f5d3SJohn Marino
3186d7f5d3SJohn Marino /* The deliberate divide by zero triggers an exception on most systems. On
3286d7f5d3SJohn Marino those where it doesn't, for example power and powerpc, use abort instead.
3386d7f5d3SJohn Marino
3486d7f5d3SJohn Marino Enhancement: Perhaps raise(SIGFPE) (or the same with kill()) would be
3586d7f5d3SJohn Marino better than abort. Perhaps it'd be possible to get the BSD style
3686d7f5d3SJohn Marino FPE_INTDIV_TRAP parameter in there too. */
3786d7f5d3SJohn Marino
3886d7f5d3SJohn Marino void
__gmp_exception(int error_bit)3986d7f5d3SJohn Marino __gmp_exception (int error_bit)
4086d7f5d3SJohn Marino {
4186d7f5d3SJohn Marino gmp_errno |= error_bit;
4286d7f5d3SJohn Marino __gmp_junk = 10 / __gmp_0;
4386d7f5d3SJohn Marino abort ();
4486d7f5d3SJohn Marino }
4586d7f5d3SJohn Marino
4686d7f5d3SJohn Marino
4786d7f5d3SJohn Marino /* These functions minimize the amount of code required in functions raising
4886d7f5d3SJohn Marino exceptions. Since they're "noreturn" and don't take any parameters, a
4986d7f5d3SJohn Marino test and call might even come out as a simple conditional jump. */
5086d7f5d3SJohn Marino void
__gmp_sqrt_of_negative(void)5186d7f5d3SJohn Marino __gmp_sqrt_of_negative (void)
5286d7f5d3SJohn Marino {
5386d7f5d3SJohn Marino __gmp_exception (GMP_ERROR_SQRT_OF_NEGATIVE);
5486d7f5d3SJohn Marino }
5586d7f5d3SJohn Marino void
__gmp_divide_by_zero(void)5686d7f5d3SJohn Marino __gmp_divide_by_zero (void)
5786d7f5d3SJohn Marino {
5886d7f5d3SJohn Marino __gmp_exception (GMP_ERROR_DIVISION_BY_ZERO);
5986d7f5d3SJohn Marino }
60