home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / hobby / palmoon / palmoon.EXE / MathLib.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-13  |  11.3 KB  |  199 lines

  1. /* MathLib: Pilot shared library of IEEE-754 double math functions
  2.  *
  3.  * Library function prototypes for the calling application.  This is
  4.  * the file that the calling application should include in order to
  5.  * get access to the routines in the library; it serves the same
  6.  * function as the file "math.h" normally used on systems with
  7.  * standard math libraries.  Each function in the library has two
  8.  * prototypes listed; the first is for the programmer-friendly
  9.  * wrapper function in MathLib.c, the second is for the raw SYS_TRAP()
  10.  * invocation that actually calls the library routine.
  11.  *
  12.  * Copyright (C) 1997 Rick Huebner
  13.  *
  14.  * This program is free software; you can redistribute it and/or modify
  15.  * it under the terms of the GNU Library General Public License as
  16.  * published by the Free Software Foundation; either version 2 of
  17.  * the License, or (at your option) any later version.
  18.  *
  19.  * This program is distributed in the hope that it will be useful,
  20.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.  * GNU Library General Public License for more details.
  23.  *
  24.  * You should have received a copy of the GNU Library General Public License
  25.  * along with this program; see file COPYING.LIB.  If not, write to the
  26.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  27.  * Boston, MA 02111-1307, USA
  28.  *
  29.  * Version 1.01, 23 August 1997, Rick Huebner
  30.  */
  31. #ifndef __MATHLIB_H__
  32. #define __MATHLIB_H__
  33.  
  34. // Library name for use with SysLibFind()
  35. #define MathLibName        "MathLib"
  36. // Values for use with SysLibLoad()
  37. #define LibType            'libr'
  38. #define MathLibCreator    'MthL'
  39.  
  40. // This is the major version number of the library.  If new functions
  41. // are added to this library, this version number must be incremented
  42. // to protect programs which are compiled with this header from trying
  43. // to invoke the new functions in an old version of MathLib.prc,
  44. // which would be fatal.  Do NOT delete any functions from this list,
  45. // or any older programs which try to use them will die.  Any changes
  46. // other than adding new functions should be reflected in the minor
  47. // part of the version number, e.g. 1.1 if a bug fix, 2.0 if new
  48. // functions added.
  49. #define MathLibVersion 1
  50.  
  51. // Possible Err values from MathLib functions
  52. typedef enum MathLibErrorCode {
  53.     mlErrNone = 0,
  54.     mlErrOldVersion,    // library is older than version passed to open()
  55.     mlErrNotOpen,        // close() without having called open() first
  56.     mlErrNoMemory        // can't allocate global data block
  57. } MathLibErrorCode;
  58.  
  59. // Library reference returned by SysLibFind() or SysLibLoad()
  60. extern UInt16 MathLibRef;
  61.  
  62. /*****************************
  63.  * Library control functions *
  64.  *****************************/
  65. Err MathLibOpen(UInt16 refnum, UInt16 version)        // Initialize library for use
  66.     SYS_TRAP(sysLibTrapOpen);
  67. Err MathLibClose(UInt16 refnum, UInt16 *usecountP)// Free library resources when finished
  68.     SYS_TRAP(sysLibTrapClose);
  69. Err MathLibSleep(UInt16 refnum)                    // Called by OS when Pilot sleeps
  70.     SYS_TRAP(sysLibTrapSleep);
  71. Err MathLibWake(UInt16 refnum)                    // Called by OS when Pilot wakes
  72.     SYS_TRAP(sysLibTrapWake);
  73.  
  74. /***************************
  75.  * Trigonometric functions *
  76.  ***************************/
  77. double acos(double x);                // Arc cosine of x 
  78. double asin(double x);                // Arc sine of x    
  79. double atan(double x);                // Arc tangent of x    
  80. double atan2(double y, double x);    // Arc tangent of y/x    
  81. double cos(double x);                // Cosine of x    
  82. double sin(double x);                // Sine of x    
  83. double tan(double x);                // Tangent of x    
  84. void   sincos(double x, double *sinx, double *cosx);     // Sine and cosine of x    
  85.  
  86. /************************    
  87.  * Hyperbolic functions    *
  88.  ************************/ 
  89. double cosh(double x);                // Hyperbolic cosine of x 
  90. double sinh(double x);                // Hyperbolic sine of x
  91. double tanh(double x);                // Hyperbolic tangent of x
  92. double acosh(double x);                // Hyperbolic arc cosine of x
  93. double asinh(double x);                // Hyperbolic arc sine of x
  94. double atanh(double x);                // Hyperbolic arc tangent of x
  95.  
  96. /*****************************************
  97.  * Exponential and logarithmic functions *
  98.  *****************************************/
  99. double exp(double x);                    // Exponential function of x [pow(e,x)]
  100. double frexp(double x, Int16 *exponent);    // Break x into normalized fraction and an integral power of 2
  101. double ldexp(double x, Int16 exponent);    // x * pow(2,exponent)
  102. double log(double x);                    // Natural logarithm of x
  103. double log10(double x);                    // Base 10 logarithm of x
  104. double modf(double x, double *intpart);    // Break x into integral and fractional parts
  105. double expm1(double x);                    // exp(x) - 1
  106. double log1p(double x);                    // log(1+x)
  107. double logb(double x);                    // Base 2 signed integral exponent of x
  108. double log2(double x);                    // Base 2 logarithm of x
  109.  
  110. /*******************
  111.  * Power functions *
  112.  *******************/    
  113. double pow(double x, double y);        // x to the y power [x**y]
  114. double sqrt(double x);                // Square root of x [x**0.5]
  115. double hypot(double x, double y);    // sqrt(x*x + y*y)    [hypotenuse of right triangle]
  116. double cbrt(double x);                // Cube root of x    [x**(1/3)]
  117.  
  118. /************************************************************
  119.  * Nearest integer, absolute value, and remainder functions *
  120.  ************************************************************/
  121. double ceil(double x);                // Smallest integral value not less than x
  122. double fabs(double x);                // Absolute value of x
  123. double floor(double x);                // Largest integral value not greater than x
  124. double fmod(double x, double y);    // Modulo remainder of x/y
  125.  
  126. /***************************
  127.  * Miscellaneous functions *
  128.  ***************************/
  129. Int16    isinf(double x);                    // Return 0 if x is finite or NaN, +1 if +Infinity, or -1 if -Infinity
  130. Int16    finite(double x);                // Return nonzero if x is finite and not NaN
  131. double scalbn(double x, Int16 exponent);    // x * pow(2,exponent)
  132. double drem(double x, double y);        // Remainder of x/y
  133. double significand(double x);            // Fractional part of x after dividing out ilogb(x)
  134. double copysign(double x, double y);    // Return x with its sign changed to match y's
  135. Int16    isnan(double x);                    // Return nonzero if x is NaN (Not a Number)
  136. Int16    ilogb(double x);                    // Binary exponent of non-zero x
  137. double rint(double x);                    // Integral value nearest x in direction of prevailing rounding mode
  138. double nextafter(double x, double y);    // Next machine double value after x in the direction towards y
  139. double remainder(double x, double y);    // Remainder of integer division x/y with infinite precision
  140. double scalb(double x, double exponent);// x * pow(2,exponent)
  141. double round(double x);                    // Round x to nearest integral value away from zero
  142. double trunc(double x);                    // Round x to nearest integral value not larger than x
  143. UInt32  signbit(double x);                // Return signbit of x's machine representation
  144.  
  145. /****************************************
  146.  * Prototypes for the system traps that *
  147.  * actually perform the library calls,  *
  148.  * in the format mandated by the OS.    *
  149.  ****************************************/
  150. Err MathLibACos(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom);
  151. Err MathLibASin(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+1);
  152. Err MathLibATan(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+2);
  153. Err MathLibATan2(UInt16 refnum, double y, double x, double *result)    SYS_TRAP(sysLibTrapCustom+3);
  154. Err MathLibCos(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+4);
  155. Err MathLibSin(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+5);
  156. Err MathLibTan(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+6);
  157. Err MathLibSinCos(UInt16 refnum, double x, double *sinx, double *cosx)    SYS_TRAP(sysLibTrapCustom+7);
  158. Err MathLibCosH(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+8);
  159. Err MathLibSinH(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+9);
  160. Err MathLibTanH(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+10);
  161. Err MathLibACosH(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+11);
  162. Err MathLibASinH(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+12);
  163. Err MathLibATanH(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+13);
  164. Err MathLibExp(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+14);
  165. Err MathLibFrExp(UInt16 refnum, double x, double *fraction, Int16 *exponent)    SYS_TRAP(sysLibTrapCustom+15);
  166. Err MathLibLdExp(UInt16 refnum, double x, Int16 exponent, double *result)    SYS_TRAP(sysLibTrapCustom+16);
  167. Err MathLibLog(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+17);
  168. Err MathLibLog10(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+18);
  169. Err MathLibModF(UInt16 refnum, double x, double *intpart, double *fracpart)    SYS_TRAP(sysLibTrapCustom+19);
  170. Err MathLibExpM1(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+20);
  171. Err MathLibLog1P(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+21);
  172. Err MathLibLogB(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+22);
  173. Err MathLibLog2(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+23);
  174. Err MathLibPow(UInt16 refnum, double x, double y, double *result)    SYS_TRAP(sysLibTrapCustom+24);
  175. Err MathLibSqrt(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+25);
  176. Err MathLibHypot(UInt16 refnum, double x, double y, double *result)    SYS_TRAP(sysLibTrapCustom+26);
  177. Err MathLibCbrt(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+27);
  178. Err MathLibCeil(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+28);
  179. Err MathLibFAbs(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+29);
  180. Err MathLibFloor(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+30);
  181. Err MathLibFMod(UInt16 refnum, double x, double y, double *result)    SYS_TRAP(sysLibTrapCustom+31);
  182. Err MathLibIsInf(UInt16 refnum, double x, Int16 *result)    SYS_TRAP(sysLibTrapCustom+32);
  183. Err MathLibFinite(UInt16 refnum, double x, Int16 *result)    SYS_TRAP(sysLibTrapCustom+33);
  184. Err MathLibScalBN(UInt16 refnum, double x, Int16 exponent, double *result)    SYS_TRAP(sysLibTrapCustom+34);
  185. Err MathLibDRem(UInt16 refnum, double x, double y, double *result)    SYS_TRAP(sysLibTrapCustom+35);
  186. Err MathLibSignificand(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+36);
  187. Err MathLibCopySign(UInt16 refnum, double x, double y, double *result)    SYS_TRAP(sysLibTrapCustom+37);
  188. Err MathLibIsNaN(UInt16 refnum, double x, Int16 *result)    SYS_TRAP(sysLibTrapCustom+38);
  189. Err MathLibILogB(UInt16 refnum, double x, Int16 *result)    SYS_TRAP(sysLibTrapCustom+39);
  190. Err MathLibRInt(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+40);
  191. Err MathLibNextAfter(UInt16 refnum, double x, double y, double *result)    SYS_TRAP(sysLibTrapCustom+41);
  192. Err MathLibRemainder(UInt16 refnum, double x, double y, double *result)    SYS_TRAP(sysLibTrapCustom+42);
  193. Err MathLibScalB(UInt16 refnum, double x, double exponent, double *result)    SYS_TRAP(sysLibTrapCustom+43);
  194. Err MathLibRound(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+44);
  195. Err MathLibTrunc(UInt16 refnum, double x, double *result)    SYS_TRAP(sysLibTrapCustom+45);
  196. Err MathLibSignBit(UInt16 refnum, double x, UInt32 *result)    SYS_TRAP(sysLibTrapCustom+46);
  197.  
  198. #endif // __MATHLIB_H__
  199.