LongFloat.st
changeset 8980 abee9fcb0385
parent 8913 b9498d27a554
child 8981 7c7b2a14c8b3
equal deleted inserted replaced
8979:869510c58b9c 8980:abee9fcb0385
    27 #ifndef __OPTIMIZE__
    27 #ifndef __OPTIMIZE__
    28 # define __OPTIMIZE__
    28 # define __OPTIMIZE__
    29 #endif
    29 #endif
    30 
    30 
    31 #define __USE_ISOC9X 1
    31 #define __USE_ISOC9X 1
       
    32 #define __USE_ISOC99 1
    32 #include <math.h>
    33 #include <math.h>
    33 
    34 
    34 /*
    35 /*
    35  * on some systems errno is a macro ... check for it here
    36  * on some systems errno is a macro ... check for it here
    36  */
    37  */
    61  * no finite(x) ?
    62  * no finite(x) ?
    62  * no isnan(x) ?
    63  * no isnan(x) ?
    63  */
    64  */
    64 # ifndef isnanl
    65 # ifndef isnanl
    65 #  define isnanl(x)      \
    66 #  define isnanl(x)      \
    66 	((((unsigned int *)(&x))[0] == 0x00000000) && \
    67         ((((unsigned int *)(&x))[0] == 0x00000000) && \
    67 	 (((unsigned int *)(&x))[1] == 0xC0000000) && \
    68          (((unsigned int *)(&x))[1] == 0xC0000000) && \
    68 	 (((unsigned short *)(&x))[4] == 0xFFFF))
    69          (((unsigned short *)(&x))[4] == 0xFFFF))
    69 # endif
    70 # endif
    70 
    71 
    71 # ifndef isnan
    72 # ifndef isnan
    72 #  define isnan(x)      \
    73 #  define isnan(x)      \
    73 	((((unsigned int *)(&x))[0] == 0x00000000) && \
    74         ((((unsigned int *)(&x))[0] == 0x00000000) && \
    74 	 (((unsigned int *)(&x))[1] == 0xFFF80000))
    75          (((unsigned int *)(&x))[1] == 0xFFF80000))
    75 # endif
    76 # endif
    76 
    77 
    77 # ifndef isPositiveInfinity
    78 # ifndef isPositiveInfinity
    78 #  define isPositiveInfinity(x) \
    79 #  define isPositiveInfinity(x) \
    79 	((((unsigned int *)(&x))[0] == 0x00000000) && \
    80         ((((unsigned int *)(&x))[0] == 0x00000000) && \
    80 	 (((unsigned int *)(&x))[1] == 0x7FF00000))
    81          (((unsigned int *)(&x))[1] == 0x7FF00000))
    81 # endif
    82 # endif
    82 
    83 
    83 # ifndef isNegativeInfinity
    84 # ifndef isNegativeInfinity
    84 #  define isPositiveInfinity(x) \
    85 #  define isPositiveInfinity(x) \
    85 	((((unsigned int *)(&x))[0] == 0x00000000) && \
    86         ((((unsigned int *)(&x))[0] == 0x00000000) && \
    86 	 (((unsigned int *)(&x))[1] == 0xFFF00000))
    87          (((unsigned int *)(&x))[1] == 0xFFF00000))
    87 # endif
    88 # endif
    88 
    89 
    89 # ifndef isinf
    90 # ifndef isinf
    90 #  define isinf(x) \
    91 #  define isinf(x) \
    91 	((((unsigned int *)(&x))[0] == 0x00000000) && \
    92         ((((unsigned int *)(&x))[0] == 0x00000000) && \
    92 	 ((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000))
    93          ((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000))
    93 # endif
    94 # endif
    94 
    95 
    95 # ifndef finite
    96 # ifndef finite
    96 #  define finite(x) (!isinf(x) && !isnan(x))
    97 #  define finite(x) (!isinf(x) && !isnan(x))
    97 # endif
    98 # endif
   100 # define NO_ACOSH
   101 # define NO_ACOSH
   101 # define NO_ATANH
   102 # define NO_ATANH
   102 #endif /* WIN32 */
   103 #endif /* WIN32 */
   103 
   104 
   104 #ifdef realIX
   105 #ifdef realIX
   105 /*
   106 # ifndef isfinite
   106  * no finite(x)
   107 #  define isfinite(x)     1
   107  */
       
   108 # ifndef finite
       
   109 #  define finite(x)     1
       
   110 # endif
   108 # endif
   111 #endif /* realIX */
   109 #endif /* realIX */
   112 
       
   113 #ifdef OSX
       
   114 # ifndef isnanl
       
   115 #  define isnanl(x)	isnan(x)
       
   116 # endif
       
   117 #endif /* OSX */
       
   118 
   110 
   119 #if defined(__GNUC__) || defined(WIN32)
   111 #if defined(__GNUC__) || defined(WIN32)
   120 # define LONGFLOAT      long double
   112 # define LONGFLOAT      long double
   121 
   113 
   122 # if defined(linux) || defined(WIN32)
   114 # if defined(linux) || defined(WIN32)
   166 # define LONGFLOAT_CLASS LongFloat
   158 # define LONGFLOAT_CLASS LongFloat
   167 # define LONGFLOAT_GLOBAL @global(LongFloat)
   159 # define LONGFLOAT_GLOBAL @global(LongFloat)
   168 #endif
   160 #endif
   169 
   161 
   170 struct __longfloatstruct {
   162 struct __longfloatstruct {
   171 	HEADER
   163         HEADER
   172 #ifdef __NEED_DOUBLE_ALIGN
   164 #ifdef __NEED_DOUBLE_ALIGN
   173 	__FILLTYPE_DOUBLE       f_filler;
   165         __FILLTYPE_DOUBLE       f_filler;
   174 #endif
   166 #endif
   175 	LONGFLOAT               f_longfloatvalue;
   167         LONGFLOAT               f_longfloatvalue;
   176 };
   168 };
   177 #define __LongFloatInstPtr(obj)      ((struct __longfloatstruct *)(__objPtr(obj)))
   169 #define __LongFloatInstPtr(obj)      ((struct __longfloatstruct *)(__objPtr(obj)))
   178 
   170 
   179 #ifndef __longFloatVal
   171 #ifndef __longFloatVal
   180 # define __longFloatVal(o) \
   172 # define __longFloatVal(o) \
   181 	__LongFloatInstPtr(o)->f_longfloatvalue
   173         __LongFloatInstPtr(o)->f_longfloatvalue
   182 #endif
   174 #endif
   183 
   175 
   184 #ifndef __qMKLFLOAT
   176 #ifndef __qMKLFLOAT
   185 # define __qMKLFLOAT(__newFloat__, __fVal__) \
   177 # define __qMKLFLOAT(__newFloat__, __fVal__) \
   186     { \
   178     { \
   187 	__qNew(__newFloat__ , sizeof(struct __longfloatstruct)); \
   179         __qNew(__newFloat__ , sizeof(struct __longfloatstruct)); \
   188 	if (__newFloat__) { \
   180         if (__newFloat__) { \
   189 	    __qClass(__newFloat__) = LONGFLOAT_GLOBAL; \
   181             __qClass(__newFloat__) = LONGFLOAT_GLOBAL; \
   190 	    __LongFloatInstPtr(__newFloat__)->f_longfloatvalue = (LONGFLOAT)(__fVal__); \
   182             __LongFloatInstPtr(__newFloat__)->f_longfloatvalue = (LONGFLOAT)(__fVal__); \
   191 	} \
   183         } \
   192     }
   184     }
   193 #endif
   185 #endif
   194 
   186 
   195 #ifndef __isLongFloat
   187 #ifndef __isLongFloat
   196 # define __isLongFloat(o) \
   188 # define __isLongFloat(o) \
   197 	(__Class(o) == @global(LongFloat))
   189         (__Class(o) == @global(LongFloat))
   198 #endif
   190 #endif
   199 
   191 
   200 #ifndef __qIsLongFloat
   192 #ifndef __qIsLongFloat
   201 # define __qIsLongFloat(o) \
   193 # define __qIsLongFloat(o) \
   202 	(__qClass(o) == @global(LongFloat))
   194         (__qClass(o) == @global(LongFloat))
   203 #endif
   195 #endif
   204 
   196 
   205 %}
   197 %}
   206 ! !
   198 ! !
   207 
   199 
   820 
   812 
   821 %{  /* NOCONTEXT */
   813 %{  /* NOCONTEXT */
   822     LONGFLOAT fVal;
   814     LONGFLOAT fVal;
   823 
   815 
   824     fVal = __longFloatVal(self);
   816     fVal = __longFloatVal(self);
   825 #ifdef WIN32
   817     if (!LONG_isnan(fVal) && (fVal >= (LONGFLOAT)_MIN_INT) && (fVal <= (LONGFLOAT)_MAX_INT)) {
   826     if (! isnanl(fVal))    
   818         RETURN ( __mkSmallInteger( (INT)fVal) );
   827 #endif
       
   828     if ((fVal >= (LONGFLOAT)_MIN_INT) && (fVal <= (LONGFLOAT)_MAX_INT)) {
       
   829 	RETURN ( __mkSmallInteger( (INT)fVal) );
       
   830     }
   819     }
   831 %}.
   820 %}.
   832     ^ super asInteger
   821     ^ super asInteger
   833 
   822 
   834     "
   823     "
  1651 
  1640 
  1652 #ifdef LONG_finite
  1641 #ifdef LONG_finite
  1653     LONGFLOAT lV = __longFloatVal(self);
  1642     LONGFLOAT lV = __longFloatVal(self);
  1654 
  1643 
  1655     if (LONG_finite(lV)) {
  1644     if (LONG_finite(lV)) {
  1656 	RETURN (true); 
  1645         RETURN (true); 
  1657     } else {
  1646     } else {
  1658 	RETURN (false); 
  1647         RETURN (false); 
  1659     }
  1648     }
  1660 #else
  1649 #else
  1661     double dV = (double) __longFloatVal(self);
  1650     double dV = (double) __longFloatVal(self);
  1662 
  1651 
  1663     if (finite(dV)) {
  1652     if (isfinite(dV)) {
  1664 	RETURN (true); 
  1653         RETURN (true); 
  1665     } else {
  1654     } else {
  1666 	RETURN (false); 
  1655         RETURN (false); 
  1667     }
  1656     }
  1668 #endif
  1657 #endif
  1669 %}
  1658 %}
  1670 
  1659 
  1671     "
  1660     "
  1672 	1.0 asLongFloat isFinite   
  1661         1.0 asLongFloat isFinite   
  1673 	(0.0 asLongFloat uncheckedDivide: 0.0) isFinite 
  1662         (0.0 asLongFloat uncheckedDivide: 0.0) isFinite 
  1674 	(1.0 asLongFloat uncheckedDivide: 0.0) isFinite 
  1663         (1.0 asLongFloat uncheckedDivide: 0.0) isFinite 
  1675 	(-1.0 asLongFloat uncheckedDivide: 0.0) isFinite 
  1664         (-1.0 asLongFloat uncheckedDivide: 0.0) isFinite 
  1676     "
  1665     "
  1677 !
  1666 !
  1678 
  1667 
  1679 isNaN
  1668 isNaN
  1680     "return true, if the receiver is an invalid float (NaN - not a number).
  1669     "return true, if the receiver is an invalid float (NaN - not a number).
  2482 ! !
  2471 ! !
  2483 
  2472 
  2484 !LongFloat class methodsFor:'documentation'!
  2473 !LongFloat class methodsFor:'documentation'!
  2485 
  2474 
  2486 version
  2475 version
  2487     ^ '$Header: /cvs/stx/stx/libbasic/LongFloat.st,v 1.51 2005-07-08 17:15:01 cg Exp $'
  2476     ^ '$Header: /cvs/stx/stx/libbasic/LongFloat.st,v 1.52 2005-11-09 15:57:36 stefan Exp $'
  2488 ! !
  2477 ! !
  2489 
  2478 
  2490 LongFloat initialize!
  2479 LongFloat initialize!