Float.st
branchjv
changeset 18060 3708e12e9aa8
parent 18045 c0c600e0d3b3
parent 15264 82b78761c585
child 18120 e3a375d5f6a8
equal deleted inserted replaced
18059:b882507b9fdf 18060:3708e12e9aa8
   189 
   189 
   190     Floats give you 64 bit floats.
   190     Floats give you 64 bit floats.
   191     In contrast to ShortFloats (32bit) and LongFloats (>=64bit).
   191     In contrast to ShortFloats (32bit) and LongFloats (>=64bit).
   192 
   192 
   193     WARNING:
   193     WARNING:
   194         The layout of Float instances is known by the runtime system and the compiler;
   194 	The layout of Float instances is known by the runtime system and the compiler;
   195         you may not add instance variables here.
   195 	you may not add instance variables here.
   196         Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats,
   196 	Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats,
   197         and does some float-checks by an identity compare with the Float-class.
   197 	and does some float-checks by an identity compare with the Float-class.
   198         (i.e. your subclasses instances may not be recognized as float-like objects,
   198 	(i.e. your subclasses instances may not be recognized as float-like objects,
   199          thus mixed mode arithmetic will always coerce them, effectively slowing things down).
   199 	 thus mixed mode arithmetic will always coerce them, effectively slowing things down).
   200 
   200 
   201     Notice, that Floats are defined as Byte-array to prevent the garbage collector
   201     Notice, that Floats are defined as Byte-array to prevent the garbage collector
   202     from going into the value ... otherwise I needed a special case in many places.
   202     from going into the value ... otherwise I needed a special case in many places.
   203 
   203 
   204     Also notice, that ST/X Floats are what Doubles are in ST-80 - this may change
   204     Also notice, that ST/X Floats are what Doubles are in ST-80 - this may change
   212     (although some memory is wasted when porting from VW).
   212     (although some memory is wasted when porting from VW).
   213     Notice that ST/X provides an alias called Double, and an extra ShortFloat class, which has 4-byte
   213     Notice that ST/X provides an alias called Double, and an extra ShortFloat class, which has 4-byte
   214     instances.
   214     instances.
   215 
   215 
   216     Mixed mode arithmetic:
   216     Mixed mode arithmetic:
   217         float op float       -> float
   217 	float op float       -> float
   218         float op fix         -> float
   218 	float op fix         -> float
   219         float op fraction    -> float
   219 	float op fraction    -> float
   220         float op integer     -> float
   220 	float op integer     -> float
   221         float op shortFloat  -> float
   221 	float op shortFloat  -> float
   222         float op longFloat   -> longFloat
   222 	float op longFloat   -> longFloat
   223         float op complex     -> complex
   223 	float op complex     -> complex
   224 
   224 
   225     Representation:
   225     Representation:
   226             64bit double precision IEE floats
   226 	    64bit double precision IEE floats
   227             53 bit mantissa,
   227 	    53 bit mantissa,
   228             11 bit exponent,
   228 	    11 bit exponent,
   229             15 decimal digits (approx)
   229 	    15 decimal digits (approx)
   230 
   230 
   231     Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
   231     Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
   232 
   232 
   233     [author:]
   233     [author:]
   234         Claus Gittinger
   234 	Claus Gittinger
   235 
   235 
   236     [see also:]
   236     [see also:]
   237         Number
   237 	Number
   238         ShortFloat LongFloat Fraction FixedPoint Integer Complex
   238 	ShortFloat LongFloat Fraction FixedPoint Integer Complex
   239         FloatArray DoubleArray
   239 	FloatArray DoubleArray
   240 "
   240 "
   241 !
   241 !
   242 
   242 
   243 errorHandling
   243 errorHandling
   244 "
   244 "
   340     "creates a double, given the four native float bytes as an integer"
   340     "creates a double, given the four native float bytes as an integer"
   341 
   341 
   342 %{  /* NOCONTEXT */
   342 %{  /* NOCONTEXT */
   343 
   343 
   344     REGISTER union {
   344     REGISTER union {
   345         unsigned int    i;
   345 	unsigned int    i;
   346         float           f;
   346 	float           f;
   347     } r;
   347     } r;
   348 
   348 
   349     r.i = __unsignedLongIntVal( anInteger );
   349     r.i = __unsignedLongIntVal( anInteger );
   350     RETURN( __MKFLOAT((double)(r.f)) );
   350     RETURN( __MKFLOAT((double)(r.f)) );
   351 %}
   351 %}
  2227     double val, rslt;
  2227     double val, rslt;
  2228     OBJ newFloat;
  2228     OBJ newFloat;
  2229 
  2229 
  2230     val = __floatVal(self);
  2230     val = __floatVal(self);
  2231 
  2231 
  2232 # ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */
  2232 # ifdef WIN32 /* don't know (yet) how to suppress the warnBox opened by win32 */
  2233     if (val >= 1.0)
  2233     if (val >= 1.0)
  2234 # endif
  2234 # endif
  2235     {
  2235     {
  2236 	__threadErrno = 0;
  2236 	__threadErrno = 0;
  2237 	rslt = acosh(val);
  2237 	rslt = acosh(val);
  2316     double val, rslt;
  2316     double val, rslt;
  2317     OBJ newFloat;
  2317     OBJ newFloat;
  2318 
  2318 
  2319     val = __floatVal(self);
  2319     val = __floatVal(self);
  2320 
  2320 
  2321 # ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */
  2321 # ifdef WIN32 /* don't know (yet) how to suppress the warnBox opened by win32 */
  2322     if (val >= 1.0)
  2322     if (val >= 1.0)
  2323 # endif
  2323 # endif
  2324     {
  2324     {
  2325 	__threadErrno = 0;
  2325 	__threadErrno = 0;
  2326 	rslt = asinh(val);
  2326 	rslt = asinh(val);
  2440     double val, rslt;
  2440     double val, rslt;
  2441     OBJ newFloat;
  2441     OBJ newFloat;
  2442 
  2442 
  2443     __threadErrno = 0;
  2443     __threadErrno = 0;
  2444     val = __floatVal(self);
  2444     val = __floatVal(self);
  2445 # ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */
  2445 # ifdef WIN32 /* don't know (yet) how to suppress the warnBox opened by win32 */
  2446     if ((val >= -1.0) && (val <= 1.0))
  2446     if ((val >= -1.0) && (val <= 1.0))
  2447 # endif
  2447 # endif
  2448     {
  2448     {
  2449 	rslt = atanh(__floatVal(self));
  2449 	rslt = atanh(__floatVal(self));
  2450 	if (! isnan(rslt))  /* Currently all our systems support isnan() */
  2450 	if (! isnan(rslt))  /* Currently all our systems support isnan() */
       
  2451 #ifdef __osx__
       
  2452 	if (! isinf(rslt))
       
  2453 #endif
  2451 	{
  2454 	{
  2452 	    if (__threadErrno == 0) {
  2455 	    if (__threadErrno == 0) {
  2453 		__qMKFLOAT(newFloat, rslt);
  2456 		__qMKFLOAT(newFloat, rslt);
  2454 		RETURN ( newFloat );
  2457 		RETURN ( newFloat );
  2455 	    }
  2458 	    }
  2899 ! !
  2902 ! !
  2900 
  2903 
  2901 !Float class methodsFor:'documentation'!
  2904 !Float class methodsFor:'documentation'!
  2902 
  2905 
  2903 version
  2906 version
  2904     ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.195 2013-03-31 20:45:44 cg Exp $'
  2907     ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.196 2013-05-21 20:45:30 cg Exp $'
  2905 !
  2908 !
  2906 
  2909 
  2907 version_CVS
  2910 version_CVS
  2908     ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.195 2013-03-31 20:45:44 cg Exp $'
  2911     ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.196 2013-05-21 20:45:30 cg Exp $'
  2909 ! !
  2912 ! !
  2910 
  2913 
  2911 
  2914 
  2912 Float initialize!
  2915 Float initialize!