]>
Commit | Line | Data |
---|---|---|
d115c0d8 | 1 | /* Raise given exceptions. |
d4697bc9 | 2 | Copyright (C) 2000-2014 Free Software Foundation, Inc. |
d115c0d8 AO |
3 | This file is part of the GNU C Library. |
4 | Contributed by Alexandre Oliva <aoliva@redhat.com> | |
5 | based on corresponding file in the M68K port. | |
6 | ||
7 | The GNU C Library is free software; you can redistribute it and/or | |
8 | modify it under the terms of the GNU Lesser General Public | |
9 | License as published by the Free Software Foundation; either | |
10 | version 2.1 of the License, or (at your option) any later version. | |
11 | ||
12 | The GNU C Library is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public | |
ab84e3ff PE |
18 | License along with the GNU C Library. If not, see |
19 | <http://www.gnu.org/licenses/>. */ | |
d115c0d8 AO |
20 | |
21 | #include <fenv.h> | |
22 | #include <float.h> | |
23 | #include <math.h> | |
24 | #include <shlib-compat.h> | |
25 | ||
26 | int | |
27 | __feraiseexcept (int excepts) | |
28 | { | |
29 | /* Raise exceptions represented by EXCEPTS. But we must raise only one | |
30 | signal at a time. It is important that if the overflow/underflow | |
31 | exception and the divide by zero exception are given at the same | |
32 | time, the overflow/underflow exception follows the divide by zero | |
33 | exception. */ | |
34 | ||
35 | /* First: invalid exception. */ | |
36 | if (excepts & FE_INVALID) | |
37 | { | |
c0c3f78a | 38 | /* One example of an invalid operation is 0 * Infinity. */ |
d115c0d8 AO |
39 | float x = HUGE_VALF, y = 0.0f; |
40 | __asm__ __volatile__ ("fmul %1,%0" : "+f" (x) : "f" (y)); | |
41 | } | |
42 | ||
43 | /* Next: division by zero. */ | |
44 | if (excepts & FE_DIVBYZERO) | |
45 | { | |
46 | float x = 1.0f, y = 0.0f; | |
47 | __asm__ __volatile__ ("fdiv %1,%0" : "+f" (x) : "f" (y)); | |
48 | } | |
49 | ||
50 | /* Next: overflow. */ | |
51 | if (excepts & FE_OVERFLOW) | |
52 | { | |
53 | float x = FLT_MAX; | |
54 | ||
55 | __asm__ __volatile__ ("fmul %0,%0" : "+f" (x)); | |
56 | } | |
57 | ||
58 | /* Next: underflow. */ | |
59 | if (excepts & FE_UNDERFLOW) | |
60 | { | |
61 | float x = -FLT_MIN; | |
62 | ||
63 | __asm__ __volatile__ ("fmul %0,%0" : "+f" (x)); | |
64 | } | |
65 | ||
66 | /* Last: inexact. */ | |
67 | if (excepts & FE_INEXACT) | |
68 | { | |
69 | float x = 1.0f, y = 3.0f; | |
70 | __asm__ __volatile__ ("fdiv %1,%0" : "=f" (x) : "f" (y)); | |
71 | } | |
72 | ||
73 | /* Success. */ | |
74 | return 0; | |
75 | } | |
76 | ||
77 | libm_hidden_ver (__feraiseexcept, feraiseexcept) | |
78 | versioned_symbol (libm, __feraiseexcept, feraiseexcept, GLIBC_2_2); |