18cf5ed51SMike Barcroft /*- 28cf5ed51SMike Barcroft * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> 38cf5ed51SMike Barcroft * Copyright (c) 2002 David Schultz <dschultz@uclink.Berkeley.EDU> 48cf5ed51SMike Barcroft * All rights reserved. 58cf5ed51SMike Barcroft * 68cf5ed51SMike Barcroft * Redistribution and use in source and binary forms, with or without 78cf5ed51SMike Barcroft * modification, are permitted provided that the following conditions 88cf5ed51SMike Barcroft * are met: 98cf5ed51SMike Barcroft * 1. Redistributions of source code must retain the above copyright 108cf5ed51SMike Barcroft * notice, this list of conditions and the following disclaimer. 118cf5ed51SMike Barcroft * 2. Redistributions in binary form must reproduce the above copyright 128cf5ed51SMike Barcroft * notice, this list of conditions and the following disclaimer in the 138cf5ed51SMike Barcroft * documentation and/or other materials provided with the distribution. 148cf5ed51SMike Barcroft * 158cf5ed51SMike Barcroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 168cf5ed51SMike Barcroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 178cf5ed51SMike Barcroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 188cf5ed51SMike Barcroft * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 198cf5ed51SMike Barcroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 208cf5ed51SMike Barcroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 218cf5ed51SMike Barcroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 228cf5ed51SMike Barcroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 238cf5ed51SMike Barcroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 248cf5ed51SMike Barcroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 258cf5ed51SMike Barcroft * SUCH DAMAGE. 268cf5ed51SMike Barcroft * 278cf5ed51SMike Barcroft * $FreeBSD$ 288cf5ed51SMike Barcroft */ 298cf5ed51SMike Barcroft 308cf5ed51SMike Barcroft #include <sys/endian.h> 318cf5ed51SMike Barcroft #include "_fpmath.h" 328cf5ed51SMike Barcroft 338cf5ed51SMike Barcroft union IEEEf2bits { 348cf5ed51SMike Barcroft float f; 358cf5ed51SMike Barcroft struct { 368cf5ed51SMike Barcroft #if _BYTE_ORDER == _LITTLE_ENDIAN 378cf5ed51SMike Barcroft unsigned int man :23; 388cf5ed51SMike Barcroft unsigned int exp :8; 398cf5ed51SMike Barcroft unsigned int sign :1; 408cf5ed51SMike Barcroft #else /* _BIG_ENDIAN */ 418cf5ed51SMike Barcroft unsigned int sign :1; 428cf5ed51SMike Barcroft unsigned int exp :8; 438cf5ed51SMike Barcroft unsigned int man :23; 448cf5ed51SMike Barcroft #endif 458cf5ed51SMike Barcroft } bits; 468cf5ed51SMike Barcroft }; 478cf5ed51SMike Barcroft 482ad26506SDavid Schultz #define DBL_MANH_SIZE 20 492ad26506SDavid Schultz #define DBL_MANL_SIZE 32 502ad26506SDavid Schultz 518cf5ed51SMike Barcroft union IEEEd2bits { 528cf5ed51SMike Barcroft double d; 538cf5ed51SMike Barcroft struct { 548cf5ed51SMike Barcroft #if _BYTE_ORDER == _LITTLE_ENDIAN 558cf5ed51SMike Barcroft unsigned int manl :32; 568cf5ed51SMike Barcroft unsigned int manh :20; 578cf5ed51SMike Barcroft unsigned int exp :11; 588cf5ed51SMike Barcroft unsigned int sign :1; 598cf5ed51SMike Barcroft #else /* _BIG_ENDIAN */ 608cf5ed51SMike Barcroft unsigned int sign :1; 618cf5ed51SMike Barcroft unsigned int exp :11; 628cf5ed51SMike Barcroft unsigned int manh :20; 638cf5ed51SMike Barcroft unsigned int manl :32; 648cf5ed51SMike Barcroft #endif 658cf5ed51SMike Barcroft } bits; 668cf5ed51SMike Barcroft }; 67