• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*  $OpenBSD: fenv.h,v 1.2 2011/05/25 21:46:49 martynas Exp $ */
2 /*  $NetBSD: fenv.h,v 1.2.4.1 2011/02/08 16:18:55 bouyer Exp $  */
3 
4 /*
5  * Copyright (c) 2010 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #pragma once
31 
32 /**
33  * @file fenv.h
34  * @brief Floating-point environment.
35  */
36 
37 #include <sys/cdefs.h>
38 
39 #if defined(__aarch64__) || defined(__arm__)
40 #include <bits/fenv_arm.h>
41 #elif defined(__i386__)
42 #include <bits/fenv_x86.h>
43 #elif defined(__riscv)
44 #include <bits/fenv_riscv64.h>
45 #elif defined(__x86_64__)
46 #include <bits/fenv_x86_64.h>
47 #endif
48 
49 __BEGIN_DECLS
50 
51 /**
52  * [feclearexcept(3)](http://man7.org/linux/man-pages/man3/feclearexcept.3.html)
53  * clears the given `exceptions` in hardware.
54  *
55  * Returns 0 on success, and returns non-zero on failure.
56  */
57 int feclearexcept(int __exceptions);
58 
59 /**
60  * [fegetexceptflag(3)](http://man7.org/linux/man-pages/man3/fegetexceptflag.3.html)
61  * copies the state of the given `exceptions` from hardware into `*flag_ptr`.
62  * See fesetexceptflag().
63  *
64  * Returns 0 on success, and returns non-zero on failure.
65  */
66 int fegetexceptflag(fexcept_t* _Nonnull __flag_ptr, int __exceptions);
67 
68 /**
69  * [feraiseexcept(3)](http://man7.org/linux/man-pages/man3/feraiseexcept.3.html)
70  * raises the given `exceptions` in hardware.
71  *
72  * Returns 0 on success, and returns non-zero on failure.
73  */
74 int feraiseexcept(int __exceptions);
75 
76 /**
77  * [fesetexceptflag(3)](http://man7.org/linux/man-pages/man3/fesetexceptflag.3.html)
78  * copies the state of the given `exceptions` from `*flag_ptr` into hardware.
79  * See fesetexceptflag().
80  *
81  * Returns 0 on success, and returns non-zero on failure.
82  */
83 int fesetexceptflag(const fexcept_t* _Nonnull __flag_ptr, int __exceptions);
84 
85 /**
86  * [fetestexcept(3)](http://man7.org/linux/man-pages/man3/fetestexcept.3.html)
87  * tests whether the given `exceptions` are set in hardware.
88  *
89  * Returns the currently-set subset of `exceptions`.
90  */
91 int fetestexcept(int __exceptions);
92 
93 /**
94  * [fegetround(3)](http://man7.org/linux/man-pages/man3/fegetround.3.html)
95  * returns the current rounding mode.
96  *
97  * Returns the rounding mode on success, and returns a negative value on failure.
98  */
99 int fegetround(void);
100 
101 /**
102  * [fesetround(3)](http://man7.org/linux/man-pages/man3/fesetround.3.html)
103  * sets the current rounding mode.
104  *
105  * Returns 0 on success, and returns non-zero on failure.
106  */
107 int fesetround(int __rounding_mode);
108 
109 /**
110  * [fegetenv(3)](http://man7.org/linux/man-pages/man3/fegetenv.3.html)
111  * gets the current floating-point environment. See fesetenv().
112  *
113  * Returns 0 on success, and returns non-zero on failure.
114  */
115 int fegetenv(fenv_t* _Nonnull __env);
116 
117 /**
118  * [feholdexcept(3)](http://man7.org/linux/man-pages/man3/feholdexcept.3.html)
119  * gets the current floating-point environment, clears the status flags, and
120  * ignores floating point exceptions. See fesetenv()/feupdateenv().
121  *
122  * Returns 0 on success, and returns non-zero on failure.
123  */
124 int feholdexcept(fenv_t* _Nonnull __env);
125 
126 /**
127  * [fesetenv(3)](http://man7.org/linux/man-pages/man3/fesetenv.3.html)
128  * sets the current floating-point environment. See fegetenv().
129  *
130  * Returns 0 on success, and returns non-zero on failure.
131  */
132 int fesetenv(const fenv_t* _Nonnull __env);
133 
134 /**
135  * [feupdateenv(3)](http://man7.org/linux/man-pages/man3/feupdateenv.3.html)
136  * sets the current floating-point environment to `*env` but with currently-raised
137  * exceptions still raised. See fesetenv().
138  *
139  * Returns 0 on success, and returns non-zero on failure.
140  */
141 int feupdateenv(const fenv_t* _Nonnull __env);
142 
143 /**
144  * [feenableexcept(3)](http://man7.org/linux/man-pages/man3/feenableexcept.3.html)
145  * sets the given `exceptions` to trap, if the hardware supports it. This is not
146  * generally useful on Android, because only x86/x86-64 can trap.
147  *
148  * Returns the previous set of enabled exceptions on success, and returns -1 on failure.
149  */
150 int feenableexcept(int __exceptions);
151 
152 /**
153  * [fedisableexcept(3)](http://man7.org/linux/man-pages/man3/fedisableexcept.3.html)
154  * sets the given `exceptions` to not trap, if the hardware supports it. This is not
155  * generally useful on Android, because only x86/x86-64 can trap.
156  *
157  * Returns the previous set of enabled exceptions on success, and returns -1 on failure.
158  */
159 int fedisableexcept(int __exceptions);
160 
161 /**
162  * [fegetexcept(3)](http://man7.org/linux/man-pages/man3/fegetexcept.3.html)
163  * returns the exceptions that currently trap. This is not generally useful on
164  * Android, because only x86/x86-64 can trap.
165  *
166  * Returns the exceptions that currently trap.
167  */
168 int fegetexcept(void);
169 
170 /** See FE_DFL_ENV. */
171 extern const fenv_t __fe_dfl_env;
172 
173 /**
174  * Constant representing the default floating-point environment
175  * (that is, the one installed at program startup).
176  *
177  * It can be used as an argument to the functions that manage the floating-point
178  * environment, namely fesetenv() and feupdateenv().
179  */
180 #define FE_DFL_ENV (&__fe_dfl_env)
181 
182 __END_DECLS
183