1*c931458eSkettenis /* $OpenBSD: fenv.h,v 1.1 2020/06/28 08:19:34 kettenis Exp $ */ 2*c931458eSkettenis 3*c931458eSkettenis /* 4*c931458eSkettenis * Copyright (c) 2011 Martynas Venckus <martynas@openbsd.org> 5*c931458eSkettenis * 6*c931458eSkettenis * Permission to use, copy, modify, and distribute this software for any 7*c931458eSkettenis * purpose with or without fee is hereby granted, provided that the above 8*c931458eSkettenis * copyright notice and this permission notice appear in all copies. 9*c931458eSkettenis * 10*c931458eSkettenis * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11*c931458eSkettenis * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12*c931458eSkettenis * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13*c931458eSkettenis * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14*c931458eSkettenis * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15*c931458eSkettenis * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16*c931458eSkettenis * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17*c931458eSkettenis */ 18*c931458eSkettenis 19*c931458eSkettenis #ifndef _MACHINE_FENV_H_ 20*c931458eSkettenis #define _MACHINE_FENV_H_ 21*c931458eSkettenis 22*c931458eSkettenis /* 23*c931458eSkettenis * Each symbol representing a floating point exception expands to an integer 24*c931458eSkettenis * constant expression with values, such that bitwise-inclusive ORs of _all 25*c931458eSkettenis * combinations_ of the constants result in distinct values. 26*c931458eSkettenis * 27*c931458eSkettenis * We use such values that allow direct bitwise operations on FPU registers. 28*c931458eSkettenis */ 29*c931458eSkettenis #define FE_INEXACT 0x02000000 30*c931458eSkettenis #define FE_DIVBYZERO 0x04000000 31*c931458eSkettenis #define FE_UNDERFLOW 0x08000000 32*c931458eSkettenis #define FE_OVERFLOW 0x10000000 33*c931458eSkettenis #define FE_INVALID 0x20000000 34*c931458eSkettenis #define _FE_INVALID_SOFT 0x00000400 35*c931458eSkettenis #define _FE_INVALID_ALL 0x01f80700 36*c931458eSkettenis 37*c931458eSkettenis /* 38*c931458eSkettenis * The following symbol is simply the bitwise-inclusive OR of all floating-point 39*c931458eSkettenis * exception constants defined above. 40*c931458eSkettenis */ 41*c931458eSkettenis #define FE_ALL_EXCEPT (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | \ 42*c931458eSkettenis FE_OVERFLOW | FE_INVALID) 43*c931458eSkettenis #define _MASK_SHIFT 22 44*c931458eSkettenis 45*c931458eSkettenis /* 46*c931458eSkettenis * Each symbol representing the rounding direction, expands to an integer 47*c931458eSkettenis * constant expression whose value is distinct non-negative value. 48*c931458eSkettenis * 49*c931458eSkettenis * We use such values that allow direct bitwise operations on FPU registers. 50*c931458eSkettenis */ 51*c931458eSkettenis #define FE_TONEAREST 0x0 52*c931458eSkettenis #define FE_TOWARDZERO 0x1 53*c931458eSkettenis #define FE_UPWARD 0x2 54*c931458eSkettenis #define FE_DOWNWARD 0x3 55*c931458eSkettenis 56*c931458eSkettenis /* 57*c931458eSkettenis * The following symbol is simply the bitwise-inclusive OR of all floating-point 58*c931458eSkettenis * rounding direction constants defined above. 59*c931458eSkettenis */ 60*c931458eSkettenis #define _ROUND_MASK (FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD | \ 61*c931458eSkettenis FE_DOWNWARD) 62*c931458eSkettenis 63*c931458eSkettenis /* 64*c931458eSkettenis * fenv_t represents the entire floating-point environment. 65*c931458eSkettenis */ 66*c931458eSkettenis typedef unsigned int fenv_t; 67*c931458eSkettenis 68*c931458eSkettenis /* 69*c931458eSkettenis * The following constant represents the default floating-point environment 70*c931458eSkettenis * (that is, the one installed at program startup) and has type pointer to 71*c931458eSkettenis * const-qualified fenv_t. 72*c931458eSkettenis * 73*c931458eSkettenis * It can be used as an argument to the functions within the <fenv.h> header 74*c931458eSkettenis * that manage the floating-point environment, namely fesetenv() and 75*c931458eSkettenis * feupdateenv(). 76*c931458eSkettenis */ 77*c931458eSkettenis __BEGIN_DECLS 78*c931458eSkettenis extern fenv_t __fe_dfl_env; 79*c931458eSkettenis __END_DECLS 80*c931458eSkettenis #define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) 81*c931458eSkettenis 82*c931458eSkettenis /* 83*c931458eSkettenis * fexcept_t represents the floating-point status flags collectively, including 84*c931458eSkettenis * any status the implementation associates with the flags. 85*c931458eSkettenis * 86*c931458eSkettenis * A floating-point status flag is a system variable whose value is set (but 87*c931458eSkettenis * never cleared) when a floating-point exception is raised, which occurs as a 88*c931458eSkettenis * side effect of exceptional floating-point arithmetic to provide auxiliary 89*c931458eSkettenis * information. 90*c931458eSkettenis * 91*c931458eSkettenis * A floating-point control mode is a system variable whose value may be set by 92*c931458eSkettenis * the user to affect the subsequent behavior of floating-point arithmetic. 93*c931458eSkettenis */ 94*c931458eSkettenis typedef unsigned int fexcept_t; 95*c931458eSkettenis 96*c931458eSkettenis #endif /* !_MACHINE_FENV_H_ */ 97