1*b9e24006Sjoerg /* $NetBSD: flt_rounds.c,v 1.2 2015/03/19 21:22:59 joerg Exp $ */
227620987Smatt
327620987Smatt /*
427620987Smatt * Copyright (c) 1996 Mark Brinicombe
527620987Smatt * All rights reserved.
627620987Smatt *
727620987Smatt * Redistribution and use in source and binary forms, with or without
827620987Smatt * modification, are permitted provided that the following conditions
927620987Smatt * are met:
1027620987Smatt * 1. Redistributions of source code must retain the above copyright
1127620987Smatt * notice, this list of conditions and the following disclaimer.
1227620987Smatt * 2. Redistributions in binary form must reproduce the above copyright
1327620987Smatt * notice, this list of conditions and the following disclaimer in the
1427620987Smatt * documentation and/or other materials provided with the distribution.
1527620987Smatt * 3. All advertising materials mentioning features or use of this software
1627620987Smatt * must display the following acknowledgement:
1727620987Smatt * This product includes software developed by Mark Brinicombe
1827620987Smatt * for the NetBSD Project.
1927620987Smatt * 4. The name of the author may not be used to endorse or promote products
2027620987Smatt * derived from this software without specific prior written permission
2127620987Smatt *
2227620987Smatt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2327620987Smatt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2427620987Smatt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2527620987Smatt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2627620987Smatt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2727620987Smatt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2827620987Smatt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2927620987Smatt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3027620987Smatt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3127620987Smatt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3227620987Smatt */
3327620987Smatt
3427620987Smatt #include <sys/cdefs.h>
3527620987Smatt #if defined(LIBC_SCCS) && !defined(lint)
36*b9e24006Sjoerg __RCSID("$NetBSD: flt_rounds.c,v 1.2 2015/03/19 21:22:59 joerg Exp $");
3727620987Smatt #endif /* LIBC_SCCS and not lint */
3827620987Smatt
39*b9e24006Sjoerg #include "namespace.h"
4027620987Smatt #include <ieeefp.h>
4127620987Smatt #include <float.h>
4227620987Smatt #include <stdint.h>
4327620987Smatt #include <machine/ieeefp.h>
4427620987Smatt
4527620987Smatt static const int rounding_map =
4627620987Smatt (1 << (FP_RN * 2)) /* round to nearest */
4727620987Smatt | (0 << (FP_RZ * 2)) /* round to zero */
4827620987Smatt | (2 << (FP_RP * 2)) /* round to positive infinity */
4927620987Smatt | (3 << (FP_RM * 2)); /* round to negative infinity */
5027620987Smatt
5127620987Smatt int
__flt_rounds(void)5227620987Smatt __flt_rounds(void)
5327620987Smatt {
5427620987Smatt return (rounding_map >> (fpgetround() * 2)) & 3;
5527620987Smatt }
56