1 /* Copyright (c) 2011 Tensilica Inc.  ALL RIGHTS RESERVED.
2 
3    Redistribution and use in source and binary forms, with or without
4    modification, are permitted provided that the following conditions
5    are met:
6 
7    1. Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9 
10    2. Redistributions in binary form must reproduce the above
11       copyright notice, this list of conditions and the following
12       disclaimer in the documentation and/or other materials provided
13       with the distribution.
14 
15    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18    FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
19    TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT,
20    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26    OF THE POSSIBILITY OF SUCH DAMAGE.  */
27 
28 
29 #ifndef _FENV_H
30 #define _FENV_H
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef unsigned long fenv_t;
37 typedef unsigned long fexcept_t;
38 
39 #define FE_DIVBYZERO   0x08
40 #define FE_INEXACT     0x01
41 #define FE_INVALID     0x10
42 #define FE_OVERFLOW    0x04
43 #define FE_UNDERFLOW   0x02
44 
45 #define FE_ALL_EXCEPT \
46   (FE_DIVBYZERO  |		      \
47    FE_INEXACT    |		      \
48    FE_INVALID    |		      \
49    FE_OVERFLOW   |		      \
50    FE_UNDERFLOW)
51 
52 #define FE_DOWNWARD   0x3
53 #define FE_TONEAREST  0x0
54 #define FE_TOWARDZERO 0x1
55 #define FE_UPWARD     0x2
56 
57 #define FE_DFL_ENV ((const fenv_t *) 0)
58 
59 int  feclearexcept(int);
60 int  fegetexceptflag(fexcept_t *, int);
61 int  feraiseexcept(int);
62 int  fesetexceptflag(const fexcept_t *, int);
63 int  fetestexcept(int);
64 int  fegetround(void);
65 int  fesetround(int);
66 int  fegetenv(fenv_t *);
67 int  feholdexcept(fenv_t *);
68 int  fesetenv(const fenv_t *);
69 int  feupdateenv(const fenv_t *);
70 
71 /* glibc extensions  */
72 int feenableexcept(int excepts);
73 int fedisableexcept(int excepts);
74 int fegetexcept(void);
75 
76 #define _FE_EXCEPTION_FLAGS_OFFSET 7
77 #define _FE_EXCEPTION_FLAG_MASK (FE_ALL_EXCEPT << _FE_EXCEPTION_FLAGS_OFFSET)
78 #define _FE_EXCEPTION_ENABLE_OFFSET 2
79 #define _FE_EXCEPTION_ENABLE_MASK (FE_ALL_EXCEPT << _FE_EXCEPTION_ENABLE_OFFSET)
80 #define _FE_ROUND_MODE_OFFSET 0
81 #define _FE_ROUND_MODE_MASK (0x3 << _FE_ROUND_MODE_OFFSET)
82 #define _FE_FLOATING_ENV_MASK (_FE_EXCEPTION_FLAG_MASK | _FE_EXCEPTION_ENABLE_MASK | _FE_ROUND_MODE_MASK)
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
88 #endif
89