os/ossrv/genericopenlibs/cstdlib/LINC/IEEEFP.H
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LINC/IEEEFP.H	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,237 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 + @publishedAll
    1.26 + @released
    1.27 +*/
    1.28 +
    1.29 +#ifndef _IEEE_FP_H_
    1.30 +#define _IEEE_FP_H_
    1.31 +
    1.32 +#include "_ansi.h"
    1.33 +
    1.34 +#include <libc/machine/ieeefp.h>
    1.35 +
    1.36 +/* FIX THIS FIX THIS FIX THIS:
    1.37 +   Neither of __ieee_{float,double}_shape_tape seem to be used anywhere
    1.38 +   except in libm/test.  If that is the case, please delete these from here.
    1.39 +   If that is not the case, please insert documentation here describing why
    1.40 +   they're needed.  */
    1.41 +
    1.42 +#ifdef __IEEE_BIG_ENDIAN
    1.43 +
    1.44 +typedef union 
    1.45 +{
    1.46 +  double value;
    1.47 +  struct 
    1.48 +  {
    1.49 +    unsigned int sign : 1;
    1.50 +    unsigned int exponent: 11;
    1.51 +    unsigned int fraction0:4;
    1.52 +    unsigned int fraction1:16;
    1.53 +    unsigned int fraction2:16;
    1.54 +    unsigned int fraction3:16;
    1.55 +    
    1.56 +  } number;
    1.57 +  struct 
    1.58 +  {
    1.59 +    unsigned int sign : 1;
    1.60 +    unsigned int exponent: 11;
    1.61 +    unsigned int quiet:1;
    1.62 +    unsigned int function0:3;
    1.63 +    unsigned int function1:16;
    1.64 +    unsigned int function2:16;
    1.65 +    unsigned int function3:16;
    1.66 +  } nan;
    1.67 +  struct 
    1.68 +  {
    1.69 +    unsigned long msw;
    1.70 +    unsigned long lsw;
    1.71 +  } parts;
    1.72 +    long aslong[2];
    1.73 +} __ieee_double_shape_type;
    1.74 +
    1.75 +#endif
    1.76 +
    1.77 +#ifdef __IEEE_LITTLE_ENDIAN
    1.78 +
    1.79 +typedef union 
    1.80 +{
    1.81 +  double value;
    1.82 +  struct 
    1.83 +  {
    1.84 +#ifdef __SMALL_BITFIELDS
    1.85 +    unsigned int fraction3:16;
    1.86 +    unsigned int fraction2:16;
    1.87 +    unsigned int fraction1:16;
    1.88 +    unsigned int fraction0: 4;
    1.89 +#else
    1.90 +    unsigned int fraction1:32;
    1.91 +    unsigned int fraction0:20;
    1.92 +#endif
    1.93 +    unsigned int exponent :11;
    1.94 +    unsigned int sign     : 1;
    1.95 +  } number;
    1.96 +  struct 
    1.97 +  {
    1.98 +#ifdef __SMALL_BITFIELDS
    1.99 +    unsigned int function3:16;
   1.100 +    unsigned int function2:16;
   1.101 +    unsigned int function1:16;
   1.102 +    unsigned int function0:3;
   1.103 +#else
   1.104 +    unsigned int function1:32;
   1.105 +    unsigned int function0:19;
   1.106 +#endif
   1.107 +    unsigned int quiet:1;
   1.108 +    unsigned int exponent: 11;
   1.109 +    unsigned int sign : 1;
   1.110 +  } nan;
   1.111 +  struct 
   1.112 +  {
   1.113 +    unsigned long lsw;
   1.114 +    unsigned long msw;
   1.115 +  } parts;
   1.116 +
   1.117 +  long aslong[2];
   1.118 +
   1.119 +} __ieee_double_shape_type;
   1.120 +
   1.121 +#endif
   1.122 +
   1.123 +#ifdef __IEEE_BIG_ENDIAN
   1.124 +
   1.125 +typedef union
   1.126 +{
   1.127 +  float value;
   1.128 +  struct 
   1.129 +  {
   1.130 +    unsigned int sign : 1;
   1.131 +    unsigned int exponent: 8;
   1.132 +    unsigned int fraction0: 7;
   1.133 +    unsigned int fraction1: 16;
   1.134 +  } number;
   1.135 +  struct 
   1.136 +  {
   1.137 +    unsigned int sign:1;
   1.138 +    unsigned int exponent:8;
   1.139 +    unsigned int quiet:1;
   1.140 +    unsigned int function0:6;
   1.141 +    unsigned int function1:16;
   1.142 +  } nan;
   1.143 +  long p1;
   1.144 +  
   1.145 +} __ieee_float_shape_type;
   1.146 +
   1.147 +#endif
   1.148 +
   1.149 +#ifdef __IEEE_LITTLE_ENDIAN
   1.150 +
   1.151 +typedef union
   1.152 +{
   1.153 +  float value;
   1.154 +  struct 
   1.155 +  {
   1.156 +    unsigned int fraction0: 7;
   1.157 +    unsigned int fraction1: 16;
   1.158 +    unsigned int exponent: 8;
   1.159 +    unsigned int sign : 1;
   1.160 +  } number;
   1.161 +  struct 
   1.162 +  {
   1.163 +    unsigned int function1:16;
   1.164 +    unsigned int function0:6;
   1.165 +    unsigned int quiet:1;
   1.166 +    unsigned int exponent:8;
   1.167 +    unsigned int sign:1;
   1.168 +  } nan;
   1.169 +  long p1;
   1.170 +  
   1.171 +} __ieee_float_shape_type;
   1.172 +
   1.173 +#endif
   1.174 +
   1.175 +
   1.176 +/**
   1.177 +FLOATING ROUNDING
   1.178 +*/
   1.179 +typedef int fp_rnd;
   1.180 +
   1.181 +#define FP_RN 0 	/* Round to nearest 		*/
   1.182 +#define FP_RM 1		/* Round down 			*/
   1.183 +#define FP_RP 2		/* Round up 			*/
   1.184 +#define FP_RZ 3		/* Round to zero (trunate) 	*/
   1.185 +
   1.186 +fp_rnd fpgetround(void);
   1.187 +fp_rnd fpsetround(fp_rnd);
   1.188 +
   1.189 +/**
   1.190 +EXCEPTIONS 
   1.191 +*/
   1.192 +typedef int fp_except;
   1.193 +
   1.194 +#define FP_X_INV 0x10	/* Invalid operation 		*/
   1.195 +#define FP_X_DX  0x80	/* Divide by zero		*/
   1.196 +#define FP_X_OFL 0x04	/* Overflow exception		*/
   1.197 +#define FP_X_UFL 0x02	/* Underflow exception		*/
   1.198 +#define FP_X_IMP 0x01	/* imprecise exception		*/
   1.199 +
   1.200 +fp_except fpgetmask(void);
   1.201 +fp_except fpsetmask(fp_except);
   1.202 +fp_except fpgetsticky(void);
   1.203 +fp_except fpsetsticky(fp_except);
   1.204 +
   1.205 +/**
   1.206 +INTEGER ROUNDING 
   1.207 +*/
   1.208 +typedef int fp_rdi;
   1.209 +#define FP_RDI_TOZ 0	/* Round to Zero 		*/
   1.210 +#define FP_RDI_RD  1	/* Follow float mode		*/
   1.211 +
   1.212 +fp_rdi fpgetroundtoi(void);
   1.213 +fp_rdi fpsetroundtoi(fp_rdi);
   1.214 +
   1.215 +int isnan(double);
   1.216 +int isinf(double);
   1.217 +int finite(double);
   1.218 +
   1.219 +int isnanf(float);
   1.220 +int isinff(float);
   1.221 +int finitef(float);
   1.222 +
   1.223 +#define __IEEE_DBL_EXPBIAS 1023
   1.224 +#define __IEEE_FLT_EXPBIAS 127
   1.225 +#define __IEEE_DBL_EXPLEN 11
   1.226 +#define __IEEE_FLT_EXPLEN 8
   1.227 +#define __IEEE_DBL_FRACLEN (64 - (__IEEE_DBL_EXPLEN + 1))
   1.228 +#define __IEEE_FLT_FRACLEN (32 - (__IEEE_FLT_EXPLEN + 1))
   1.229 +#define __IEEE_DBL_MAXPOWTWO	((double)(1L << 32 - 2) * (1L << (32-11) - 32 + 1))
   1.230 +#define __IEEE_FLT_MAXPOWTWO	((float)(1L << (32-8) - 1))
   1.231 +#define __IEEE_DBL_NAN_EXP 0x7ff
   1.232 +#define __IEEE_FLT_NAN_EXP 0xff
   1.233 +
   1.234 +#define isnanf(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
   1.235 +		   ((*(long *)&(x) & 0x007fffffL)!=0000000000L))
   1.236 +#define isinff(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
   1.237 +		   ((*(long *)&(x) & 0x007fffffL)==0000000000L))
   1.238 +#define finitef(x) (((*(long *)&(x) & 0x7f800000L)!=0x7f800000L))
   1.239 +
   1.240 +#endif /* _IEEE_FP_H_ */