sl@0: /*
sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description:
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: 
sl@0: /**
sl@0:  @file
sl@0:  @publishedAll
sl@0:  @released
sl@0: */
sl@0: 
sl@0: #ifndef _IEEE_FP_H_
sl@0: #define _IEEE_FP_H_
sl@0: 
sl@0: #include "_ansi.h"
sl@0: 
sl@0: #include <libc/machine/ieeefp.h>
sl@0: 
sl@0: /* FIX THIS FIX THIS FIX THIS:
sl@0:    Neither of __ieee_{float,double}_shape_tape seem to be used anywhere
sl@0:    except in libm/test.  If that is the case, please delete these from here.
sl@0:    If that is not the case, please insert documentation here describing why
sl@0:    they're needed.  */
sl@0: 
sl@0: #ifdef __IEEE_BIG_ENDIAN
sl@0: 
sl@0: typedef union 
sl@0: {
sl@0:   double value;
sl@0:   struct 
sl@0:   {
sl@0:     unsigned int sign : 1;
sl@0:     unsigned int exponent: 11;
sl@0:     unsigned int fraction0:4;
sl@0:     unsigned int fraction1:16;
sl@0:     unsigned int fraction2:16;
sl@0:     unsigned int fraction3:16;
sl@0:     
sl@0:   } number;
sl@0:   struct 
sl@0:   {
sl@0:     unsigned int sign : 1;
sl@0:     unsigned int exponent: 11;
sl@0:     unsigned int quiet:1;
sl@0:     unsigned int function0:3;
sl@0:     unsigned int function1:16;
sl@0:     unsigned int function2:16;
sl@0:     unsigned int function3:16;
sl@0:   } nan;
sl@0:   struct 
sl@0:   {
sl@0:     unsigned long msw;
sl@0:     unsigned long lsw;
sl@0:   } parts;
sl@0:     long aslong[2];
sl@0: } __ieee_double_shape_type;
sl@0: 
sl@0: #endif
sl@0: 
sl@0: #ifdef __IEEE_LITTLE_ENDIAN
sl@0: 
sl@0: typedef union 
sl@0: {
sl@0:   double value;
sl@0:   struct 
sl@0:   {
sl@0: #ifdef __SMALL_BITFIELDS
sl@0:     unsigned int fraction3:16;
sl@0:     unsigned int fraction2:16;
sl@0:     unsigned int fraction1:16;
sl@0:     unsigned int fraction0: 4;
sl@0: #else
sl@0:     unsigned int fraction1:32;
sl@0:     unsigned int fraction0:20;
sl@0: #endif
sl@0:     unsigned int exponent :11;
sl@0:     unsigned int sign     : 1;
sl@0:   } number;
sl@0:   struct 
sl@0:   {
sl@0: #ifdef __SMALL_BITFIELDS
sl@0:     unsigned int function3:16;
sl@0:     unsigned int function2:16;
sl@0:     unsigned int function1:16;
sl@0:     unsigned int function0:3;
sl@0: #else
sl@0:     unsigned int function1:32;
sl@0:     unsigned int function0:19;
sl@0: #endif
sl@0:     unsigned int quiet:1;
sl@0:     unsigned int exponent: 11;
sl@0:     unsigned int sign : 1;
sl@0:   } nan;
sl@0:   struct 
sl@0:   {
sl@0:     unsigned long lsw;
sl@0:     unsigned long msw;
sl@0:   } parts;
sl@0: 
sl@0:   long aslong[2];
sl@0: 
sl@0: } __ieee_double_shape_type;
sl@0: 
sl@0: #endif
sl@0: 
sl@0: #ifdef __IEEE_BIG_ENDIAN
sl@0: 
sl@0: typedef union
sl@0: {
sl@0:   float value;
sl@0:   struct 
sl@0:   {
sl@0:     unsigned int sign : 1;
sl@0:     unsigned int exponent: 8;
sl@0:     unsigned int fraction0: 7;
sl@0:     unsigned int fraction1: 16;
sl@0:   } number;
sl@0:   struct 
sl@0:   {
sl@0:     unsigned int sign:1;
sl@0:     unsigned int exponent:8;
sl@0:     unsigned int quiet:1;
sl@0:     unsigned int function0:6;
sl@0:     unsigned int function1:16;
sl@0:   } nan;
sl@0:   long p1;
sl@0:   
sl@0: } __ieee_float_shape_type;
sl@0: 
sl@0: #endif
sl@0: 
sl@0: #ifdef __IEEE_LITTLE_ENDIAN
sl@0: 
sl@0: typedef union
sl@0: {
sl@0:   float value;
sl@0:   struct 
sl@0:   {
sl@0:     unsigned int fraction0: 7;
sl@0:     unsigned int fraction1: 16;
sl@0:     unsigned int exponent: 8;
sl@0:     unsigned int sign : 1;
sl@0:   } number;
sl@0:   struct 
sl@0:   {
sl@0:     unsigned int function1:16;
sl@0:     unsigned int function0:6;
sl@0:     unsigned int quiet:1;
sl@0:     unsigned int exponent:8;
sl@0:     unsigned int sign:1;
sl@0:   } nan;
sl@0:   long p1;
sl@0:   
sl@0: } __ieee_float_shape_type;
sl@0: 
sl@0: #endif
sl@0: 
sl@0: 
sl@0: /**
sl@0: FLOATING ROUNDING
sl@0: */
sl@0: typedef int fp_rnd;
sl@0: 
sl@0: #define FP_RN 0 	/* Round to nearest 		*/
sl@0: #define FP_RM 1		/* Round down 			*/
sl@0: #define FP_RP 2		/* Round up 			*/
sl@0: #define FP_RZ 3		/* Round to zero (trunate) 	*/
sl@0: 
sl@0: fp_rnd fpgetround(void);
sl@0: fp_rnd fpsetround(fp_rnd);
sl@0: 
sl@0: /**
sl@0: EXCEPTIONS 
sl@0: */
sl@0: typedef int fp_except;
sl@0: 
sl@0: #define FP_X_INV 0x10	/* Invalid operation 		*/
sl@0: #define FP_X_DX  0x80	/* Divide by zero		*/
sl@0: #define FP_X_OFL 0x04	/* Overflow exception		*/
sl@0: #define FP_X_UFL 0x02	/* Underflow exception		*/
sl@0: #define FP_X_IMP 0x01	/* imprecise exception		*/
sl@0: 
sl@0: fp_except fpgetmask(void);
sl@0: fp_except fpsetmask(fp_except);
sl@0: fp_except fpgetsticky(void);
sl@0: fp_except fpsetsticky(fp_except);
sl@0: 
sl@0: /**
sl@0: INTEGER ROUNDING 
sl@0: */
sl@0: typedef int fp_rdi;
sl@0: #define FP_RDI_TOZ 0	/* Round to Zero 		*/
sl@0: #define FP_RDI_RD  1	/* Follow float mode		*/
sl@0: 
sl@0: fp_rdi fpgetroundtoi(void);
sl@0: fp_rdi fpsetroundtoi(fp_rdi);
sl@0: 
sl@0: int isnan(double);
sl@0: int isinf(double);
sl@0: int finite(double);
sl@0: 
sl@0: int isnanf(float);
sl@0: int isinff(float);
sl@0: int finitef(float);
sl@0: 
sl@0: #define __IEEE_DBL_EXPBIAS 1023
sl@0: #define __IEEE_FLT_EXPBIAS 127
sl@0: #define __IEEE_DBL_EXPLEN 11
sl@0: #define __IEEE_FLT_EXPLEN 8
sl@0: #define __IEEE_DBL_FRACLEN (64 - (__IEEE_DBL_EXPLEN + 1))
sl@0: #define __IEEE_FLT_FRACLEN (32 - (__IEEE_FLT_EXPLEN + 1))
sl@0: #define __IEEE_DBL_MAXPOWTWO	((double)(1L << 32 - 2) * (1L << (32-11) - 32 + 1))
sl@0: #define __IEEE_FLT_MAXPOWTWO	((float)(1L << (32-8) - 1))
sl@0: #define __IEEE_DBL_NAN_EXP 0x7ff
sl@0: #define __IEEE_FLT_NAN_EXP 0xff
sl@0: 
sl@0: #define isnanf(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
sl@0: 		   ((*(long *)&(x) & 0x007fffffL)!=0000000000L))
sl@0: #define isinff(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
sl@0: 		   ((*(long *)&(x) & 0x007fffffL)==0000000000L))
sl@0: #define finitef(x) (((*(long *)&(x) & 0x7f800000L)!=0x7f800000L))
sl@0: 
sl@0: #endif /* _IEEE_FP_H_ */