/* $NetBSD: ieee754.h,v 1.4 2003/10/27 02:30:26 simonb Exp $ */12/*-3* SPDX-License-Identifier: BSD-3-Clause4*5* Copyright (c) 1992, 19936* The Regents of the University of California. All rights reserved.7*8* This software was developed by the Computer Systems Engineering group9* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and10* contributed to Berkeley.11*12* All advertising materials mentioning features or use of this software13* must display the following acknowledgement:14* This product includes software developed by the University of15* California, Lawrence Berkeley Laboratory.16*17* Redistribution and use in source and binary forms, with or without18* modification, are permitted provided that the following conditions19* are met:20* 1. Redistributions of source code must retain the above copyright21* notice, this list of conditions and the following disclaimer.22* 2. Redistributions in binary form must reproduce the above copyright23* notice, this list of conditions and the following disclaimer in the24* documentation and/or other materials provided with the distribution.25* 3. Neither the name of the University nor the names of its contributors26* may be used to endorse or promote products derived from this software27* without specific prior written permission.28*29* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND30* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE31* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE32* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE33* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL34* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS35* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)36* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT37* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY38* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF39* SUCH DAMAGE.40*41*/4243/*44* NOTICE: This is not a standalone file. To use it, #include it in45* your port's ieee.h header.46*/4748#include <machine/endian.h>4950/*51* <sys/ieee754.h> defines the layout of IEEE 754 floating point types.52* Only single-precision and double-precision types are defined here;53* extended types, if available, are defined in the machine-dependent54* header.55*/5657/*58* Define the number of bits in each fraction and exponent.59*60* k k+161* Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented62*63* (-exp_bias+1)64* as fractions that look like 0.fffff x 2 . This means that65*66* -12667* the number 0.10000 x 2 , for instance, is the same as the normalized68*69* -127 -12870* float 1.0 x 2 . Thus, to represent 2 , we need one leading zero71*72* -12973* in the fraction; to represent 2 , we need two, and so on. This74*75* (-exp_bias-fracbits+1)76* implies that the smallest denormalized number is 277*78* for whichever format we are talking about: for single precision, for79*80* -126 -14981* instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and82*83* -149 == -127 - 23 + 1.84*/85#define SNG_EXPBITS 886#define SNG_FRACBITS 238788#define DBL_EXPBITS 1189#define DBL_FRACBITS 529091#if defined(__VFP_FP__) || defined(__ARM_EABI__)92#define _IEEE_WORD_ORDER _BYTE_ORDER93#else94#define _IEEE_WORD_ORDER _BIG_ENDIAN95#endif9697struct ieee_single {98#if _BYTE_ORDER == _BIG_ENDIAN99u_int sng_sign:1;100u_int sng_exp:8;101u_int sng_frac:23;102#else103u_int sng_frac:23;104u_int sng_exp:8;105u_int sng_sign:1;106#endif107};108109struct ieee_double {110#if _BYTE_ORDER == _BIG_ENDIAN111u_int dbl_sign:1;112u_int dbl_exp:11;113u_int dbl_frach:20;114u_int dbl_fracl;115#else116#if _IEEE_WORD_ORDER == _LITTLE_ENDIAN117u_int dbl_fracl;118#endif119u_int dbl_frach:20;120u_int dbl_exp:11;121u_int dbl_sign:1;122#if _IEEE_WORD_ORDER == _BIG_ENDIAN123u_int dbl_fracl;124#endif125#endif126};127128/*129* Floats whose exponent is in [1..INFNAN) (of whatever type) are130* `normal'. Floats whose exponent is INFNAN are either Inf or NaN.131* Floats whose exponent is zero are either zero (iff all fraction132* bits are zero) or subnormal values.133*134* A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its135* high fraction; if the bit is set, it is a `quiet NaN'.136*/137#define SNG_EXP_INFNAN 255138#define DBL_EXP_INFNAN 2047139140#if 0141#define SNG_QUIETNAN (1 << 22)142#define DBL_QUIETNAN (1 << 19)143#endif144145/*146* Exponent biases.147*/148#define SNG_EXP_BIAS 127149#define DBL_EXP_BIAS 1023150151/*152* Convenience data structures.153*/154union ieee_single_u {155float sngu_f;156struct ieee_single sngu_sng;157};158159union ieee_double_u {160double dblu_d;161struct ieee_double dblu_dbl;162};163164165