xref: /freebsd/lib/libc/include/fpmath.h (revision 587392a5a04955b85c3beac4cff26ca568359f54)
1 /*-
2  * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
3  * Copyright (c) 2002 David Schultz <das@FreeBSD.ORG>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #include <sys/endian.h>
31 #include "_fpmath.h"
32 
33 #ifndef _IEEE_WORD_ORDER
34 #define	_IEEE_WORD_ORDER	_BYTE_ORDER
35 #endif
36 
37 union IEEEf2bits {
38 	float	f;
39 	struct {
40 #if _BYTE_ORDER == _LITTLE_ENDIAN
41 		unsigned int	man	:23;
42 		unsigned int	exp	:8;
43 		unsigned int	sign	:1;
44 #else /* _BIG_ENDIAN */
45 		unsigned int	sign	:1;
46 		unsigned int	exp	:8;
47 		unsigned int	man	:23;
48 #endif
49 	} bits;
50 };
51 
52 #define	DBL_MANH_SIZE	20
53 #define	DBL_MANL_SIZE	32
54 
55 union IEEEd2bits {
56 	double	d;
57 	struct {
58 #if _BYTE_ORDER == _LITTLE_ENDIAN
59 #if _IEEE_WORD_ORDER == _LITTLE_ENDIAN
60 		unsigned int	manl	:32;
61 #endif
62 		unsigned int	manh	:20;
63 		unsigned int	exp	:11;
64 		unsigned int	sign	:1;
65 #if _IEEE_WORD_ORDER == _BIG_ENDIAN
66 		unsigned int	manl	:32;
67 #endif
68 #else /* _BIG_ENDIAN */
69 		unsigned int	sign	:1;
70 		unsigned int	exp	:11;
71 		unsigned int	manh	:20;
72 		unsigned int	manl	:32;
73 #endif
74 	} bits;
75 };
76