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