aboutsummaryrefslogtreecommitdiff
path: root/math/single/dunder.c
blob: faec985f8e35b5863e0f72ebf2b29425edb06aa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * dunder.c - manually provoke FP exceptions for mathlib
 *
 * Copyright (c) 2009-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */


#include "math_private.h"
#include <fenv.h>

__inline double __mathlib_dbl_infnan(double x)
{
  return x+x;
}

__inline double __mathlib_dbl_infnan2(double x, double y)
{
  return x+y;
}

double __mathlib_dbl_underflow(void)
{
#ifdef CLANG_EXCEPTIONS
  feraiseexcept(FE_UNDERFLOW);
#endif
  return 0x1p-767 * 0x1p-767;
}

double __mathlib_dbl_overflow(void)
{
#ifdef CLANG_EXCEPTIONS
  feraiseexcept(FE_OVERFLOW);
#endif
  return 0x1p+769 * 0x1p+769;
}

double __mathlib_dbl_invalid(void)
{
#ifdef CLANG_EXCEPTIONS
  feraiseexcept(FE_INVALID);
#endif
  return 0.0 / 0.0;
}

double __mathlib_dbl_divzero(void)
{
#ifdef CLANG_EXCEPTIONS
  feraiseexcept(FE_DIVBYZERO);
#endif
  return 1.0 / 0.0;
}