fenv.h revision 1.26 1 /* $NetBSD: fenv.h,v 1.26 2017/04/09 15:29:07 christos Exp $ */
2 /*
3 * Copyright (c) 2010 The NetBSD Foundation, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27 #ifndef _FENV_H_
28 #define _FENV_H_
29
30 #include <sys/featuretest.h>
31
32 #if defined(__vax__)
33 # ifndef __TEST_FENV
34 # error "fenv.h is currently not supported for this architecture"
35 # endif
36 typedef int fexcept_t;
37 typedef int fenv_t;
38 #else
39 # define __HAVE_FENV
40 # include <machine/fenv.h>
41 #endif
42
43 #if \
44 (defined(__arm__) && defined(__SOFTFP__)) || \
45 (defined(__m68k__) && !defined(__HAVE_68881__)) || \
46 defined(__mips_soft_float) || \
47 (defined(__powerpc__) && defined(_SOFT_FLOAT)) || \
48 (defined(__sh__) && !defined(__SH_FPU_ANY__)) || \
49 0
50
51 /*
52 * Common definitions for softfloat.
53 */
54
55 #ifndef __HAVE_FENV_SOFTFLOAT_DEFS
56
57 typedef int fexcept_t;
58
59 typedef struct {
60 int __flags;
61 int __mask;
62 int __round;
63 } fenv_t;
64
65 #define __FENV_GET_FLAGS(__envp) (__envp)->__flags
66 #define __FENV_GET_MASK(__envp) (__envp)->__mask
67 #define __FENV_GET_ROUND(__envp) (__envp)->__round
68 #define __FENV_SET_FLAGS(__envp, __val) \
69 (__envp)->__flags = (__val)
70 #define __FENV_SET_MASK(__envp, __val) \
71 (__envp)->__mask = (__val)
72 #define __FENV_SET_ROUND(__envp, __val) \
73 (__envp)->__round = (__val)
74
75 #endif /* __FENV_GET_FLAGS */
76
77 #endif /* softfloat */
78
79 __BEGIN_DECLS
80
81 /* Function prototypes */
82 int feclearexcept(int);
83 int fegetexceptflag(fexcept_t *, int);
84 int feraiseexcept(int);
85 int fesetexceptflag(const fexcept_t *, int);
86 int fetestexcept(int);
87 int fegetround(void);
88 int fesetround(int);
89 int fegetenv(fenv_t *);
90 int feholdexcept(fenv_t *);
91 int fesetenv(const fenv_t *);
92 int feupdateenv(const fenv_t *);
93
94 #if defined(_NETBSD_SOURCE) || defined(_GNU_SOURCE)
95
96 int feenableexcept(int);
97 int fedisableexcept(int);
98 int fegetexcept(void);
99
100 #endif /* _NETBSD_SOURCE || _GNU_SOURCE */
101
102 __END_DECLS
103
104 #endif /* ! _FENV_H_ */
105