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