Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / am33 / fpu / fraiseexcpt.c
blobb86a51eb8e4b6934d27e59130c26920073220cd7
1 /* Raise given exceptions.
2 Copyright (C) 2000-2014 Free Software Foundation, Inc.
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.
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.
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.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library. If not, see
19 <http://www.gnu.org/licenses/>. */
21 #include <fenv.h>
22 #include <float.h>
23 #include <math.h>
24 #include <shlib-compat.h>
26 int
27 __feraiseexcept (int excepts)
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. */
35 /* First: invalid exception. */
36 if (excepts & FE_INVALID)
38 /* One example of an invalid operation is 0 * Infinity. */
39 float x = HUGE_VALF, y = 0.0f;
40 __asm__ __volatile__ ("fmul %1,%0" : "+f" (x) : "f" (y));
43 /* Next: division by zero. */
44 if (excepts & FE_DIVBYZERO)
46 float x = 1.0f, y = 0.0f;
47 __asm__ __volatile__ ("fdiv %1,%0" : "+f" (x) : "f" (y));
50 /* Next: overflow. */
51 if (excepts & FE_OVERFLOW)
53 float x = FLT_MAX;
55 __asm__ __volatile__ ("fmul %0,%0" : "+f" (x));
58 /* Next: underflow. */
59 if (excepts & FE_UNDERFLOW)
61 float x = -FLT_MIN;
63 __asm__ __volatile__ ("fmul %0,%0" : "+f" (x));
66 /* Last: inexact. */
67 if (excepts & FE_INEXACT)
69 float x = 1.0f, y = 3.0f;
70 __asm__ __volatile__ ("fdiv %1,%0" : "=f" (x) : "f" (y));
73 /* Success. */
74 return 0;
77 libm_hidden_ver (__feraiseexcept, feraiseexcept)
78 versioned_symbol (libm, __feraiseexcept, feraiseexcept, GLIBC_2_2);