1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1988 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * Macros to pull apart parts of single and double precision 32 * floating point numbers in IEEE format 33 * Be sure to include /usr/include/values.h before including 34 * this file to get the required definition of _IEEE 35 */ 36 37 #if _IEEE 38 #if defined(__sparc) 39 /* byte order with high order bits at lowest address */ 40 41 /* double precision */ 42 typedef union { 43 struct { 44 unsigned sign :1; 45 unsigned exp :11; 46 unsigned hi :20; 47 unsigned lo :32; 48 } fparts; 49 struct { 50 unsigned sign :1; 51 unsigned exp :11; 52 unsigned qnan_bit :1; 53 unsigned hi :19; 54 unsigned lo :32; 55 } nparts; 56 struct { 57 unsigned hi; 58 unsigned lo; 59 } fwords; 60 double d; 61 } _dval; 62 63 /* single precision */ 64 typedef union { 65 struct { 66 unsigned sign :1; 67 unsigned exp :8; 68 unsigned fract :23; 69 } fparts; 70 struct { 71 unsigned sign :1; 72 unsigned exp :8; 73 unsigned qnan_bit :1; 74 unsigned fract :22; 75 } nparts; 76 unsigned long fword; 77 float f; 78 } _fval; 79 80 81 #elif defined(__i386) || defined(__amd64) 82 /* byte order with low order bits at lowest address */ 83 84 /* double precision */ 85 typedef union { 86 struct { 87 unsigned lo :32; 88 unsigned hi :20; 89 unsigned exp :11; 90 unsigned sign :1; 91 } fparts; 92 struct { 93 unsigned lo :32; 94 unsigned hi :19; 95 unsigned qnan_bit :1; 96 unsigned exp :11; 97 unsigned sign :1; 98 } nparts; 99 struct { 100 unsigned lo :32; 101 unsigned hi :32; 102 } fwords; 103 double d; 104 } _dval; 105 106 /* single precision */ 107 typedef union { 108 struct { 109 unsigned fract :23; 110 unsigned exp :8; 111 unsigned sign :1; 112 } fparts; 113 struct { 114 unsigned fract :22; 115 unsigned qnan_bit :1; 116 unsigned exp :8; 117 unsigned sign :1; 118 } nparts; 119 unsigned long fword; 120 float f; 121 } _fval; 122 #endif 123 124 /* parts of a double precision floating point number */ 125 #define SIGNBIT(X) (((_dval *)&(X))->fparts.sign) 126 #define EXPONENT(X) (((_dval *)&(X))->fparts.exp) 127 128 #define HIFRACTION(X) (((_dval *)&(X))->fparts.hi) 129 #define LOFRACTION(X) (((_dval *)&(X))->fparts.lo) 130 #define QNANBIT(X) (((_dval *)&(X))->nparts.qnan_bit) 131 #define HIWORD(X) (((_dval *)&(X))->fwords.hi) 132 #define LOWORD(X) (((_dval *)&(X))->fwords.lo) 133 134 #define MAXEXP 0x7ff /* maximum exponent of double */ 135 #define ISMAXEXP(X) ((EXPONENT(X)) == MAXEXP) 136 137 /* macros used to create quiet NaNs as return values */ 138 #define SETQNAN(X) ((((_dval *)&(X))->nparts.qnan_bit) = 0x1) 139 #define HIQNAN(X) ((HIWORD(X)) = 0x7ff80000) 140 #define LOQNAN(X) ((((_dval *)&(X))->fwords.lo) = 0x0) 141 142 /* macros used to extract parts of single precision values */ 143 #define FSIGNBIT(X) (((_fval *)&(X))->fparts.sign) 144 #define FEXPONENT(X) (((_fval *)&(X))->fparts.exp) 145 #define FFRACTION(X) (((_fval *)&(X))->fparts.fract) 146 147 #define FWORD(X) (((_fval *)&(X))->fword) 148 #define FQNANBIT(X) (((_fval *)&(X))->nparts.qnan_bit) 149 #define MAXEXPF 255 /* maximum exponent of single */ 150 #define FISMAXEXP(X) ((FEXPONENT(X)) == MAXEXPF) 151 152 #endif /* _IEEE */ 153