?? mathsoftlib.c
字號(hào):
/* mathSoftLib.c - high-level floating-point emulation library *//* Copyright 1984-1995 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01p,04sep98,yh fixed mathSoftCeil for spr#22152.01o,21nov95,gbj switched to ansi-style function declarations01n,07jul95,rcs changed LOG2E back to correct value.01m,03feb95,rhp doc: warn that sw f/p is not available for all archs01l,12jan95,rhp doc: correct config macro to call mathSoftInit() (SPR#3733).01k,14jul94,dvs fixed argument order and doc for mathSoftAtan2/mathSoftAtan2f (SPR# 2580)01j,21nov92,jdi documentation cleanup.01i,13nov92,jcf made logMsg calls indirect to reduce coupling.01h,13oct92,jdi doc, and NOMANUAL for mathSoftSincos() and mathSoftSincosf(). 01g,30jul92,kdl changed to ANSI single precision names (e.g. sinf -> sinf).01f,26jul92,gae fixed number of parameters to logMsg().01e,04jul92,jcf ansi clean up.01d,03jul92,smb removed include of vxTypes.h.01c,26may92,rrr the tree shuffle01b,04oct91,rrr passed through the ansification filter -changed VOID to void -changed copyright notice01a,28jan91,kdl original version, based on library written by S. Huddleston.*//*DESCRIPTIONThis library provides software emulation of various high-levelfloating-point operations. This emulation is generally for use in systemsthat lack a floating-point coprocessor.WARNINGSoftware floating point is not supported for all architectures. Seethe architecture-specific appendices of the.I VxWorks Programmer's Guide.INCLUDE FILES: math.hSEE ALSO: mathHardLib, mathALib,.I VxWorks Programmer's Guidearchitecture-specific appendicesINTERNALAuthors:Major portions by Scott Huddleston, Computer Research Lab, Tektronix. Copyright 1990, Tektronix Inc.Cube-root function (cbrt) written by K.C. Ng, UC Berkeley. Copyright 1985, Regents of the University of California.Hyperbolic trig functions (cosh, sinh, tanh) written by Fred Fish.*/#include "vxWorks.h"#include "math.h"#include "logLib.h"#include "private/funcBindP.h"/* make sure PI is defined */#ifndef PI#define PI 3.14159265358979323846264338327950#endif/* constant PI in single precision */static float PI_SINGLE = PI;#define INF_HiShort 0x7ff0#define INF_HiShort_SINGLE 0x7f80/* tests for NaN (Not a Number) and INF (infinity) */#define isNaN(z) (((*(short*)&z) & 0x7fff) > INF_HiShort)#define isINF(z) (((*(short*)&z) & 0x7fff) == INF_HiShort)#define isINFNaN(z) (((*(short*)&z) & 0x7fff) >= INF_HiShort)#define isNaN_SINGLE(z) (((*(short*)&z) & 0x7fff) > INF_HiShort_SINGLE)#define isINF_SINGLE(z) (((*(short*)&z) & 0x7fff) == INF_HiShort_SINGLE)#define isINFNaN_SINGLE(z) (((*(short*)&z) & 0x7fff) >= INF_HiShort_SINGLE)#define LOGE_MAXDOUBLE 7.09782712893383970e+02#define LOGE_MINDOUBLE -7.09089565712824080e+02#define TANH_MAXARG 16#define LOG2E 1.4426950408889634074 /* Log to base 2 of e *//* Externals */extern double mathSoftAtan (); /* functions in mathSoftALib.s */extern double mathSoftCos ();extern double mathSoftExp ();extern double mathSoftFloor ();extern double mathSoftInfinity ();extern double mathSoftLog ();extern double mathSoftLog10 ();extern double mathSoftRealtoint ();extern double mathSoftSin ();extern double mathSoftSqrt ();extern double mathSoftTan ();extern float mathSoftAtanf ();extern float mathSoftCosf ();extern float mathSoftExpf ();extern float mathSoftFloorf ();extern float mathSoftInfinityf ();extern float mathSoftLogf ();extern float mathSoftLog10f ();extern float mathSoftRealtointf ();extern float mathSoftSinf ();extern float mathSoftSqrtf ();extern float mathSoftTanf ();extern DBLFUNCPTR mathAcosFunc; /* double-precision function ptrs */extern DBLFUNCPTR mathAsinFunc;extern DBLFUNCPTR mathAtanFunc;extern DBLFUNCPTR mathAtan2Func;extern DBLFUNCPTR mathCbrtFunc;extern DBLFUNCPTR mathCeilFunc;extern DBLFUNCPTR mathCosFunc;extern DBLFUNCPTR mathCoshFunc;extern DBLFUNCPTR mathExpFunc;extern DBLFUNCPTR mathFabsFunc;extern DBLFUNCPTR mathFloorFunc;extern DBLFUNCPTR mathFmodFunc;extern DBLFUNCPTR mathHypotFunc;extern DBLFUNCPTR mathInfinityFunc;extern FUNCPTR mathIrintFunc;extern FUNCPTR mathIroundFunc;extern DBLFUNCPTR mathLogFunc;extern DBLFUNCPTR mathLog2Func;extern DBLFUNCPTR mathLog10Func;extern DBLFUNCPTR mathPowFunc;extern DBLFUNCPTR mathRoundFunc;extern DBLFUNCPTR mathSinFunc;extern VOIDFUNCPTR mathSincosFunc;extern DBLFUNCPTR mathSinhFunc;extern DBLFUNCPTR mathSqrtFunc;extern DBLFUNCPTR mathTanFunc;extern DBLFUNCPTR mathTanhFunc;extern DBLFUNCPTR mathTruncFunc;extern FLTFUNCPTR mathAcosfFunc; /* single-precision function ptrs */extern FLTFUNCPTR mathAsinfFunc;extern FLTFUNCPTR mathAtanfFunc;extern FLTFUNCPTR mathAtan2fFunc;extern FLTFUNCPTR mathCbrtfFunc;extern FLTFUNCPTR mathCeilfFunc;extern FLTFUNCPTR mathCosfFunc;extern FLTFUNCPTR mathCoshfFunc;extern FLTFUNCPTR mathExpfFunc;extern FLTFUNCPTR mathFabsfFunc;extern FLTFUNCPTR mathFmodfFunc;extern FLTFUNCPTR mathFloorfFunc;extern FLTFUNCPTR mathHypotfFunc;extern FLTFUNCPTR mathInfinityfFunc;extern FUNCPTR mathIrintfFunc;extern FUNCPTR mathIroundfFunc;extern FLTFUNCPTR mathLogfFunc;extern FLTFUNCPTR mathLog2fFunc;extern FLTFUNCPTR mathLog10fFunc;extern FLTFUNCPTR mathPowfFunc;extern FLTFUNCPTR mathRoundfFunc;extern FLTFUNCPTR mathSinfFunc;extern VOIDFUNCPTR mathSincosfFunc;extern FLTFUNCPTR mathSinhfFunc;extern FLTFUNCPTR mathSqrtfFunc;extern FLTFUNCPTR mathTanfFunc;extern FLTFUNCPTR mathTanhfFunc;extern FLTFUNCPTR mathTruncfFunc;/* Locals */LOCAL char *errMsgString = "ERROR - %s function not supported\n";/* Forward references */LOCAL double mathSoftAcos (double dblParam);LOCAL double mathSoftAsin (double dblParam);LOCAL double mathSoftAtan2 (double dblY, double dblX);LOCAL double mathSoftCbrt (double x);LOCAL double mathSoftCeil (double dblParam);LOCAL double mathSoftCosh (double dblParam);LOCAL double mathSoftFabs (double dblParam);LOCAL double mathSoftHypot (double dblX, double dblY);LOCAL double mathSoftLog2 (double dblParam);LOCAL double mathSoftPow (double dblX, double dblY);LOCAL double mathSoftSinh (double dblParam);LOCAL void mathSoftSincos (double dblParam, double *pSinResult, double *pCosResult);LOCAL double mathSoftTanh (double dblParam);LOCAL float mathSoftAcosf (float fltParam);LOCAL float mathSoftAsinf (float fltParam);LOCAL float mathSoftAtan2f (float fltY, float fltX);LOCAL float mathSoftCbrtf (float x);LOCAL float mathSoftCeilf (float fltParam);LOCAL float mathSoftFabsf (float fltParam);LOCAL float mathSoftHypotf (float fltX, float fltY);LOCAL float mathSoftLog2f (float fltParam);LOCAL float mathSoftPowf (float fltX, float fltY);LOCAL void mathSoftSincosf (float fltParam, float *pSinResult, float *pCosResult); /* unsupported */LOCAL void mathSoftFmod (double dblParam, double dblDivisor); /* unsupported */LOCAL void mathSoftIrint (double dblParam); /* unsupported */LOCAL void mathSoftIround (double dblParam); /* unsupported */LOCAL void mathSoftRound (double dblParam); /* unsupported */LOCAL void mathSoftTrunc (double dblParam); /* unsupported */LOCAL void mathSoftCoshf (float fltParam); /* unsupported */LOCAL void mathSoftFmodf (float fltParam, float fltDivisor); /* unsupported */LOCAL void mathSoftIrintf (float fltParam); /* unsupported */LOCAL void mathSoftIroundf (float fltParam); /* unsupported */LOCAL void mathSoftRoundf (float fltParam); /* unsupported */LOCAL void mathSoftSinhf (float fltParam); /* unsupported */LOCAL void mathSoftTanhf (float fltParam); /* unsupported */LOCAL void mathSoftTruncf (float fltParam);/******************************************************************************** mathSoftInit - initialize software floating-point math support** This routine places the addresses of the emulated high-level math* functions (trigonometric functions, etc.) in a set of global variables.* This allows the standard math functions (e.g., sin(), pow()) to have a* single entry point but be dispatched to the hardware or software support* routines, as specified.** This routine is called from usrConfig.c if INCLUDE_SW_FP is defined.* This definition causes the linker to include the floating-point* emulation library.** If the system is to use some combination of emulated as well as hardware* coprocessor floating points, then this routine should be called before calling* mathHardInit().** RETURNS: N/A** SEE ALSO: mathHardInit()**/void mathSoftInit () { /* Load software routine addresses into global variables * defined in mathALib.s. */ /* Double-precision routines */ mathAcosFunc = mathSoftAcos; mathAsinFunc = mathSoftAsin; mathAtanFunc = mathSoftAtan; mathAtan2Func = mathSoftAtan2; mathCbrtFunc = mathSoftCbrt; mathCeilFunc = mathSoftCeil; mathCosFunc = mathSoftCos; mathCoshFunc = mathSoftCosh; mathExpFunc = mathSoftExp; mathFabsFunc = mathSoftFabs; mathFmodFunc = (DBLFUNCPTR) mathSoftFmod; /* unsupported */ mathFloorFunc = mathSoftFloor; mathHypotFunc = mathSoftHypot; mathInfinityFunc = mathSoftInfinity; mathIrintFunc = (FUNCPTR) mathSoftIrint; /* unsupported */ mathIroundFunc = (FUNCPTR) mathSoftIround; /* unsupported */ mathLogFunc = mathSoftLog; mathLog2Func = mathSoftLog2; mathLog10Func = mathSoftLog10; mathPowFunc = mathSoftPow; mathRoundFunc = (DBLFUNCPTR) mathSoftRound; /* unsupported */ mathSinFunc = mathSoftSin; mathSincosFunc = mathSoftSincos; mathSinhFunc = mathSoftSinh; mathSqrtFunc = mathSoftSqrt; mathTanFunc = mathSoftTan; mathTanhFunc = mathSoftTanh; mathTruncFunc = (DBLFUNCPTR) mathSoftTrunc; /* unsupported */ /* Single-precision routines */ mathAcosfFunc = (FLTFUNCPTR)mathSoftAcosf; mathAsinfFunc = (FLTFUNCPTR)mathSoftAsinf; mathAtanfFunc = mathSoftAtanf; mathAtan2fFunc = (FLTFUNCPTR)mathSoftAtan2f; mathCbrtfFunc = (FLTFUNCPTR)mathSoftCbrtf; mathCeilfFunc = (FLTFUNCPTR)mathSoftCeilf; mathCosfFunc = mathSoftCosf; mathCoshfFunc = (FLTFUNCPTR) mathSoftCoshf; /* unsupported */ mathExpfFunc = mathSoftExpf; mathFabsfFunc = (FLTFUNCPTR)mathSoftFabsf; mathFmodfFunc = (FLTFUNCPTR) mathSoftFmodf; /* unsupported */ mathFloorfFunc = mathSoftFloorf; mathHypotfFunc = (FLTFUNCPTR)mathSoftHypotf; mathInfinityfFunc = mathSoftInfinityf; mathIrintfFunc = (FUNCPTR) mathSoftIrintf; /* unsupported */ mathIroundfFunc = (FUNCPTR) mathSoftIroundf; /* unsupported */ mathLogfFunc = mathSoftLogf; mathLog2fFunc = (FLTFUNCPTR)mathSoftLog2f; mathLog10fFunc = mathSoftLog10f; mathPowfFunc = (FLTFUNCPTR)mathSoftPowf; mathRoundfFunc = (FLTFUNCPTR) mathSoftRoundf; /* unsupported */ mathSinfFunc = mathSoftSinf; mathSincosfFunc = (VOIDFUNCPTR)mathSoftSincosf; mathSinhfFunc = (FLTFUNCPTR) mathSoftSinhf; /* unsupported */ mathSqrtfFunc = mathSoftSqrtf; mathTanfFunc = mathSoftTanf; mathTanhfFunc = (FLTFUNCPTR) mathSoftTanhf; /* unsupported */ mathTruncfFunc = (FLTFUNCPTR) mathSoftTruncf; /* unsupported */ }/******************************************************************************** mathSoftFabs - software floating point absolute value** This routine takes the input double-precision floating point* parameter and returns the absolute value.** RETURNS: double-precision absolute value.*/LOCAL double mathSoftFabs ( double dblParam ) { return ((dblParam < 0.0) ? -dblParam : dblParam); }/******************************************************************************** mathSoftCeil - software floating point ceiling** This routine takes the input double-precision floating point* parameter and returns (in double-precision floating point format)* the integer immediately greater than the input parameter.** RETURNS: double-precision representation of next largest integer.*/LOCAL double mathSoftCeil ( double dblParam ) { if (dblParam <= 0.0 && dblParam > -1.0) return 0.0; else return (-floor (-dblParam)); }/******************************************************************************** mathSoftPow - software floating point power function** This routine takes two input double-precision floating point* parameters, <dblX> and <dblY>, and returns the double-precision* value of <dblX> to the <dblY> power.** INTERNAL* The US Software emulation library has a special function for taking* a floating point number to an integer power. This routine therefore* checks to see if the <dblY> parameter is an integer, and uses the* US Software function (XTOI) if it is.** RETURNS: double-precision value of <dblX> to <dblY> power.*/LOCAL double mathSoftPow ( double dblX, double dblY ) { if (isNaN(dblY)) return (dblY); /* dblY = NaN --> NaN */ if (dblX == 1.0) return (1.0); /* dblX = 1 --> 1 */ if (dblY == floor (dblY)) /* int dblY --> XTOI(dblX,dblY) */ return (mathSoftRealtoint (dblX,(long int) dblY)); return (exp (dblY * log(dblX))); }/******************************************************************************** mathSoftAsin - software floating point arc sine** This routine takes the input double-precision floating point* parameter and returns the arc sine.** RETURNS: double-precision arc sine value.*/LOCAL double mathSoftAsin ( double dblParam ) { return (atan (dblParam / sqrt (1.0 - dblParam * dblParam))); }/******************************************************************************** mathSoftAcos - software floating point arc cosine** This routine takes the input double-precision floating point* parameter and returns the arc cosine.** RETURNS: double-precision arc cosine value.*/LOCAL double mathSoftAcos ( double dblParam ) { double result; result = atan (sqrt (1.0 - dblParam * dblParam) / dblParam);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -