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