1 /* Raise given exceptions.
2 Copyright (C) 1997-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
21 #include <fpu_control.h>
25 __feraiseexcept (int excepts
)
30 /* Raise exceptions represented by EXPECTS. */
32 if (excepts
& FE_INEXACT
)
34 double d
= 1.0, x
= 3.0;
35 __asm__
__volatile__ ("fdiv %1, %0" : "+d" (d
) : "d" (x
));
38 if (excepts
& FE_UNDERFLOW
)
40 long double d
= LDBL_MIN
, x
= 10;
41 __asm__
__volatile__ ("fdiv %1, %0" : "+d" (d
) : "d" (x
));
44 if (excepts
& FE_OVERFLOW
)
46 long double d
= LDBL_MAX
;
47 __asm__
__volatile__ ("fmul %0, %0" : "+d" (d
) : "d" (d
));
50 if (excepts
& FE_DIVBYZERO
)
52 double d
= 1.0, x
= 0.0;
53 __asm__
__volatile__ ("fdiv %1, %0" : "+d" (d
) : "d" (x
));
56 if (excepts
& FE_INVALID
)
58 double d
= HUGE_VAL
, x
= 0.0;
59 __asm__
__volatile__ ("fmul %1, %0" : "+d" (d
) : "d" (x
));
63 /* Restore flag fields. */
66 cw
|= (excepts
& FE_ALL_EXCEPT
);
72 libm_hidden_def (__feraiseexcept
)
73 weak_alias (__feraiseexcept
, feraiseexcept
)
74 libm_hidden_weak (feraiseexcept
)