blob: faec985f8e35b5863e0f72ebf2b29425edb06aa8 [file] [log] [blame]
George Landerda55ef92015-11-19 12:05:06 +00001/*
Szabolcs Nagy1b945972018-05-14 14:46:40 +01002 * dunder.c - manually provoke FP exceptions for mathlib
George Landerda55ef92015-11-19 12:05:06 +00003 *
Szabolcs Nagy11253b02018-11-12 11:10:57 +00004 * Copyright (c) 2009-2018, Arm Limited.
5 * SPDX-License-Identifier: MIT
George Landerda55ef92015-11-19 12:05:06 +00006 */
7
8
9#include "math_private.h"
10#include <fenv.h>
11
12__inline double __mathlib_dbl_infnan(double x)
13{
14 return x+x;
15}
16
17__inline double __mathlib_dbl_infnan2(double x, double y)
18{
19 return x+y;
20}
21
22double __mathlib_dbl_underflow(void)
23{
24#ifdef CLANG_EXCEPTIONS
25 feraiseexcept(FE_UNDERFLOW);
26#endif
27 return 0x1p-767 * 0x1p-767;
28}
29
30double __mathlib_dbl_overflow(void)
31{
32#ifdef CLANG_EXCEPTIONS
33 feraiseexcept(FE_OVERFLOW);
34#endif
35 return 0x1p+769 * 0x1p+769;
36}
37
38double __mathlib_dbl_invalid(void)
39{
40#ifdef CLANG_EXCEPTIONS
41 feraiseexcept(FE_INVALID);
42#endif
43 return 0.0 / 0.0;
44}
45
46double __mathlib_dbl_divzero(void)
47{
48#ifdef CLANG_EXCEPTIONS
49 feraiseexcept(FE_DIVBYZERO);
50#endif
51 return 1.0 / 0.0;
52}