blob: f7dcc8e4f85104057a9766e0dc278b747a922ba6 [file] [log] [blame]
Calin Juravle2d367902014-02-25 14:49:41 +00001/* $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
Elliott Hughes222ce952018-08-30 09:26:43 -070030#pragma once
Calin Juravle2d367902014-02-25 14:49:41 +000031
Elliott Hughes9cf60362023-05-26 12:53:42 -070032/**
33 * @file fenv.h
34 * @brief Floating-point environment.
35 */
36
Calin Juravle2d367902014-02-25 14:49:41 +000037#include <sys/cdefs.h>
Elliott Hughesd4ca2312017-10-11 22:27:45 -070038
Elliott Hughesb6c7f6e2017-11-03 16:46:32 -070039#if defined(__aarch64__) || defined(__arm__)
Elliott Hughesd4ca2312017-10-11 22:27:45 -070040#include <bits/fenv_arm.h>
41#elif defined(__i386__)
42#include <bits/fenv_x86.h>
Elliott Hughes4c6d66c2022-10-07 20:46:48 +000043#elif defined(__riscv)
44#include <bits/fenv_riscv64.h>
Elliott Hughesd4ca2312017-10-11 22:27:45 -070045#elif defined(__x86_64__)
46#include <bits/fenv_x86_64.h>
47#endif
Calin Juravle2d367902014-02-25 14:49:41 +000048
49__BEGIN_DECLS
50
Elliott Hughes9cf60362023-05-26 12:53:42 -070051/**
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 */
57int feclearexcept(int __exceptions);
Calin Juravle2d367902014-02-25 14:49:41 +000058
Elliott Hughes9cf60362023-05-26 12:53:42 -070059/**
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 */
66int fegetexceptflag(fexcept_t* _Nonnull __flag_ptr, int __exceptions);
Calin Juravle2d367902014-02-25 14:49:41 +000067
Elliott Hughes9cf60362023-05-26 12:53:42 -070068/**
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 */
74int feraiseexcept(int __exceptions);
Calin Juravle2d367902014-02-25 14:49:41 +000075
Elliott Hughes9cf60362023-05-26 12:53:42 -070076/**
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 */
83int fesetexceptflag(const fexcept_t* _Nonnull __flag_ptr, int __exceptions);
Calin Juravle2d367902014-02-25 14:49:41 +000084
Elliott Hughes9cf60362023-05-26 12:53:42 -070085/**
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 */
91int 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 */
99int 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 */
107int 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 */
115int 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 */
124int 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 */
132int 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 */
141int 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 */
150int 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 */
159int 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 */
168int fegetexcept(void);
169
170/** See FE_DFL_ENV. */
171extern 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).
Calin Juravle2d367902014-02-25 14:49:41 +0000176 *
177 * It can be used as an argument to the functions that manage the floating-point
178 * environment, namely fesetenv() and feupdateenv().
179 */
Elliott Hughes222ce952018-08-30 09:26:43 -0700180#define FE_DFL_ENV (&__fe_dfl_env)
Calin Juravle2d367902014-02-25 14:49:41 +0000181
Calin Juravle2d367902014-02-25 14:49:41 +0000182__END_DECLS