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