fp.h
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:41k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*
  2.      File:       fp.h
  3.  
  4.      Contains:   FPCE Floating-Point Definitions and Declarations.
  5.  
  6.      Version:    Technology: MathLib v2
  7.                  Release:    QuickTime 6.0.2
  8.  
  9.      Copyright:  (c) 1987-2001 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:      For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __FP__
  18. #define __FP__
  19. #ifndef __CONDITIONALMACROS__
  20. #include "ConditionalMacros.h"
  21. #endif
  22. #ifndef __MACTYPES__
  23. #include "MacTypes.h"
  24. #endif
  25. /********************************************************************************
  26. *                                                                               *
  27. *    A collection of numerical functions designed to facilitate a wide          *
  28. *    range of numerical programming as required by C9X.                         *
  29. *                                                                               *
  30. *    The <fp.h> declares many functions in support of numerical programming.    *
  31. *    It provides a superset of <math.h> and <SANE.h> functions.  Some           *
  32. *    functionality previously found in <SANE.h> and not in the FPCE <fp.h>      *
  33. *    can be found in this <fp.h> under the heading "__NOEXTENSIONS__".          *
  34. *                                                                               *
  35. *    All of these functions are IEEE 754 aware and treat exceptions, NaNs,      *
  36. *    positive and negative zero and infinity consistent with the floating-      *
  37. *    point standard.                                                            *
  38. *                                                                               *
  39. ********************************************************************************/
  40. #if PRAGMA_ONCE
  41. #pragma once
  42. #endif
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. #if PRAGMA_IMPORT
  47. #pragma import on
  48. #endif
  49. #if PRAGMA_STRUCT_ALIGN
  50.     #pragma options align=mac68k
  51. #elif PRAGMA_STRUCT_PACKPUSH
  52.     #pragma pack(push, 2)
  53. #elif PRAGMA_STRUCT_PACK
  54.     #pragma pack(2)
  55. #endif
  56. /********************************************************************************
  57. *                                                                               *
  58. *                            Efficient types                                    *
  59. *                                                                               *
  60. *    float_t         Most efficient type at least as wide as float              *
  61. *    double_t        Most efficient type at least as wide as double             *
  62. *                                                                               *
  63. *      CPU            float_t(bits)                double_t(bits)               *
  64. *    --------        -----------------            -----------------             *
  65. *    PowerPC          float(32)                    double(64)                   *
  66. *    68K              long double(80/96)           long double(80/96)           *
  67. *    x86              long double(80)              long double(80)              *
  68. *                                                                               *
  69. ********************************************************************************/
  70. #if defined(__MWERKS__) && defined(__cmath__)
  71. /* these types were already defined in MSL's math.h */
  72. #else
  73. #if TARGET_CPU_PPC
  74. typedef float                           float_t;
  75. typedef double                          double_t;
  76. #elif TARGET_CPU_68K
  77. typedef long double                     float_t;
  78. typedef long double                     double_t;
  79. #elif TARGET_CPU_X86
  80. #if NeXT || TARGET_OS_MAC
  81. typedef double                          float_t;
  82. typedef double                          double_t;
  83. #else
  84. typedef long double                     float_t;
  85. typedef long double                     double_t;
  86. #endif  /* NeXT || TARGET_OS_MAC */
  87. #elif TARGET_CPU_MIPS
  88. typedef double                          float_t;
  89. typedef double                          double_t;
  90. #elif TARGET_CPU_ALPHA
  91. typedef double                          float_t;
  92. typedef double                          double_t;
  93. #elif TARGET_CPU_SPARC
  94. typedef double                          float_t;
  95. typedef double                          double_t;
  96. #else
  97. #error unsupported CPU
  98. #endif  /*  */
  99. /********************************************************************************
  100. *                                                                               *
  101. *                              Define some constants.                           *
  102. *                                                                               *
  103. *    HUGE_VAL            IEEE 754 value of infinity.                            *
  104. *    INFINITY            IEEE 754 value of infinity.                            *
  105. *    NAN                 A generic NaN (Not A Number).                          *
  106. *    DECIMAL_DIG         Satisfies the constraint that the conversion from      *
  107. *                        double to decimal and back is the identity function.   *
  108. *                                                                               *
  109. ********************************************************************************/
  110. #if TARGET_OS_MAC
  111.   #if TARGET_RT_MAC_MACHO
  112.     #define   HUGE_VAL                1e500 /* compatible with bsd math.h */
  113.   #else
  114.     #define   HUGE_VAL                __inf()
  115.   #endif
  116.   #define     INFINITY                __inf()
  117.   #define     NAN                     nan("255")
  118. #else
  119.   #define     NAN                     sqrt(-1)
  120. #endif
  121. #if TARGET_CPU_PPC
  122.     #define      DECIMAL_DIG              17 /* does not exist for double-double */
  123. #elif TARGET_CPU_68K
  124.     #define      DECIMAL_DIG              21
  125. #endif      
  126. #endif  /* __MWERKS__ && __cmath__ */
  127. #if TARGET_OS_MAC
  128. /* MSL already defines these */
  129. #if !defined(__MWERKS__) || !defined(__cmath__)
  130. /********************************************************************************
  131. *                                                                               *
  132. *                            Trigonometric functions                            *
  133. *                                                                               *
  134. *   acos        result is in [0,pi].                                            *
  135. *   asin        result is in [-pi/2,pi/2].                                      *
  136. *   atan        result is in [-pi/2,pi/2].                                      *
  137. *   atan2       Computes the arc tangent of y/x in [-pi,pi] using the sign of   *
  138. *               both arguments to determine the quadrant of the computed value. *
  139. *                                                                               *
  140. ********************************************************************************/
  141. EXTERN_API_C( double_t ) cos(double_t x);
  142. EXTERN_API_C( double_t ) sin(double_t x);
  143. EXTERN_API_C( double_t ) tan(double_t x);
  144. EXTERN_API_C( double_t ) acos(double_t x);
  145. EXTERN_API_C( double_t ) asin(double_t x);
  146. EXTERN_API_C( double_t ) atan(double_t x);
  147. EXTERN_API_C( double_t ) atan2(double_t y, double_t x);
  148. /********************************************************************************
  149. *                                                                               *
  150. *                              Hyperbolic functions                             *
  151. *                                                                               *
  152. ********************************************************************************/
  153. EXTERN_API_C( double_t ) cosh(double_t x);
  154. EXTERN_API_C( double_t ) sinh(double_t x);
  155. EXTERN_API_C( double_t ) tanh(double_t x);
  156. EXTERN_API_C( double_t ) acosh(double_t x);
  157. EXTERN_API_C( double_t ) asinh(double_t x);
  158. EXTERN_API_C( double_t ) atanh(double_t x);
  159. /********************************************************************************
  160. *                                                                               *
  161. *                              Exponential functions                            *
  162. *                                                                               *
  163. *   expm1       expm1(x) = exp(x) - 1.  But, for small enough arguments,        *
  164. *               expm1(x) is expected to be more accurate than exp(x) - 1.       *
  165. *   frexp       Breaks a floating-point number into a normalized fraction       *
  166. *               and an integral power of 2.  It stores the integer in the       *
  167. *               object pointed by *exponent.                                    *
  168. *   ldexp       Multiplies a floating-point number by an integer power of 2.    *
  169. *   log1p       log1p = log(1 + x). But, for small enough arguments,            *
  170. *               log1p is expected to be more accurate than log(1 + x).          *
  171. *   logb        Extracts the exponent of its argument, as a signed integral     *
  172. *               value. A subnormal argument is treated as though it were first  *
  173. *               normalized. Thus:                                               *
  174. *                                  1   <=   x * 2^(-logb(x))   <   2            *
  175. *   modf        Returns fractional part of x as function result and returns     *
  176. *               integral part of x via iptr. Note C9X uses double not double_t. *
  177. *   scalb       Computes x * 2^n efficently.  This is not normally done by      *
  178. *               computing 2^n explicitly.                                       *
  179. *                                                                               *
  180. ********************************************************************************/
  181. EXTERN_API_C( double_t ) exp(double_t x);
  182. EXTERN_API_C( double_t ) expm1(double_t x);
  183. EXTERN_API_C( double_t ) exp2(double_t x);
  184. EXTERN_API_C( double_t ) frexp(double_t x, int *exponent);
  185. EXTERN_API_C( double_t ) ldexp(double_t x, int n);
  186. EXTERN_API_C( double_t ) log(double_t x);
  187. EXTERN_API_C( double_t ) log2(double_t x);
  188. EXTERN_API_C( double_t ) log1p(double_t x);
  189. EXTERN_API_C( double_t ) log10(double_t x);
  190. EXTERN_API_C( double_t ) logb(double_t x);
  191. #if !TARGET_RT_MAC_MACHO
  192. EXTERN_API_C( long double ) modfl(long double x, long double *iptrl);
  193. #endif  /* !TARGET_RT_MAC_MACHO */
  194. EXTERN_API_C( double_t ) modf(double_t x, double_t *iptr);
  195. EXTERN_API_C( float ) modff(float x, float *iptrf);
  196. EXTERN_API_C( double_t ) scalb(double_t x, long n);
  197. /********************************************************************************
  198. *                                                                               *
  199. *                     Power and absolute value functions                        *
  200. *                                                                               *
  201. *   hypot       Computes the square root of the sum of the squares of its       *
  202. *               arguments, without undue overflow or underflow.                 *
  203. *   pow         Returns x raised to the power of y.  Result is more accurate    *
  204. *               than using exp(log(x)*y).                                       *
  205. *                                                                               *
  206. ********************************************************************************/
  207. EXTERN_API_C( double_t ) fabs(double_t x);
  208. EXTERN_API_C( double_t ) hypot(double_t x, double_t y);
  209. EXTERN_API_C( double_t ) pow(double_t x, double_t y);
  210. EXTERN_API_C( double_t ) sqrt(double_t x);
  211. /********************************************************************************
  212. *                                                                               *
  213. *                        Gamma and Error functions                              *
  214. *                                                                               *
  215. *   erf         The error function.                                             *
  216. *   erfc        Complementary error function.                                   *
  217. *   gamma       The gamma function.                                             *
  218. *   lgamma      Computes the base-e logarithm of the absolute value of          *
  219. *               gamma of its argument x, for x > 0.                             *
  220. *                                                                               *
  221. ********************************************************************************/
  222. EXTERN_API_C( double_t ) erf(double_t x);
  223. EXTERN_API_C( double_t ) erfc(double_t x);
  224. EXTERN_API_C( double_t ) gamma(double_t x);
  225. EXTERN_API_C( double_t ) lgamma(double_t x);
  226. /********************************************************************************
  227. *                                                                               *
  228. *                        Nearest integer functions                              *
  229. *                                                                               *
  230. *   rint        Rounds its argument to an integral value in floating point      *
  231. *               format, honoring the current rounding direction.                *
  232. *                                                                               *
  233. *   nearbyint   Differs from rint only in that it does not raise the inexact    *
  234. *               exception. It is the nearbyint function recommended by the      *
  235. *               IEEE floating-point standard 854.                               *
  236. *                                                                               *
  237. *   rinttol     Rounds its argument to the nearest long int using the current   *
  238. *               rounding direction.  NOTE: if the rounded value is outside      *
  239. *               the range of long int, then the result is undefined.            *
  240. *                                                                               *
  241. *   round       Rounds the argument to the nearest integral value in floating   *
  242. *               point format similar to the Fortran "anint" function. That is:  *
  243. *               add half to the magnitude and chop.                             *
  244. *                                                                               *
  245. *   roundtol    Similar to the Fortran function nint or to the Pascal round.    *
  246. *               NOTE: if the rounded value is outside the range of long int,    *
  247. *               then the result is undefined.                                   *
  248. *                                                                               *
  249. *   trunc       Computes the integral value, in floating format, nearest to     *
  250. *               but no larger in magnitude than its argument.   NOTE: on 68K    *
  251. *               compilers when using -elems881, trunc must return an int        *
  252. *                                                                               *
  253. ********************************************************************************/
  254. EXTERN_API_C( double_t ) ceil(double_t x);
  255. EXTERN_API_C( double_t ) floor(double_t x);
  256. EXTERN_API_C( double_t ) rint(double_t x);
  257. EXTERN_API_C( double_t ) nearbyint(double_t x);
  258. EXTERN_API_C( long ) rinttol(double_t x);
  259. EXTERN_API_C( double_t ) round(double_t x);
  260. EXTERN_API_C( long ) roundtol(double_t round);
  261. #if TARGET_RT_MAC_68881
  262. #if CALL_NOT_IN_CARBON
  263. EXTERN_API_C( int ) trunc(double_t x);
  264. #endif  /* CALL_NOT_IN_CARBON */
  265. #else
  266. EXTERN_API_C( double_t ) trunc(double_t x);
  267. #endif  /* TARGET_RT_MAC_68881 */
  268. /********************************************************************************
  269. *                                                                               *
  270. *                            Remainder functions                                *
  271. *                                                                               *
  272. *   remainder       IEEE 754 floating point standard for remainder.             *
  273. *   remquo          SANE remainder.  It stores into 'quotient' the 7 low-order  *
  274. *                   bits of the integer quotient x/y, such that:                *
  275. *                       -127 <= quotient <= 127.                                *
  276. *                                                                               *
  277. ********************************************************************************/
  278. EXTERN_API_C( double_t ) fmod(double_t x, double_t y);
  279. EXTERN_API_C( double_t ) remainder(double_t x, double_t y);
  280. EXTERN_API_C( double_t ) remquo(double_t x, double_t y, int *quo);
  281. /********************************************************************************
  282. *                                                                               *
  283. *                             Auxiliary functions                               *
  284. *                                                                               *
  285. *   copysign        Produces a value with the magnitude of its first argument   *
  286. *                   and sign of its second argument.  NOTE: the order of the    *
  287. *                   arguments matches the recommendation of the IEEE 754        *
  288. *                   floating point standard,  which is opposite from the SANE   *
  289. *                   copysign function.                                          *
  290. *                                                                               *
  291. *   nan             The call 'nan("n-char-sequence")' returns a quiet NaN       *
  292. *                   with content indicated through tagp in the selected         *
  293. *                   data type format.                                           *
  294. *                                                                               *
  295. *   nextafter       Computes the next representable value after 'x' in the      *
  296. *                   direction of 'y'.  if x == y, then y is returned.           *
  297. *                                                                               *
  298. ********************************************************************************/
  299. EXTERN_API_C( double_t ) copysign(double_t x, double_t y);
  300. #if !TARGET_RT_MAC_MACHO
  301. EXTERN_API_C( long double ) nanl(const char *tagp);
  302. #else
  303. #define nanl(tagp) ((long double)nan(tagp))
  304. #endif  /* !TARGET_RT_MAC_MACHO */
  305. EXTERN_API_C( double ) nan(const char *tagp);
  306. EXTERN_API_C( float ) nanf(const char *tagp);
  307. #if !TARGET_RT_MAC_MACHO
  308. EXTERN_API_C( long double ) nextafterl(long double x, long double y);
  309. #else
  310. #define nextafterl(x,y) ((long double)nextafter((double)x,(double)y))
  311. #endif  /* !TARGET_RT_MAC_MACHO */
  312. EXTERN_API_C( double ) nextafterd(double x, double y);
  313. EXTERN_API_C( float ) nextafterf(float x, float y);
  314. /********************************************************************************
  315. *                                                                               *
  316. *                              Inquiry macros                                   *
  317. *                                                                               *
  318. *   fpclassify      Returns one of the FP_* values.                             *
  319. *   isnormal        Non-zero if and only if the argument x is normalized.       *
  320. *   isfinite        Non-zero if and only if the argument x is finite.           *
  321. *   isnan           Non-zero if and only if the argument x is a NaN.            *
  322. *   signbit         Non-zero if and only if the sign of the argument x is       *
  323. *                   negative.  This includes, NaNs, infinities and zeros.       *
  324. *                                                                               *
  325. ********************************************************************************/
  326. enum {
  327.     FP_SNAN                     = 0,                            /*      signaling NaN                         */
  328.     FP_QNAN                     = 1,                            /*      quiet NaN                             */
  329.     FP_INFINITE                 = 2,                            /*      + or - infinity                       */
  330.     FP_ZERO                     = 3,                            /*      + or - zero                           */
  331.     FP_NORMAL                   = 4,                            /*      all normal numbers                    */
  332.     FP_SUBNORMAL                = 5                             /*      denormal numbers                      */
  333. };
  334. #if TARGET_RT_MAC_MACHO
  335. #define __fpclassify(x) __fpclassifyd((double)x)
  336. #define __isnormal(x)   __isnormald((double)x)
  337. #define __isfinite(x)   __isfinited((double)x)
  338. #define __isnan(x)      __isnand((double)x)
  339. #define __signbit(x)    __signbitd((double)x)
  340. #endif
  341. #define      fpclassify(x)    ( ( sizeof ( x ) == sizeof(long double) ) ?      
  342.                               __fpclassify  ( x ) :                            
  343.                                 ( sizeof ( x ) == sizeof(double) ) ?           
  344.                               __fpclassifyd ( x ) :                            
  345.                               __fpclassifyf ( x ) )
  346. #define      isnormal(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      
  347.                               __isnormal ( x ) :                               
  348.                                 ( sizeof ( x ) == sizeof(double) ) ?           
  349.                               __isnormald ( x ) :                              
  350.                               __isnormalf ( x ) )
  351. #define      isfinite(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      
  352.                               __isfinite ( x ) :                               
  353.                                 ( sizeof ( x ) == sizeof(double) ) ?           
  354.                               __isfinited ( x ) :                              
  355.                               __isfinitef ( x ) )
  356. #define      isnan(x)         ( ( sizeof ( x ) == sizeof(long double) ) ?      
  357.                               __isnan ( x ) :                                  
  358.                               ( sizeof ( x ) == sizeof(double) ) ?             
  359.                               __isnand ( x ) :                                 
  360.                               __isnanf ( x ) )
  361. #define      signbit(x)       ( ( sizeof ( x ) == sizeof(long double) ) ?      
  362.                               __signbit ( x ) :                                
  363.                               ( sizeof ( x ) == sizeof(double) ) ?             
  364.                               __signbitd ( x ) :                               
  365.                               __signbitf ( x ) )
  366. #if !TARGET_RT_MAC_MACHO
  367. EXTERN_API_C( long ) __fpclassify(long double x);
  368. #endif  /* !TARGET_RT_MAC_MACHO */
  369. EXTERN_API_C( long ) __fpclassifyd(double x);
  370. EXTERN_API_C( long ) __fpclassifyf(float x);
  371. #if !TARGET_RT_MAC_MACHO
  372. EXTERN_API_C( long ) __isnormal(long double x);
  373. #endif  /* !TARGET_RT_MAC_MACHO */
  374. EXTERN_API_C( long ) __isnormald(double x);
  375. EXTERN_API_C( long ) __isnormalf(float x);
  376. #if !TARGET_RT_MAC_MACHO
  377. EXTERN_API_C( long ) __isfinite(long double x);
  378. #endif  /* !TARGET_RT_MAC_MACHO */
  379. EXTERN_API_C( long ) __isfinited(double x);
  380. EXTERN_API_C( long ) __isfinitef(float x);
  381. #if !TARGET_RT_MAC_MACHO
  382. EXTERN_API_C( long ) __isnan(long double x);
  383. #endif  /* !TARGET_RT_MAC_MACHO */
  384. EXTERN_API_C( long ) __isnand(double x);
  385. EXTERN_API_C( long ) __isnanf(float x);
  386. #if !TARGET_RT_MAC_MACHO
  387. EXTERN_API_C( long ) __signbit(long double x);
  388. #endif  /* !TARGET_RT_MAC_MACHO */
  389. EXTERN_API_C( long ) __signbitd(double x);
  390. EXTERN_API_C( long ) __signbitf(float x);
  391. EXTERN_API_C( double_t ) __inf(void );
  392. /********************************************************************************
  393. *                                                                               *
  394. *                      Max, Min and Positive Difference                         *
  395. *                                                                               *
  396. *   fdim        Determines the 'positive difference' between its arguments:     *
  397. *               { x - y, if x > y }, { +0, if x <= y }.  If one argument is     *
  398. *               NaN, then fdim returns that NaN.  if both arguments are NaNs,   *
  399. *               then fdim returns the first argument.                           *
  400. *                                                                               *
  401. *   fmax        Returns the maximum of the two arguments.  Corresponds to the   *
  402. *               max function in FORTRAN.  NaN arguments are treated as missing  *
  403. *               data.  If one argument is NaN and the other is a number, then   *
  404. *               the number is returned.  If both are NaNs then the first        *
  405. *               argument is returned.                                           *
  406. *                                                                               *
  407. *   fmin        Returns the minimum of the two arguments.  Corresponds to the   *
  408. *               min function in FORTRAN.  NaN arguments are treated as missing  *
  409. *               data.  If one argument is NaN and the other is a number, then   *
  410. *               the number is returned.  If both are NaNs then the first        *
  411. *               argument is returned.                                           *
  412. *                                                                               *
  413. ********************************************************************************/
  414. EXTERN_API_C( double_t ) fdim(double_t x, double_t y);
  415. EXTERN_API_C( double_t ) fmax(double_t x, double_t y);
  416. EXTERN_API_C( double_t ) fmin(double_t x, double_t y);
  417. #endif /* !defined(__MWERKS__) || !defined(__cmath__) */
  418. /*******************************************************************************
  419. *                                Constants                                     *
  420. *******************************************************************************/
  421. extern const double_t pi;
  422. /********************************************************************************
  423. *                                                                               *
  424. *                              Non NCEG extensions                              *
  425. *                                                                               *
  426. ********************************************************************************/
  427. #ifndef __NOEXTENSIONS__
  428. /********************************************************************************
  429. *                                                                               *
  430. *                              Financial functions                              *
  431. *                                                                               *
  432. *   compound        Computes the compound interest factor "(1 + rate)^periods"  *
  433. *                   more accurately than the straightforward computation with   *
  434. *                   the Power function.  This is SANE's compound function.      *
  435. *                                                                               *
  436. *   annuity         Computes the present value factor for an annuity            *
  437. *                   "(1 - (1 + rate)^(-periods)) /rate" more accurately than    *
  438. *                   the straightforward computation with the Power function.    *
  439. *                   This is SANE's annuity function.                            *
  440. *                                                                               *
  441. ********************************************************************************/
  442. EXTERN_API_C( double_t ) compound(double_t rate, double_t periods);
  443. EXTERN_API_C( double_t ) annuity(double_t rate, double_t periods);
  444. /********************************************************************************
  445. *                                                                               *
  446. *                              Random function                                  *
  447. *                                                                               *
  448. *   randomx         A pseudorandom number generator.  It uses the iteration:    *
  449. *                               (7^5*x)mod(2^31-1)                              *
  450. *                                                                               *
  451. ********************************************************************************/
  452. EXTERN_API_C( double_t ) randomx(double_t *x);
  453. /*******************************************************************************
  454. *                              Relational operator                             *
  455. *******************************************************************************/
  456. /*      relational operator      */
  457. typedef short                           relop;
  458. enum {
  459.     GREATERTHAN                 = 0,
  460.     LESSTHAN                    = 1,
  461.     EQUALTO                     = 2,
  462.     UNORDERED                   = 3
  463. };
  464. #if !defined(__MWERKS__) || !defined(__cmath__)
  465. EXTERN_API_C( relop ) relation(double_t x, double_t y);
  466. #endif /* !defined(__MWERKS__) || !defined(__cmath__) */
  467. /********************************************************************************
  468. *                                                                               *
  469. *                         Binary to decimal conversions                         *
  470. *                                                                               *
  471. *   SIGDIGLEN   Significant decimal digits.                                     *
  472. *                                                                               *
  473. *   decimal     A record which provides an intermediate unpacked form for       *
  474. *               programmers who wish to do their own parsing of numeric input   *
  475. *               or formatting of numeric output.                                *
  476. *                                                                               *
  477. *   decform     Controls each conversion to a decimal string.  The style field  *
  478. *               is either FLOATDECIMAL or FIXEDDECIMAL. If FLOATDECIMAL, the    *
  479. *               value of the field digits is the number of significant digits.  *
  480. *               If FIXEDDECIMAL value of the field digits is the number of      *
  481. *               digits to the right of the decimal point.                       *
  482. *                                                                               *
  483. *   num2dec     Converts a double_t to a decimal record using a decform.        *
  484. *   dec2num     Converts a decimal record d to a double_t value.                *
  485. *   dec2str     Converts a decform and decimal to a string using a decform.     *
  486. *   str2dec     Converts a string to a decimal struct.                          *
  487. *   dec2d       Similar to dec2num except a double is returned (68k only).      *
  488. *   dec2f       Similar to dec2num except a float is returned.                  *
  489. *   dec2s       Similar to dec2num except a short is returned.                  *
  490. *   dec2l       Similar to dec2num except a long is returned.                   *
  491. *                                                                               *
  492. ********************************************************************************/
  493. #if TARGET_CPU_PPC
  494.     #define SIGDIGLEN      36  
  495. #elif TARGET_CPU_68K
  496.     #define SIGDIGLEN      20
  497. #elif TARGET_CPU_X86
  498.     #define SIGDIGLEN      20
  499. #endif
  500. #define      DECSTROUTLEN   80               /* max length for dec2str output */
  501. #define      FLOATDECIMAL   ((char)(0))
  502. #define      FIXEDDECIMAL   ((char)(1))
  503. struct decimal {
  504.     char                            sgn;                        /* sign 0 for +, 1 for - */
  505.     char                            unused;
  506.     short                           exp;                        /* decimal exponent */
  507.     struct {
  508.         unsigned char                   length;
  509.         unsigned char                   text[SIGDIGLEN];        /* significant digits */
  510.         unsigned char                   unused;
  511.     }                               sig;
  512. };
  513. typedef struct decimal decimal;
  514. struct decform {
  515.     char                            style;                      /*  FLOATDECIMAL or FIXEDDECIMAL */
  516.     char                            unused;
  517.     short                           digits;
  518. };
  519. typedef struct decform decform;
  520. EXTERN_API_C( void ) num2dec(const decform *f, double_t x, decimal *d);
  521. EXTERN_API_C( double_t ) dec2num(const decimal *d);
  522. EXTERN_API_C( void ) dec2str(const decform *f, const decimal *d, char *s);
  523. EXTERN_API_C( void ) str2dec(const char *s, short *ix, decimal *d, short *vp);
  524. #if TARGET_CPU_68K
  525. #if CALL_NOT_IN_CARBON
  526. EXTERN_API_C( double ) dec2d(const decimal *d);
  527. #endif  /* CALL_NOT_IN_CARBON */
  528. #endif  /* TARGET_CPU_68K */
  529. EXTERN_API_C( float ) dec2f(const decimal *d);
  530. EXTERN_API_C( short ) dec2s(const decimal *d);
  531. EXTERN_API_C( long ) dec2l(const decimal *d);
  532. /********************************************************************************
  533. *                                                                               *
  534. *                         68k-only Transfer Function Prototypes                 *
  535. *                                                                               *
  536. ********************************************************************************/
  537. #if TARGET_CPU_68K
  538. #if CALL_NOT_IN_CARBON
  539. EXTERN_API_C( void ) x96tox80(const extended96 *x, extended80 *x80);
  540. EXTERN_API_C( void ) x80tox96(const extended80 *x80, extended96 *x);
  541. #endif  /* CALL_NOT_IN_CARBON */
  542. #endif  /* TARGET_CPU_68K */
  543. #endif  /* !defined(__NOEXTENSIONS__) */
  544. /********************************************************************************
  545. *                                                                               *
  546. *                         PowerPC-only Function Prototypes                      *
  547. *                                                                               *
  548. ********************************************************************************/
  549. #if TARGET_CPU_PPC
  550. #if !TARGET_RT_MAC_MACHO
  551. #ifndef __MWERKS__  /* Metrowerks does not support double double */
  552. EXTERN_API_C( long double ) cosl(long double x);
  553. EXTERN_API_C( long double ) sinl(long double x);
  554. EXTERN_API_C( long double ) tanl(long double x);
  555. EXTERN_API_C( long double ) acosl(long double x);
  556. EXTERN_API_C( long double ) asinl(long double x);
  557. EXTERN_API_C( long double ) atanl(long double x);
  558. EXTERN_API_C( long double ) atan2l(long double y, long double x);
  559. EXTERN_API_C( long double ) coshl(long double x);
  560. EXTERN_API_C( long double ) sinhl(long double x);
  561. EXTERN_API_C( long double ) tanhl(long double x);
  562. EXTERN_API_C( long double ) acoshl(long double x);
  563. EXTERN_API_C( long double ) asinhl(long double x);
  564. EXTERN_API_C( long double ) atanhl(long double x);
  565. EXTERN_API_C( long double ) expl(long double x);
  566. EXTERN_API_C( long double ) expm1l(long double x);
  567. EXTERN_API_C( long double ) exp2l(long double x);
  568. EXTERN_API_C( long double ) frexpl(long double x, int *exponent);
  569. EXTERN_API_C( long double ) ldexpl(long double x, int n);
  570. EXTERN_API_C( long double ) logl(long double x);
  571. EXTERN_API_C( long double ) log1pl(long double x);
  572. EXTERN_API_C( long double ) log10l(long double x);
  573. EXTERN_API_C( long double ) log2l(long double x);
  574. EXTERN_API_C( long double ) logbl(long double x);
  575. EXTERN_API_C( long double ) scalbl(long double x, long n);
  576. EXTERN_API_C( long double ) fabsl(long double x);
  577. EXTERN_API_C( long double ) hypotl(long double x, long double y);
  578. EXTERN_API_C( long double ) powl(long double x, long double y);
  579. EXTERN_API_C( long double ) sqrtl(long double x);
  580. EXTERN_API_C( long double ) erfl(long double x);
  581. EXTERN_API_C( long double ) erfcl(long double x);
  582. EXTERN_API_C( long double ) gammal(long double x);
  583. EXTERN_API_C( long double ) lgammal(long double x);
  584. EXTERN_API_C( long double ) ceill(long double x);
  585. EXTERN_API_C( long double ) floorl(long double x);
  586. EXTERN_API_C( long double ) rintl(long double x);
  587. EXTERN_API_C( long double ) nearbyintl(long double x);
  588. EXTERN_API_C( long ) rinttoll(long double x);
  589. EXTERN_API_C( long double ) roundl(long double x);
  590. EXTERN_API_C( long ) roundtoll(long double round);
  591. EXTERN_API_C( long double ) truncl(long double x);
  592. EXTERN_API_C( long double ) remainderl(long double x, long double y);
  593. EXTERN_API_C( long double ) remquol(long double x, long double y, int *quo);
  594. EXTERN_API_C( long double ) copysignl(long double x, long double y);
  595. EXTERN_API_C( long double ) fdiml(long double x, long double y);
  596. EXTERN_API_C( long double ) fmaxl(long double x, long double y);
  597. EXTERN_API_C( long double ) fminl(long double x, long double y);
  598. #endif /* __MWERKS__ */
  599. #else
  600. #define cosl(x)          ((long double) cos((double_t)(x)))
  601. #define sinl(x)          ((long double) sin((double_t)(x)))
  602. #define tanl(x)          ((long double) tan((double_t)(x)))
  603. #define acosl(x)         ((long double) acos((double_t)(x)))
  604. #define asinl(x)         ((long double) asin((double_t)(x)))
  605. #define atanl(x)         ((long double) atan((double_t)(x)))
  606. #define atan2l(y,x)      ((long double) atan2((double_t)(y),(double_t)(x)))
  607. #define coshl(x)         ((long double) cosh((double_t)(x)))
  608. #define sinhl(x)         ((long double) sinh((double_t)(x)))
  609. #define tanhl(x)         ((long double) tanh((double_t)(x)))
  610. #define acoshl(x)        ((long double) acosh((double_t)(x)))
  611. #define asinhl(x)        ((long double) asinh((double_t)(x)))
  612. #define atanhl(x)        ((long double) atanh((double_t)(x)))
  613. #define expl(x)          ((long double) exp((double_t)(x)))
  614. #define expm1l(x)        ((long double) expm1((double_t)(x)))
  615. #define exp2l(x)         ((long double) exp2((double_t)(x)))
  616. #define frexpl(x,exp)    ((long double) frexp((double_t)(x),(exp)))
  617. #define ldexpl(x,n)      ((long double) ldexp((double_t)(x),(n)))
  618. #define logl(x)          ((long double) log((double_t)(x)))
  619. #define log1pl(x)        ((long double) log1p((double_t)(x)))
  620. #define log10l(x)        ((long double) log10((double_t)(x)))
  621. #define log2l(x)         ((long double) log2((double_t)(x)))
  622. #define logbl(x)         ((long double) logb((double_t)(x)))
  623. #define scalbl(x,n)      ((long double) scalb((double_t)(x),(n)))
  624. #define fabsl(x)         ((long double) fabs((double_t)(x)))
  625. #define hypotl(x,y)      ((long double) hypot((double_t)(x),(double_t)(y)))
  626. #define powl(x,y)        ((long double) pow((double_t)(x),(double_t)(y)))
  627. #define sqrtl(x)         ((long double) sqrt((double_t)(x)))
  628. #define erfl(x)          ((long double) erf((double_t)(x)))
  629. #define erfcl(x)         ((long double) erfc((double_t)(x)))
  630. #define gammal(x)        ((long double) gamma((double_t)(x)))
  631. #define lgammal(x)       ((long double) lgamma((double_t)(x)))
  632. #define ceill(x)         ((long double) ceil((double_t)(x)))
  633. #define floorl(x)        ((long double) floor((double_t)(x)))
  634. #define rintl(x)         ((long double) rint((double_t)(x)))
  635. #define nearbyintl(x)    ((long double) nearbyint((double_t)(x)))
  636. #define rinttoll(x)      (rinttol((double_t)(x)))
  637. #define roundl(x)        ((long double) round((double_t)(x)))
  638. #define roundtoll(x)     (roundtol((double_t)(x)))
  639. #define truncl(x)        ((long double) trunc((double_t)(x)))
  640. #define remainderl(x,y)  ((long double) remainder((double_t)(x),(double_t)(y)))
  641. #define remquol(x,y,quo) ((long double) remquo((double_t)(x),(double_t)(y),(quo)))
  642. #define copysignl(x,y)   ((long double) copysign((double_t)(x),(double_t)(y)))
  643. #define fdiml(x,y)       ((long double) fdim((double_t)(x),(double_t)(y)))
  644. #define fmaxl(x,y)       ((long double) fmax((double_t)(x),(double_t)(y)))
  645. #define fminl(x,y)       ((long double) fmin((double_t)(x),(double_t)(y)))
  646. #endif  /* !TARGET_RT_MAC_MACHO */
  647. #ifndef __NOEXTENSIONS__
  648. #if !TARGET_RT_MAC_MACHO
  649. EXTERN_API_C( relop ) relationl(long double x, long double y);
  650. EXTERN_API_C( void ) num2decl(const decform *f, long double x, decimal *d);
  651. EXTERN_API_C( long double ) dec2numl(const decimal *d);
  652. #else
  653.        #define relationl(x,y) (relation((double_t)x,(double_t)y))
  654.      #define num2decl(f,x,d) (num2dec(f,(double_t)x,d))
  655.      #define dec2numl(d) ((long double)dec2num(d))
  656.       
  657. #endif  /* !TARGET_RT_MAC_MACHO */
  658. #endif  /* !defined(__NOEXTENSIONS__) */
  659. #endif  /* TARGET_CPU_PPC */
  660. #endif  /* TARGET_OS_MAC */
  661. #ifndef __NOEXTENSIONS__
  662. #if !TARGET_RT_MAC_MACHO
  663. EXTERN_API_C( void ) x80told(const extended80 *x80, long double *x);
  664. EXTERN_API_C( void ) ldtox80(const long double *x, extended80 *x80);
  665. #else
  666.    #define x80told(x80,ld) (*(ld) = x80tod(x80))
  667.   #define ldtox80(ld,x80) do { double d = (double) *(ld); dtox80(&d, (x80)); } while (0)
  668.  
  669. #endif  /* !TARGET_RT_MAC_MACHO */
  670. /*    
  671.         MathLib v2 has two new transfer functions: x80tod and dtox80.  They can 
  672.         be used to directly transform 68k 80-bit extended data types to double
  673.         and back for PowerPC based machines without using the functions
  674.         x80told or ldtox80.  Double rounding may occur. 
  675.     */
  676. EXTERN_API_C( double ) x80tod(const extended80 *x80);
  677. EXTERN_API_C( void ) dtox80(const double *x, extended80 *x80);
  678. #endif  /* !defined(__NOEXTENSIONS__) */
  679. #if PRAGMA_STRUCT_ALIGN
  680.     #pragma options align=reset
  681. #elif PRAGMA_STRUCT_PACKPUSH
  682.     #pragma pack(pop)
  683. #elif PRAGMA_STRUCT_PACK
  684.     #pragma pack()
  685. #endif
  686. #ifdef PRAGMA_IMPORT_OFF
  687. #pragma import off
  688. #elif PRAGMA_IMPORT
  689. #pragma import reset
  690. #endif
  691. #ifdef __cplusplus
  692. }
  693. #endif
  694. #endif /* __FP__ */