| Calin Juravle | 2d36790 | 2014-02-25 14:49:41 +0000 | [diff] [blame] | 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 |  | 
| Elliott Hughes | 222ce95 | 2018-08-30 09:26:43 -0700 | [diff] [blame] | 30 | #pragma once | 
| Calin Juravle | 2d36790 | 2014-02-25 14:49:41 +0000 | [diff] [blame] | 31 |  | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 32 | /** | 
|  | 33 | * @file fenv.h | 
|  | 34 | * @brief Floating-point environment. | 
|  | 35 | */ | 
|  | 36 |  | 
| Calin Juravle | 2d36790 | 2014-02-25 14:49:41 +0000 | [diff] [blame] | 37 | #include <sys/cdefs.h> | 
| Elliott Hughes | d4ca231 | 2017-10-11 22:27:45 -0700 | [diff] [blame] | 38 |  | 
| Elliott Hughes | b6c7f6e | 2017-11-03 16:46:32 -0700 | [diff] [blame] | 39 | #if defined(__aarch64__) || defined(__arm__) | 
| Elliott Hughes | d4ca231 | 2017-10-11 22:27:45 -0700 | [diff] [blame] | 40 | #include <bits/fenv_arm.h> | 
|  | 41 | #elif defined(__i386__) | 
|  | 42 | #include <bits/fenv_x86.h> | 
| Elliott Hughes | 4c6d66c | 2022-10-07 20:46:48 +0000 | [diff] [blame] | 43 | #elif defined(__riscv) | 
|  | 44 | #include <bits/fenv_riscv64.h> | 
| Elliott Hughes | d4ca231 | 2017-10-11 22:27:45 -0700 | [diff] [blame] | 45 | #elif defined(__x86_64__) | 
|  | 46 | #include <bits/fenv_x86_64.h> | 
|  | 47 | #endif | 
| Calin Juravle | 2d36790 | 2014-02-25 14:49:41 +0000 | [diff] [blame] | 48 |  | 
|  | 49 | __BEGIN_DECLS | 
|  | 50 |  | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 51 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 52 | * [feclearexcept(3)](https://man7.org/linux/man-pages/man3/feclearexcept.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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); | 
| Calin Juravle | 2d36790 | 2014-02-25 14:49:41 +0000 | [diff] [blame] | 58 |  | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 59 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 60 | * [fegetexceptflag(3)](https://man7.org/linux/man-pages/man3/fegetexceptflag.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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); | 
| Calin Juravle | 2d36790 | 2014-02-25 14:49:41 +0000 | [diff] [blame] | 67 |  | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 68 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 69 | * [feraiseexcept(3)](https://man7.org/linux/man-pages/man3/feraiseexcept.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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); | 
| Calin Juravle | 2d36790 | 2014-02-25 14:49:41 +0000 | [diff] [blame] | 75 |  | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 76 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 77 | * [fesetexceptflag(3)](https://man7.org/linux/man-pages/man3/fesetexceptflag.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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); | 
| Calin Juravle | 2d36790 | 2014-02-25 14:49:41 +0000 | [diff] [blame] | 84 |  | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 85 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 86 | * [fetestexcept(3)](https://man7.org/linux/man-pages/man3/fetestexcept.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 94 | * [fegetround(3)](https://man7.org/linux/man-pages/man3/fegetround.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 102 | * [fesetround(3)](https://man7.org/linux/man-pages/man3/fesetround.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 110 | * [fegetenv(3)](https://man7.org/linux/man-pages/man3/fegetenv.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 118 | * [feholdexcept(3)](https://man7.org/linux/man-pages/man3/feholdexcept.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 127 | * [fesetenv(3)](https://man7.org/linux/man-pages/man3/fesetenv.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 135 | * [feupdateenv(3)](https://man7.org/linux/man-pages/man3/feupdateenv.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 144 | * [feenableexcept(3)](https://man7.org/linux/man-pages/man3/feenableexcept.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 153 | * [fedisableexcept(3)](https://man7.org/linux/man-pages/man3/fedisableexcept.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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 | /** | 
| Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 162 | * [fegetexcept(3)](https://man7.org/linux/man-pages/man3/fegetexcept.3.html) | 
| Elliott Hughes | 9cf6036 | 2023-05-26 12:53:42 -0700 | [diff] [blame] | 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). | 
| Calin Juravle | 2d36790 | 2014-02-25 14:49:41 +0000 | [diff] [blame] | 176 | * | 
|  | 177 | * It can be used as an argument to the functions that manage the floating-point | 
|  | 178 | * environment, namely fesetenv() and feupdateenv(). | 
|  | 179 | */ | 
| Elliott Hughes | 222ce95 | 2018-08-30 09:26:43 -0700 | [diff] [blame] | 180 | #define FE_DFL_ENV (&__fe_dfl_env) | 
| Calin Juravle | 2d36790 | 2014-02-25 14:49:41 +0000 | [diff] [blame] | 181 |  | 
| Calin Juravle | 2d36790 | 2014-02-25 14:49:41 +0000 | [diff] [blame] | 182 | __END_DECLS |