os/ossrv/genericopenlibs/cstdlib/LMATH/FDLIBM.H
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LMATH/FDLIBM.H	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,239 @@
     1.4 +/* FDLIBM.H
     1.5 + * 
     1.6 + * Portions Copyright (c) 1993-1999 Nokia Corporation and/or its subsidiary(-ies).
     1.7 + * All rights reserved.
     1.8 + */
     1.9 +
    1.10 +
    1.11 +/* @(#)fdlibm.h 5.1 93/09/24 */
    1.12 +/*
    1.13 + * ====================================================
    1.14 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
    1.15 + *
    1.16 + * Developed at SunPro, a Sun Microsystems, Inc. business.
    1.17 + * Permission to use, copy, modify, and distribute this
    1.18 + * software is freely granted, provided that this notice 
    1.19 + * is preserved.
    1.20 + * ====================================================
    1.21 + */
    1.22 +
    1.23 +#ifdef __cplusplus
    1.24 +extern "C" {
    1.25 +#endif
    1.26 +
    1.27 +/**
    1.28 +SYMBIAN adaptations 
    1.29 +@internalComponent
    1.30 +*/
    1.31 +#define huge	fhuge
    1.32 +#define tiny	ftiny
    1.33 +/**
    1.34 +@internalComponent
    1.35 +*/
    1.36 +typedef unsigned long	__uint32_t;
    1.37 +typedef long			__int32_t;
    1.38 +
    1.39 +#ifdef __VC32__
    1.40 +/* warning C4056: overflow in floating-point constant arithmetic 
    1.41 + * Caused by negative floating point constants, it seems!
    1.42 + * For example, static double foo = -1.0;
    1.43 + */
    1.44 +#pragma warning( disable: 4056 )
    1.45 +#endif
    1.46 +#ifdef __ARMCC__
    1.47 +/* Warning:  #222-D: floating-point operation result is out of range
    1.48 + * The compiler detects constant math that overflows, we want overflow though!
    1.49 + */
    1.50 +#pragma diag_suppress 222
    1.51 +#endif
    1.52 +
    1.53 +#include <math.h>
    1.54 +/**
    1.55 +@internalComponent
    1.56 +*/
    1.57 +#define	HUGE	((float)3.40282346638528860e+38)
    1.58 +
    1.59 +/** 
    1.60 +set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
    1.61 +(one may replace the following line by "#include <values.h>")
    1.62 +@internalComponent
    1.63 +*/
    1.64 +#define X_TLOSS		1.41484755040568800000e+16 
    1.65 +
    1.66 +/**
    1.67 +ieee style elementary functions - ESTLIB is exporting
    1.68 +these functions directly, so we simply map the names across
    1.69 +@internalComponent
    1.70 +*/
    1.71 +#define __ieee754_cosh	cosh			
    1.72 +#define __ieee754_sinh	sinh			
    1.73 +#define __ieee754_tanh	tanh	
    1.74 +#define __ieee754_exp	exp			
    1.75 +
    1.76 +/* The original code used statements like
    1.77 +	n0 = ((*(int*)&one)>>29)^1;		* index of high word *
    1.78 +	ix0 = *(n0+(int*)&x);			* high word of x *
    1.79 +	ix1 = *((1-n0)+(int*)&x);		* low word of x *
    1.80 +   to dig two 32 bit words out of the 64 bit IEEE floating point
    1.81 +   value.  That is non-ANSI, and, moreover, the gcc instruction
    1.82 +   scheduler gets it wrong.  We instead use the following macros.
    1.83 +   Unlike the original code, we determine the endianness at compile
    1.84 +   time, not at run time; I don't see much benefit to selecting
    1.85 +   endianness at run time.  */
    1.86 +
    1.87 +#ifndef __IEEE_BIG_ENDIAN
    1.88 +#ifndef __IEEE_LITTLE_ENDIAN
    1.89 + #error Must define endianness
    1.90 +#endif
    1.91 +#endif
    1.92 +
    1.93 +/* A union which permits us to convert between a double and two 32 bit
    1.94 +   ints.  */
    1.95 +
    1.96 +#ifdef __IEEE_BIG_ENDIAN
    1.97 +/**
    1.98 +@internalComponent
    1.99 +*/
   1.100 +typedef union 
   1.101 +{
   1.102 +  double value;
   1.103 +  struct 
   1.104 +  {
   1.105 +    unsigned long msw;
   1.106 +    unsigned long lsw;
   1.107 +  } parts;
   1.108 +} ieee_double_shape_type;
   1.109 +
   1.110 +#else
   1.111 +
   1.112 +#ifdef __IEEE_LITTLE_ENDIAN
   1.113 +/**
   1.114 +@internalComponent
   1.115 +*/
   1.116 +typedef union 
   1.117 +{
   1.118 +  double value;
   1.119 +  struct 
   1.120 +  {
   1.121 +    unsigned long lsw;
   1.122 +    unsigned long msw;
   1.123 +  } parts;
   1.124 +} ieee_double_shape_type;
   1.125 +
   1.126 +#endif
   1.127 +#endif
   1.128 +
   1.129 +/**
   1.130 +Get two 32 bit ints from a double.  
   1.131 +@internalComponent
   1.132 +*/
   1.133 +#define EXTRACT_WORDS(ix0,ix1,d)				\
   1.134 +{								\
   1.135 +  ieee_double_shape_type ew_u;					\
   1.136 +  ew_u.value = (d);						\
   1.137 +  (ix0) = ew_u.parts.msw;					\
   1.138 +  (ix1) = ew_u.parts.lsw;					\
   1.139 +}
   1.140 +
   1.141 +/** 
   1.142 +Get the more significant 32 bit int from a double.  
   1.143 +@internalComponent
   1.144 +*/
   1.145 +#define GET_HIGH_WORD(i,d)					\
   1.146 +{								\
   1.147 +  ieee_double_shape_type gh_u;					\
   1.148 +  gh_u.value = (d);						\
   1.149 +  (i) = gh_u.parts.msw;						\
   1.150 +}
   1.151 +
   1.152 +/**
   1.153 +Get the less significant 32 bit int from a double.  
   1.154 +@internalComponent
   1.155 +*/
   1.156 +#define GET_LOW_WORD(i,d)					\
   1.157 +{								\
   1.158 +  ieee_double_shape_type gl_u;					\
   1.159 +  gl_u.value = (d);						\
   1.160 +  (i) = gl_u.parts.lsw;						\
   1.161 +}
   1.162 +
   1.163 +/**
   1.164 +Set a double from two 32 bit ints.  
   1.165 +@internalComponent
   1.166 +*/
   1.167 +#define INSERT_WORDS(d,ix0,ix1)					\
   1.168 +{								\
   1.169 +  ieee_double_shape_type iw_u;					\
   1.170 +  iw_u.parts.msw = (ix0);					\
   1.171 +  iw_u.parts.lsw = (ix1);					\
   1.172 +  (d) = iw_u.value;						\
   1.173 +}
   1.174 +
   1.175 +/** 
   1.176 +Set the more significant 32 bits of a double from an int.  
   1.177 +@internalComponent
   1.178 +*/
   1.179 +#define SET_HIGH_WORD(d,v)					\
   1.180 +{								\
   1.181 +  ieee_double_shape_type sh_u;					\
   1.182 +  sh_u.value = (d);						\
   1.183 +  sh_u.parts.msw = (v);						\
   1.184 +  (d) = sh_u.value;						\
   1.185 +}
   1.186 +
   1.187 +/** 
   1.188 +Set the less significant 32 bits of a double from an int.  
   1.189 +@internalComponent
   1.190 +*/
   1.191 +#define SET_LOW_WORD(d,v)					\
   1.192 +{								\
   1.193 +  ieee_double_shape_type sl_u;					\
   1.194 +  sl_u.value = (d);						\
   1.195 +  sl_u.parts.lsw = (v);						\
   1.196 +  (d) = sl_u.value;						\
   1.197 +}
   1.198 +
   1.199 +/** 
   1.200 +A union which permits us to convert between a float and a 32 bit
   1.201 +int.  
   1.202 +@internalComponent
   1.203 +*/
   1.204 +typedef union
   1.205 +{
   1.206 +  float value;
   1.207 +  unsigned long word;
   1.208 +} ieee_float_shape_type;
   1.209 +
   1.210 +/**
   1.211 +Get a 32 bit int from a float.  
   1.212 +@internalComponent
   1.213 +*/
   1.214 +#define GET_FLOAT_WORD(i,d)					\
   1.215 +{								\
   1.216 +  ieee_float_shape_type gf_u;					\
   1.217 +  gf_u.value = (d);						\
   1.218 +  (i) = gf_u.word;						\
   1.219 +}
   1.220 +
   1.221 +/** 
   1.222 +Set a float from a 32 bit int.  
   1.223 +@internalComponent
   1.224 +*/
   1.225 +#define SET_FLOAT_WORD(d,i)					\
   1.226 +{								\
   1.227 +  ieee_float_shape_type sf_u;					\
   1.228 +  sf_u.word = (i);						\
   1.229 +  (d) = sf_u.value;						\
   1.230 +}
   1.231 +
   1.232 +/**
   1.233 +Test a 32-bit value for being 0.
   1.234 +(x==0)? 0: (some value with top bit set to 1)
   1.235 +@internalComponent
   1.236 +*/
   1.237 +
   1.238 +#define CHECK_ZERO(x)	((x)|-(__int32_t)(x))
   1.239 +
   1.240 +#ifdef __cplusplus
   1.241 +}
   1.242 +#endif