fpType.c
上传用户:nvosite88
上传日期:2007-01-17
资源大小:4983k
文件大小:3k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* fpType.c - floating point type functions */
  2. /* Copyright 1992-2001 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01h,03oct01,to   use IEEE little endian for ARM
  7. 01g,16may00,pai  Implemented fixes for incorrect mask usage in fpTypeGet
  8.                  (SPR #7515), (SPR #8515), (SPR #20508).
  9. 01f,23jan97,cdp  reverse words in double for ARM.
  10. 01e,19mar95,dvs  removed tron reference - no longer supported.
  11. 01d,01sep93,hdn  added byte order condition for I80X86.
  12. 01c,17aug92,kdl  added dummy pointer declaration to work around tron gcc bug.
  13. 01b,30jul92,kdl  removed unused static variables.
  14. 01a,30jul92,kdl  created.
  15. */
  16. /*
  17. DESCRIPTION
  18. This file contains a routine, fpTypeGet(), which will return the
  19. type of a floating point number, where the type is one of NULL,
  20. NAN, INTEGER, INF, or REAL.
  21. NOMANUAL
  22. */
  23. #include "vxWorks.h"
  24. #include "math.h"
  25. #include "private/mathP.h"
  26. #if (_BYTE_ORDER == _BIG_ENDIAN)
  27. #define LOW 0 /* array indices for mantissa */
  28. #define HIGH 1
  29. #else
  30. #define LOW 1 /* array indices for mantissa */
  31. #define HIGH 0
  32. #endif /* _BYTE_ORDER == _BIG_ENDIAN */
  33. static unsigned map[32] =
  34.     {
  35.     0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
  36.     0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
  37.     0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
  38.     0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
  39.     0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
  40.     0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
  41.     0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
  42.     0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
  43.     };
  44. /*******************************************************************************
  45. *
  46. * fpTypeGet - determine type of fp number
  47. *
  48. * This routine examines a double floating point value and returns
  49. * a code indicating the type (i.e. ZERO, INF, NAN, REAL, INT).
  50. *
  51. * RETURNS: encoded type (value).
  52. * NOMANUAL
  53. */
  54. int fpTypeGet
  55.     (
  56.     double  v,  /* value */
  57.     double * r /* pointer to integral */
  58.     )
  59.     {
  60.     __cv_type cv;
  61.     int   exp;
  62.     BOOL  any;
  63.     cv.p_double = v;
  64.     if (((cv.p_mant[LOW] & 0x7fffffff) == 0) && (cv.p_mant[HIGH] == 0))
  65.         {
  66.         if (r != NULL)
  67.             *r = v;
  68.         return (ZERO);
  69.         }
  70.     exp = ((cv.p_mant[LOW] & 0x7ff00000) >> 20);
  71.     if (exp == 2047)
  72.         {
  73.         if (r != NULL)
  74.             *r = v;
  75.         return (((cv.p_mant[LOW] & 0x000fffff) == 0) && 
  76. (cv.p_mant[HIGH] == 0)) ? INF : NAN;
  77.         }
  78.     if (r == NULL)
  79.         return (REAL);
  80.     exp -= 1023;
  81.     any = FALSE;
  82.     if (exp < 0)
  83.         {
  84.         any = TRUE;
  85.         cv.p_mant[LOW] &= 0x80000000;
  86.         cv.p_mant[HIGH] = 0;
  87.         }
  88.     else if (exp < 20)
  89.         {
  90.         if ((cv.p_mant[HIGH] != 0) || ((cv.p_mant[LOW] & ~(map[20 - exp])) != 0))
  91.             {
  92.             any = TRUE;
  93.             cv.p_mant[HIGH] = 0;
  94.             cv.p_mant[LOW] &= map[20 - exp];
  95.             }
  96.         }
  97.     else if (exp == 20)
  98.         {
  99.         if ((cv.p_mant[HIGH] & ~(0x00000000)) != 0)
  100.             {
  101.             any = TRUE;
  102.             cv.p_mant[HIGH] &= 0x00000000;
  103.             }
  104.         }
  105.     else if (exp < 52)
  106.         {
  107.         if ((cv.p_mant[HIGH] & ~(map [52 - exp])) != 0)
  108.             {
  109.             any = TRUE;
  110.             cv.p_mant[HIGH] &= map [52 - exp];
  111.             }
  112.         }
  113.     *r = cv.p_double;
  114.     return (any ? REAL : INTEGER);
  115.     }