genericopenlibs/cstdlib/LINC/IEEEFP.H
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @publishedAll
       
    23  @released
       
    24 */
       
    25 
       
    26 #ifndef _IEEE_FP_H_
       
    27 #define _IEEE_FP_H_
       
    28 
       
    29 #include "_ansi.h"
       
    30 
       
    31 #include <libc/machine/ieeefp.h>
       
    32 
       
    33 /* FIX THIS FIX THIS FIX THIS:
       
    34    Neither of __ieee_{float,double}_shape_tape seem to be used anywhere
       
    35    except in libm/test.  If that is the case, please delete these from here.
       
    36    If that is not the case, please insert documentation here describing why
       
    37    they're needed.  */
       
    38 
       
    39 #ifdef __IEEE_BIG_ENDIAN
       
    40 
       
    41 typedef union 
       
    42 {
       
    43   double value;
       
    44   struct 
       
    45   {
       
    46     unsigned int sign : 1;
       
    47     unsigned int exponent: 11;
       
    48     unsigned int fraction0:4;
       
    49     unsigned int fraction1:16;
       
    50     unsigned int fraction2:16;
       
    51     unsigned int fraction3:16;
       
    52     
       
    53   } number;
       
    54   struct 
       
    55   {
       
    56     unsigned int sign : 1;
       
    57     unsigned int exponent: 11;
       
    58     unsigned int quiet:1;
       
    59     unsigned int function0:3;
       
    60     unsigned int function1:16;
       
    61     unsigned int function2:16;
       
    62     unsigned int function3:16;
       
    63   } nan;
       
    64   struct 
       
    65   {
       
    66     unsigned long msw;
       
    67     unsigned long lsw;
       
    68   } parts;
       
    69     long aslong[2];
       
    70 } __ieee_double_shape_type;
       
    71 
       
    72 #endif
       
    73 
       
    74 #ifdef __IEEE_LITTLE_ENDIAN
       
    75 
       
    76 typedef union 
       
    77 {
       
    78   double value;
       
    79   struct 
       
    80   {
       
    81 #ifdef __SMALL_BITFIELDS
       
    82     unsigned int fraction3:16;
       
    83     unsigned int fraction2:16;
       
    84     unsigned int fraction1:16;
       
    85     unsigned int fraction0: 4;
       
    86 #else
       
    87     unsigned int fraction1:32;
       
    88     unsigned int fraction0:20;
       
    89 #endif
       
    90     unsigned int exponent :11;
       
    91     unsigned int sign     : 1;
       
    92   } number;
       
    93   struct 
       
    94   {
       
    95 #ifdef __SMALL_BITFIELDS
       
    96     unsigned int function3:16;
       
    97     unsigned int function2:16;
       
    98     unsigned int function1:16;
       
    99     unsigned int function0:3;
       
   100 #else
       
   101     unsigned int function1:32;
       
   102     unsigned int function0:19;
       
   103 #endif
       
   104     unsigned int quiet:1;
       
   105     unsigned int exponent: 11;
       
   106     unsigned int sign : 1;
       
   107   } nan;
       
   108   struct 
       
   109   {
       
   110     unsigned long lsw;
       
   111     unsigned long msw;
       
   112   } parts;
       
   113 
       
   114   long aslong[2];
       
   115 
       
   116 } __ieee_double_shape_type;
       
   117 
       
   118 #endif
       
   119 
       
   120 #ifdef __IEEE_BIG_ENDIAN
       
   121 
       
   122 typedef union
       
   123 {
       
   124   float value;
       
   125   struct 
       
   126   {
       
   127     unsigned int sign : 1;
       
   128     unsigned int exponent: 8;
       
   129     unsigned int fraction0: 7;
       
   130     unsigned int fraction1: 16;
       
   131   } number;
       
   132   struct 
       
   133   {
       
   134     unsigned int sign:1;
       
   135     unsigned int exponent:8;
       
   136     unsigned int quiet:1;
       
   137     unsigned int function0:6;
       
   138     unsigned int function1:16;
       
   139   } nan;
       
   140   long p1;
       
   141   
       
   142 } __ieee_float_shape_type;
       
   143 
       
   144 #endif
       
   145 
       
   146 #ifdef __IEEE_LITTLE_ENDIAN
       
   147 
       
   148 typedef union
       
   149 {
       
   150   float value;
       
   151   struct 
       
   152   {
       
   153     unsigned int fraction0: 7;
       
   154     unsigned int fraction1: 16;
       
   155     unsigned int exponent: 8;
       
   156     unsigned int sign : 1;
       
   157   } number;
       
   158   struct 
       
   159   {
       
   160     unsigned int function1:16;
       
   161     unsigned int function0:6;
       
   162     unsigned int quiet:1;
       
   163     unsigned int exponent:8;
       
   164     unsigned int sign:1;
       
   165   } nan;
       
   166   long p1;
       
   167   
       
   168 } __ieee_float_shape_type;
       
   169 
       
   170 #endif
       
   171 
       
   172 
       
   173 /**
       
   174 FLOATING ROUNDING
       
   175 */
       
   176 typedef int fp_rnd;
       
   177 
       
   178 #define FP_RN 0 	/* Round to nearest 		*/
       
   179 #define FP_RM 1		/* Round down 			*/
       
   180 #define FP_RP 2		/* Round up 			*/
       
   181 #define FP_RZ 3		/* Round to zero (trunate) 	*/
       
   182 
       
   183 fp_rnd fpgetround(void);
       
   184 fp_rnd fpsetround(fp_rnd);
       
   185 
       
   186 /**
       
   187 EXCEPTIONS 
       
   188 */
       
   189 typedef int fp_except;
       
   190 
       
   191 #define FP_X_INV 0x10	/* Invalid operation 		*/
       
   192 #define FP_X_DX  0x80	/* Divide by zero		*/
       
   193 #define FP_X_OFL 0x04	/* Overflow exception		*/
       
   194 #define FP_X_UFL 0x02	/* Underflow exception		*/
       
   195 #define FP_X_IMP 0x01	/* imprecise exception		*/
       
   196 
       
   197 fp_except fpgetmask(void);
       
   198 fp_except fpsetmask(fp_except);
       
   199 fp_except fpgetsticky(void);
       
   200 fp_except fpsetsticky(fp_except);
       
   201 
       
   202 /**
       
   203 INTEGER ROUNDING 
       
   204 */
       
   205 typedef int fp_rdi;
       
   206 #define FP_RDI_TOZ 0	/* Round to Zero 		*/
       
   207 #define FP_RDI_RD  1	/* Follow float mode		*/
       
   208 
       
   209 fp_rdi fpgetroundtoi(void);
       
   210 fp_rdi fpsetroundtoi(fp_rdi);
       
   211 
       
   212 int isnan(double);
       
   213 int isinf(double);
       
   214 int finite(double);
       
   215 
       
   216 int isnanf(float);
       
   217 int isinff(float);
       
   218 int finitef(float);
       
   219 
       
   220 #define __IEEE_DBL_EXPBIAS 1023
       
   221 #define __IEEE_FLT_EXPBIAS 127
       
   222 #define __IEEE_DBL_EXPLEN 11
       
   223 #define __IEEE_FLT_EXPLEN 8
       
   224 #define __IEEE_DBL_FRACLEN (64 - (__IEEE_DBL_EXPLEN + 1))
       
   225 #define __IEEE_FLT_FRACLEN (32 - (__IEEE_FLT_EXPLEN + 1))
       
   226 #define __IEEE_DBL_MAXPOWTWO	((double)(1L << 32 - 2) * (1L << (32-11) - 32 + 1))
       
   227 #define __IEEE_FLT_MAXPOWTWO	((float)(1L << (32-8) - 1))
       
   228 #define __IEEE_DBL_NAN_EXP 0x7ff
       
   229 #define __IEEE_FLT_NAN_EXP 0xff
       
   230 
       
   231 #define isnanf(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
       
   232 		   ((*(long *)&(x) & 0x007fffffL)!=0000000000L))
       
   233 #define isinff(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
       
   234 		   ((*(long *)&(x) & 0x007fffffL)==0000000000L))
       
   235 #define finitef(x) (((*(long *)&(x) & 0x7f800000L)!=0x7f800000L))
       
   236 
       
   237 #endif /* _IEEE_FP_H_ */