xref: /openbsd/sys/arch/sh/include/fenv.h (revision c9683224)
1*c9683224Smartynas /*	$OpenBSD: fenv.h,v 1.3 2011/05/25 21:46:49 martynas Exp $	*/
26e40b843Smartynas 
36e40b843Smartynas /*
46e40b843Smartynas  * Copyright (c) 2011 Martynas Venckus <martynas@openbsd.org>
56e40b843Smartynas  *
66e40b843Smartynas  * Permission to use, copy, modify, and distribute this software for any
76e40b843Smartynas  * purpose with or without fee is hereby granted, provided that the above
86e40b843Smartynas  * copyright notice and this permission notice appear in all copies.
96e40b843Smartynas  *
106e40b843Smartynas  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
116e40b843Smartynas  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
126e40b843Smartynas  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
136e40b843Smartynas  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
146e40b843Smartynas  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
156e40b843Smartynas  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
166e40b843Smartynas  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
176e40b843Smartynas  */
186e40b843Smartynas 
196e40b843Smartynas #ifndef	_SH_FENV_H_
206e40b843Smartynas #define	_SH_FENV_H_
216e40b843Smartynas 
226e40b843Smartynas /*
236e40b843Smartynas  * Each symbol representing a floating point exception expands to an integer
246e40b843Smartynas  * constant expression with values, such that bitwise-inclusive ORs of _all
256e40b843Smartynas  * combinations_ of the constants result in distinct values.
266e40b843Smartynas  *
276e40b843Smartynas  * We use such values that allow direct bitwise operations on FPU registers.
286e40b843Smartynas  */
296e40b843Smartynas #define	FE_INEXACT		0x04
306e40b843Smartynas #define	FE_UNDERFLOW		0x08
316e40b843Smartynas #define	FE_OVERFLOW		0x10
326e40b843Smartynas #define	FE_DIVBYZERO		0x20
336e40b843Smartynas #define	FE_INVALID		0x40
346e40b843Smartynas 
356e40b843Smartynas /*
366e40b843Smartynas  * The following symbol is simply the bitwise-inclusive OR of all floating-point
376e40b843Smartynas  * exception constants defined above.
386e40b843Smartynas  */
39d6f349c8Smartynas #define	FE_ALL_EXCEPT		(FE_INEXACT | FE_UNDERFLOW | FE_OVERFLOW | \
40d6f349c8Smartynas 				 FE_DIVBYZERO | FE_INVALID)
41d6f349c8Smartynas #define	_MASK_SHIFT		5
426e40b843Smartynas 
436e40b843Smartynas /*
446e40b843Smartynas  * Each symbol representing the rounding direction, expands to an integer
456e40b843Smartynas  * constant expression whose value is distinct non-negative value.
466e40b843Smartynas  *
476e40b843Smartynas  * We use such values that allow direct bitwise operations on FPU registers.
486e40b843Smartynas  */
496e40b843Smartynas #define	FE_TONEAREST		0x0
506e40b843Smartynas #define	FE_TOWARDZERO		0x1
516e40b843Smartynas #define	FE_UPWARD		0x2
526e40b843Smartynas #define	FE_DOWNWARD		0x3
536e40b843Smartynas 
546e40b843Smartynas /*
55d6f349c8Smartynas  * The following symbol is simply the bitwise-inclusive OR of all floating-point
56d6f349c8Smartynas  * rounding direction constants defined above.
576e40b843Smartynas  */
58d6f349c8Smartynas #define	_ROUND_MASK		(FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD | \
59d6f349c8Smartynas 				 FE_DOWNWARD)
606e40b843Smartynas 
616e40b843Smartynas /*
62d6f349c8Smartynas  * fenv_t represents the entire floating-point environment.
636e40b843Smartynas  */
646e40b843Smartynas typedef	unsigned int		fenv_t;
656e40b843Smartynas 
66d6f349c8Smartynas /*
67d6f349c8Smartynas  * The following constant represents the default floating-point environment
68d6f349c8Smartynas  * (that is, the one installed at program startup) and has type pointer to
69d6f349c8Smartynas  * const-qualified fenv_t.
70d6f349c8Smartynas  *
71d6f349c8Smartynas  * It can be used as an argument to the functions within the <fenv.h> header
72d6f349c8Smartynas  * that manage the floating-point environment, namely fesetenv() and
73d6f349c8Smartynas  * feupdateenv().
74d6f349c8Smartynas  */
75*c9683224Smartynas __BEGIN_DECLS
766e40b843Smartynas extern	fenv_t			__fe_dfl_env;
77*c9683224Smartynas __END_DECLS
786e40b843Smartynas #define	FE_DFL_ENV		((const fenv_t *)&__fe_dfl_env)
796e40b843Smartynas 
806e40b843Smartynas /*
816e40b843Smartynas  * fexcept_t represents the floating-point status flags collectively, including
826e40b843Smartynas  * any status the implementation associates with the flags.
836e40b843Smartynas  *
846e40b843Smartynas  * A floating-point status flag is a system variable whose value is set (but
856e40b843Smartynas  * never cleared) when a floating-point exception is raised, which occurs as a
866e40b843Smartynas  * side effect of exceptional floating-point arithmetic to provide auxiliary
876e40b843Smartynas  * information.
886e40b843Smartynas  *
896e40b843Smartynas  * A floating-point control mode is a system variable whose value may be set by
906e40b843Smartynas  * the user to affect the subsequent behavior of floating-point arithmetic.
916e40b843Smartynas  */
926e40b843Smartynas typedef	unsigned int		fexcept_t;
936e40b843Smartynas 
946e40b843Smartynas #endif	/* !_SH_FENV_H_ */
95