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