1110566Smike/*- 2110566Smike * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> 3141379Sdas * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG> 4110566Smike * All rights reserved. 5110566Smike * 6110566Smike * Redistribution and use in source and binary forms, with or without 7110566Smike * modification, are permitted provided that the following conditions 8110566Smike * are met: 9110566Smike * 1. Redistributions of source code must retain the above copyright 10110566Smike * notice, this list of conditions and the following disclaimer. 11110566Smike * 2. Redistributions in binary form must reproduce the above copyright 12110566Smike * notice, this list of conditions and the following disclaimer in the 13110566Smike * documentation and/or other materials provided with the distribution. 14110566Smike * 15110566Smike * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16110566Smike * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17110566Smike * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18110566Smike * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19110566Smike * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20110566Smike * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21110566Smike * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22110566Smike * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23110566Smike * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24110566Smike * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25110566Smike * SUCH DAMAGE. 26110566Smike * 27110566Smike * $FreeBSD$ 28110566Smike */ 29110566Smike 30111555Smike#include <sys/endian.h> 31111555Smike 32110566Smikeunion IEEEl2bits { 33110566Smike long double e; 34110566Smike struct { 35111555Smike#if _BYTE_ORDER == _LITTLE_ENDIAN 36111555Smike unsigned int manl :32; 37111555Smike unsigned int manh :32; 38110566Smike unsigned int exp :15; 39110566Smike unsigned int sign :1; 40111555Smike unsigned long junk :48; 41111555Smike#else /* _BIG_ENDIAN */ 42111555Smike unsigned long junk :48; 43111555Smike unsigned int sign :1; 44111555Smike unsigned int exp :15; 45111555Smike unsigned int manh :32; 46111555Smike unsigned int manl :32; 47111555Smike#endif 48110566Smike } bits; 49175402Sbde struct { 50175402Sbde#if _BYTE_ORDER == _LITTLE_ENDIAN 51175402Sbde unsigned long man :64; 52175402Sbde unsigned int expsign :16; 53175402Sbde unsigned long junk :48; 54175402Sbde#else /* _BIG_ENDIAN */ 55175402Sbde unsigned long junk :48; 56175402Sbde unsigned int expsign :16; 57175402Sbde unsigned long man :64; 58175402Sbde#endif 59175402Sbde } xbits; 60110566Smike}; 61110566Smike 62111555Smike#if _BYTE_ORDER == _LITTLE_ENDIAN 63143215Sdas#define LDBL_NBIT 0x80000000 64143215Sdas#define mask_nbit_l(u) ((u).bits.manh &= ~LDBL_NBIT) 65111555Smike#else /* _BIG_ENDIAN */ 66143215Sdas/* 67143215Sdas * XXX This doesn't look right. Very few machines have a different 68143215Sdas * endianness for integers and floating-point, and in nextafterl() 69143215Sdas * we assume that none do. If you have an environment for testing 70143215Sdas * this, please let me know. --das 71143215Sdas */ 72143215Sdas#define LDBL_NBIT 0x80 73143215Sdas#define mask_nbit_l(u) ((u).bits.manh &= ~LDBL_NBIT) 74111555Smike#endif 75113145Sdas 76124653Sdas#define LDBL_MANH_SIZE 32 77124653Sdas#define LDBL_MANL_SIZE 32 78124653Sdas 79113145Sdas#define LDBL_TO_ARRAY32(u, a) do { \ 80113145Sdas (a)[0] = (uint32_t)(u).bits.manl; \ 81113145Sdas (a)[1] = (uint32_t)(u).bits.manh; \ 82175402Sbde} while (0) 83