Main Page | Alphabetical List | Data Structures | File List | Globals | Related Pages

MathLib.h

00001 /* MathLib: Pilot shared library of IEEE-754 double math functions
00002  *
00003  * Library function prototypes for the calling application.  This is
00004  * the file that the calling application should include in order to
00005  * get access to the routines in the library; it serves the same
00006  * function as the file "math.h" normally used on systems with
00007  * standard math libraries.  Each function in the library has two
00008  * prototypes listed; the first is for the programmer-friendly
00009  * wrapper function in MathLib.c, the second is for the raw SYS_TRAP()
00010  * invocation that actually calls the library routine.
00011  *
00012  * Copyright (C) 1997 Rick Huebner
00013  *
00014  * This program is free software; you can redistribute it and/or modify
00015  * it under the terms of the GNU Library General Public License as
00016  * published by the Free Software Foundation; either version 2 of
00017  * the License, or (at your option) any later version.
00018  *
00019  * This program is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU Library General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Library General Public License
00025  * along with this program; see file COPYING.LIB.  If not, write to the
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00027  * Boston, MA 02111-1307, USA
00028  *
00029  * Version 1.01, 23 August 1997, Rick Huebner
00030  */
00031 #ifndef __MATHLIB_H__
00032 #define __MATHLIB_H__
00033 
00034 // Library name for use with SysLibFind()
00035 #define MathLibName             "MathLib"
00036 // Values for use with SysLibLoad()
00037 #define LibType                 'libr'
00038 #define MathLibCreator  'MthL'
00039 
00040 // This is the major version number of the library.  If new functions
00041 // are added to this library, this version number must be incremented
00042 // to protect programs which are compiled with this header from trying
00043 // to invoke the new functions in an old version of MathLib.prc,
00044 // which would be fatal.  Do NOT delete any functions from this list,
00045 // or any older programs which try to use them will die.  Any changes
00046 // other than adding new functions should be reflected in the minor
00047 // part of the version number, e.g. 1.1 if a bug fix, 2.0 if new
00048 // functions added.
00049 #define MathLibVersion 1
00050 
00051 // Possible Err values from MathLib functions
00052 typedef enum MathLibErrorCode {
00053         mlErrNone = 0,
00054         mlErrOldVersion,        // library is older than version passed to open()
00055         mlErrNotOpen,           // close() without having called open() first
00056         mlErrNoMemory           // can't allocate global data block
00057 } MathLibErrorCode;
00058 
00059 // Library reference returned by SysLibFind() or SysLibLoad()
00060 extern UInt16 MathLibRef;
00061 
00062 /*****************************
00063  * Library control functions *
00064  *****************************/
00065 Err MathLibOpen(UInt16 refnum, UInt16 version)          // Initialize library for use
00066         SYS_TRAP(sysLibTrapOpen);
00067 Err MathLibClose(UInt16 refnum, UInt16* usecountP)// Free library resources when finished
00068         SYS_TRAP(sysLibTrapClose);
00069 Err MathLibSleep(UInt16 refnum)                                 // Called by OS when Pilot sleeps
00070         SYS_TRAP(sysLibTrapSleep);
00071 Err MathLibWake(UInt16 refnum)                                  // Called by OS when Pilot wakes
00072         SYS_TRAP(sysLibTrapWake);
00073 
00074 /***************************
00075  * Trigonometric functions *
00076  ***************************/
00077 double acos(double x);                          // Arc cosine of x 
00078 double asin(double x);                          // Arc sine of x        
00079 double atan(double x);                          // Arc tangent of x     
00080 double atan2(double y, double x);       // Arc tangent of y/x   
00081 double cos(double x);                           // Cosine of x  
00082 double sin(double x);                           // Sine of x    
00083 double tan(double x);                           // Tangent of x 
00084 void   sincos(double x, double *sinx, double *cosx);    // Sine and cosine of x 
00085 
00086 /************************       
00087  * Hyperbolic functions *
00088  ************************/ 
00089 double cosh(double x);                          // Hyperbolic cosine of x 
00090 double sinh(double x);                          // Hyperbolic sine of x
00091 double tanh(double x);                          // Hyperbolic tangent of x
00092 double acosh(double x);                         // Hyperbolic arc cosine of x
00093 double asinh(double x);                         // Hyperbolic arc sine of x
00094 double atanh(double x);                         // Hyperbolic arc tangent of x
00095 
00096 /*****************************************
00097  * Exponential and logarithmic functions *
00098  *****************************************/
00099 double exp(double x);                                   // Exponential function of x [pow(e,x)]
00100 double frexp(double x, Int16 *exponent);        // Break x into normalized fraction and an integral power of 2
00101 double ldexp(double x, Int16 exponent); // x * pow(2,exponent)
00102 double log(double x);                                   // Natural logarithm of x
00103 double log10(double x);                                 // Base 10 logarithm of x
00104 double modf(double x, double *intpart); // Break x into integral and fractional parts
00105 double expm1(double x);                                 // exp(x) - 1
00106 double log1p(double x);                                 // log(1+x)
00107 double logb(double x);                                  // Base 2 signed integral exponent of x
00108 double log2(double x);                                  // Base 2 logarithm of x
00109 
00110 /*******************
00111  * Power functions *
00112  *******************/   
00113 double pow(double x, double y);         // x to the y power [x**y]
00114 double sqrt(double x);                          // Square root of x [x**0.5]
00115 double hypot(double x, double y);       // sqrt(x*x + y*y)      [hypotenuse of right triangle]
00116 double cbrt(double x);                          // Cube root of x       [x**(1/3)]
00117 
00118 /************************************************************
00119  * Nearest integer, absolute value, and remainder functions *
00120  ************************************************************/
00121 double ceil(double x);                          // Smallest integral value not less than x
00122 double fabs(double x);                          // Absolute value of x
00123 double floor(double x);                         // Largest integral value not greater than x
00124 double fmod(double x, double y);        // Modulo remainder of x/y
00125 
00126 /***************************
00127  * Miscellaneous functions *
00128  ***************************/
00129 Int16    isinf(double x);                                       // Return 0 if x is finite or NaN, +1 if +Infinity, or -1 if -Infinity
00130 Int16    finite(double x);                              // Return nonzero if x is finite and not NaN
00131 double scalbn(double x, Int16 exponent);        // x * pow(2,exponent)
00132 double drem(double x, double y);                // Remainder of x/y
00133 double significand(double x);                   // Fractional part of x after dividing out ilogb(x)
00134 double copysign(double x, double y);    // Return x with its sign changed to match y's
00135 Int16    isnan(double x);                                       // Return nonzero if x is NaN (Not a Number)
00136 Int16    ilogb(double x);                                       // Binary exponent of non-zero x
00137 double rint(double x);                                  // Integral value nearest x in direction of prevailing rounding mode
00138 double nextafter(double x, double y);   // Next machine double value after x in the direction towards y
00139 double remainder(double x, double y);   // Remainder of integer division x/y with infinite precision
00140 double scalb(double x, double exponent);// x * pow(2,exponent)
00141 double round(double x);                                 // Round x to nearest integral value away from zero
00142 double trunc(double x);                                 // Round x to nearest integral value not larger than x
00143 UInt32  signbit(double x);                              // Return signbit of x's machine representation
00144 
00145 /****************************************
00146  * Prototypes for the system traps that *
00147  * actually perform the library calls,  *
00148  * in the format mandated by the OS.    *
00149  ****************************************/
00150 Err MathLibACos(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom);
00151 Err MathLibASin(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+1);
00152 Err MathLibATan(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+2);
00153 Err MathLibATan2(UInt16 refnum, double y, double x, double *result)     SYS_TRAP(sysLibTrapCustom+3);
00154 Err MathLibCos(UInt16 refnum, double x, double *result) SYS_TRAP(sysLibTrapCustom+4);
00155 Err MathLibSin(UInt16 refnum, double x, double *result) SYS_TRAP(sysLibTrapCustom+5);
00156 Err MathLibTan(UInt16 refnum, double x, double *result) SYS_TRAP(sysLibTrapCustom+6);
00157 Err MathLibSinCos(UInt16 refnum, double x, double *sinx, double *cosx)  SYS_TRAP(sysLibTrapCustom+7);
00158 Err MathLibCosH(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+8);
00159 Err MathLibSinH(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+9);
00160 Err MathLibTanH(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+10);
00161 Err MathLibACosH(UInt16 refnum, double x, double *result)       SYS_TRAP(sysLibTrapCustom+11);
00162 Err MathLibASinH(UInt16 refnum, double x, double *result)       SYS_TRAP(sysLibTrapCustom+12);
00163 Err MathLibATanH(UInt16 refnum, double x, double *result)       SYS_TRAP(sysLibTrapCustom+13);
00164 Err MathLibExp(UInt16 refnum, double x, double *result) SYS_TRAP(sysLibTrapCustom+14);
00165 Err MathLibFrExp(UInt16 refnum, double x, double *fraction, Int16 *exponent)    SYS_TRAP(sysLibTrapCustom+15);
00166 Err MathLibLdExp(UInt16 refnum, double x, Int16 exponent, double *result)       SYS_TRAP(sysLibTrapCustom+16);
00167 Err MathLibLog(UInt16 refnum, double x, double *result) SYS_TRAP(sysLibTrapCustom+17);
00168 Err MathLibLog10(UInt16 refnum, double x, double *result)       SYS_TRAP(sysLibTrapCustom+18);
00169 Err MathLibModF(UInt16 refnum, double x, double *intpart, double *fracpart)     SYS_TRAP(sysLibTrapCustom+19);
00170 Err MathLibExpM1(UInt16 refnum, double x, double *result)       SYS_TRAP(sysLibTrapCustom+20);
00171 Err MathLibLog1P(UInt16 refnum, double x, double *result)       SYS_TRAP(sysLibTrapCustom+21);
00172 Err MathLibLogB(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+22);
00173 Err MathLibLog2(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+23);
00174 Err MathLibPow(UInt16 refnum, double x, double y, double *result)       SYS_TRAP(sysLibTrapCustom+24);
00175 Err MathLibSqrt(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+25);
00176 Err MathLibHypot(UInt16 refnum, double x, double y, double *result)     SYS_TRAP(sysLibTrapCustom+26);
00177 Err MathLibCbrt(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+27);
00178 Err MathLibCeil(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+28);
00179 Err MathLibFAbs(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+29);
00180 Err MathLibFloor(UInt16 refnum, double x, double *result)       SYS_TRAP(sysLibTrapCustom+30);
00181 Err MathLibFMod(UInt16 refnum, double x, double y, double *result)      SYS_TRAP(sysLibTrapCustom+31);
00182 Err MathLibIsInf(UInt16 refnum, double x, Int16 *result)        SYS_TRAP(sysLibTrapCustom+32);
00183 Err MathLibFinite(UInt16 refnum, double x, Int16 *result)       SYS_TRAP(sysLibTrapCustom+33);
00184 Err MathLibScalBN(UInt16 refnum, double x, Int16 exponent, double *result)      SYS_TRAP(sysLibTrapCustom+34);
00185 Err MathLibDRem(UInt16 refnum, double x, double y, double *result)      SYS_TRAP(sysLibTrapCustom+35);
00186 Err MathLibSignificand(UInt16 refnum, double x, double *result) SYS_TRAP(sysLibTrapCustom+36);
00187 Err MathLibCopySign(UInt16 refnum, double x, double y, double *result)  SYS_TRAP(sysLibTrapCustom+37);
00188 Err MathLibIsNaN(UInt16 refnum, double x, Int16 *result)        SYS_TRAP(sysLibTrapCustom+38);
00189 Err MathLibILogB(UInt16 refnum, double x, Int16 *result)        SYS_TRAP(sysLibTrapCustom+39);
00190 Err MathLibRInt(UInt16 refnum, double x, double *result)        SYS_TRAP(sysLibTrapCustom+40);
00191 Err MathLibNextAfter(UInt16 refnum, double x, double y, double *result) SYS_TRAP(sysLibTrapCustom+41);
00192 Err MathLibRemainder(UInt16 refnum, double x, double y, double *result) SYS_TRAP(sysLibTrapCustom+42);
00193 Err MathLibScalB(UInt16 refnum, double x, double exponent, double *result)      SYS_TRAP(sysLibTrapCustom+43);
00194 Err MathLibRound(UInt16 refnum, double x, double *result)       SYS_TRAP(sysLibTrapCustom+44);
00195 Err MathLibTrunc(UInt16 refnum, double x, double *result)       SYS_TRAP(sysLibTrapCustom+45);
00196 Err MathLibSignBit(UInt16 refnum, double x, UInt32 *result)     SYS_TRAP(sysLibTrapCustom+46);
00197  
00198 #endif // __MATHLIB_H__

Generated on Sun Mar 13 09:36:01 2005 for GPilotS by doxygen 1.3.6