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