LongFloat.st
changeset 25036 a92213ab83ac
parent 25027 d552e6a21c22
child 25049 1c82be43aa8b
--- a/LongFloat.st	Sun Dec 01 16:12:12 2019 +0100
+++ b/LongFloat.st	Mon Dec 02 10:43:47 2019 +0100
@@ -48,9 +48,7 @@
 # include <locale.h>
 #endif
 
-#if defined (__aix__)
-# include <float.h>
-#endif
+#include <float.h>
 
 #if defined(__irix__) || defined(__solaris__) || defined(__sunos__)
 # include <nan.h>
@@ -220,52 +218,52 @@
     but faster than software emulations.
 
     NOTE:
-        on systems which do not support 'long doubles', LongFloats are (silently)
-        represented as 'doubles'.
+	on systems which do not support 'long doubles', LongFloats are (silently)
+	represented as 'doubles'.
 
     Representation:
-        gcc-x86:
-            80bit extended IEEE floats stored in in 96bits (12bytes);
-            1 bit integer part,
-            64 bit mantissa,
-            16 bit exponent,
-            19 decimal digits (approx.)
-
-        borland-x86 (WIN32):
-            80bit extended IEEE floats stored in in 80bits (10bytes);
-            1 bit integer part,
-            64 bit mantissa,
-            16 bit exponent,
-            19 decimal digits (approx.)
-
-        gcc-x86_64: (WIN64)
-            like gcc-x86
-
-        gcc-sparc:
-            128bit quadruple IEEE floats (16bytes);
-            112 bit mantissa,
-            16 bit exponent,
-            34 decimal digits (approx.)
+	gcc-x86:
+	    80bit extended IEEE floats stored in in 96bits (12bytes);
+	    1 bit integer part,
+	    64 bit mantissa,
+	    16 bit exponent,
+	    19 decimal digits (approx.)
+
+	borland-x86 (WIN32):
+	    80bit extended IEEE floats stored in in 80bits (10bytes);
+	    1 bit integer part,
+	    64 bit mantissa,
+	    16 bit exponent,
+	    19 decimal digits (approx.)
+
+	gcc-x86_64: (WIN64)
+	    like gcc-x86
+
+	gcc-sparc:
+	    128bit quadruple IEEE floats (16bytes);
+	    112 bit mantissa,
+	    16 bit exponent,
+	    34 decimal digits (approx.)
 
     Mixed mode arithmetic:
-        longFloat op longFloat   -> longFloat
-        longFloat op fix         -> longFloat
-        longFloat op fraction    -> longFloat
-        longFloat op integer     -> longFloat
-        longFloat op shortFloat  -> longFloat
-        longFloat op float       -> longFloat
-        longFloat op complex     -> complex
+	longFloat op longFloat   -> longFloat
+	longFloat op fix         -> longFloat
+	longFloat op fraction    -> longFloat
+	longFloat op integer     -> longFloat
+	longFloat op shortFloat  -> longFloat
+	longFloat op float       -> longFloat
+	longFloat op complex     -> complex
 
     Range and precision of storage formats: see LimitedPrecisionReal >> documentation
 
     [author:]
-        Claus Gittinger
+	Claus Gittinger
 
     [see also:]
-        Number
-        Float ShortFloat Fraction FixedPoint Integer Complex
-        FloatArray DoubleArray
-        https://en.wikipedia.org/wiki/Extended_precision
+	Number
+	Float ShortFloat Fraction FixedPoint Integer Complex
+	FloatArray DoubleArray
+	https://en.wikipedia.org/wiki/Extended_precision
 "
 ! !
 
@@ -451,7 +449,7 @@
 
     if (__unsignedLong64IntVal(anInteger, &r.u64))  {
 	OBJ newFloat;
-        LONGFLOAT_t f = (LONGFLOAT_t)r.d;
+	LONGFLOAT_t f = (LONGFLOAT_t)r.d;
 
 	__qMKLFLOAT(newFloat, f);
 	RETURN( newFloat );
@@ -746,7 +744,7 @@
 emin
     "The smallest exponent value allowed by instances of this class."
 
-    ^ -16382 
+    ^ -16382
 
     "
      1.0 asLongFloat fmax  -> 1.189731495357231765E+4932
@@ -781,18 +779,17 @@
     "The largest value allowed by instances of this class."
 
 %{  /* NOCONTEXT */
-#include <float.h>
-#if defined(LDBL_MAX)
+#if defined(LDBL_MAX) && !defined(__BORLANDC__)
     {
-        OBJ newFloat;
-        __qMKLFLOAT(newFloat, LDBL_MAX);
-        RETURN(newFloat);
+	OBJ newFloat;
+	__qMKLFLOAT(newFloat, LDBL_MAX);
+	RETURN(newFloat);
     }
 #endif
 %}.
     ^ super fmax
 
-    "                         
+    "
      1.0 asLongFloat fmax  -> 1.189731495357231765E+4932
     "
 !
@@ -801,12 +798,11 @@
     "The smallest non-zero value allowed by instances of this class."
 
 %{  /* NOCONTEXT */
-#include <float.h>
-#if defined(LDBL_MIN)
+#if defined(LDBL_MIN) && !defined(__BORLANDC__)
     {
-        OBJ newFloat;
-        __qMKLFLOAT(newFloat, LDBL_MIN);
-        RETURN(newFloat);
+	OBJ newFloat;
+	__qMKLFLOAT(newFloat, LDBL_MIN);
+	RETURN(newFloat);
     }
 #endif
 %}.
@@ -830,35 +826,35 @@
 numBitsInExponent
     "answer the number of bits in the exponent
      i386: This is an 80bit longfloat stored in 96 bits (upper 16 bits are unused),
-           where 15 bits are available in the exponent (i bit is ignored):
-        00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
+	   where 15 bits are available in the exponent (i bit is ignored):
+	00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
      x86_64: This is an 80bit longfloat stored in 128 bits (upper 48 bits are unused),
-           where 15 bits are available in the exponent:
-        00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
+	   where 15 bits are available in the exponent:
+	00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
      sparc & others: This is an 128bit longfloat,
-           where 15 bits are available in the exponent:
-        seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm...
+	   where 15 bits are available in the exponent:
+	seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm...
     "
 %{  /* NOCONTEXT */
 #if defined(__x86__) || defined(__x86_64__)
     if (sizeof(LONGFLOAT_t) == 10) {      /* x86 - WIN32: 80bit floats */
-        RETURN (__mkSmallInteger(15));
+	RETURN (__mkSmallInteger(15));
     }
     if (sizeof(LONGFLOAT_t) == 12) {      /* x86 - some unixes: 96bit floats */
-        RETURN (__mkSmallInteger(15));
+	RETURN (__mkSmallInteger(15));
     }
     if (sizeof(LONGFLOAT_t) == 16) {      /* amd64, x86_64 */
-        RETURN (__mkSmallInteger(15));
+	RETURN (__mkSmallInteger(15));
     }
 #else
     if (sizeof(LONGFLOAT_t) == 16) {
-        RETURN (__mkSmallInteger(15));  /* sparc */
+	RETURN (__mkSmallInteger(15));  /* sparc */
     }
 #endif
 %}.
     "systems without longFloat support use doubles instead"
     self basicNew basicSize == Float basicNew basicSize ifTrue:[
-        ^ Float numBitsInExponent
+	^ Float numBitsInExponent
     ].
     self error:'missing definition'  "ifdef missing in above primitive code for this architecture"
 
@@ -875,35 +871,35 @@
      See https://en.wikipedia.org/wiki/Extended_precision.
 
      i386: This is an 80bit longfloat stored in 96 bits (upper 16 bits are unused),
-           where 1 bit is used for the integer part in the mantissa:
-        00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
+	   where 1 bit is used for the integer part in the mantissa:
+	00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
      x86_64: This is an 80bit longfloat stored in 128 bits (upper 48 bits are unused),
-           where 1+63 bits are available in the mantissa:
-        00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
+	   where 1+63 bits are available in the mantissa:
+	00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
      sparc & others: This is an 128bit longfloat,
-           where 112 bits are available in the mantissa:
-        seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm...
+	   where 112 bits are available in the mantissa:
+	seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm...
     "
 %{  /* NOCONTEXT */
 #if defined(__x86__) || defined(__x86_64__)
     if (sizeof(LONGFLOAT_t) == 10) {      /* x86 - WIN32: 80bit floats */
-        RETURN (__mkSmallInteger(1));
+	RETURN (__mkSmallInteger(1));
     }
     if (sizeof(LONGFLOAT_t) == 12) {      /* x86 - some other unixes: 96bit floats*/
-        RETURN (__mkSmallInteger(1));
+	RETURN (__mkSmallInteger(1));
     }
     if (sizeof(LONGFLOAT_t) == 16) {
-        RETURN (__mkSmallInteger(1));   /* amd64, x86_64 */
+	RETURN (__mkSmallInteger(1));   /* amd64, x86_64 */
     }
 #else
     if (sizeof(LONGFLOAT_t) == 16) {
-        RETURN (__mkSmallInteger(0));   /* sparc */
+	RETURN (__mkSmallInteger(0));   /* sparc */
     }
 #endif
 %}.
     "systems without longFloat support use doubles instead"
     self basicNew basicSize == Float basicNew basicSize ifTrue:[
-        ^ Float numBitsInIntegerPart
+	^ Float numBitsInIntegerPart
     ].
     self error:'missing definition'  "ifdef missing in above primitive code for this architecture"
 
@@ -922,35 +918,35 @@
      the hidden bit is not counted here:
 
      i386: This is an 80bit longfloat stored in 96 bits (upper 16 bits are unused),
-           where 1+63 bits are available in the mantissa:
-        00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
+	   where 1+63 bits are available in the mantissa:
+	00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
      x86_64: This is an 80bit longfloat stored in 128 bits (upper 48 bits are unused),
-           where 1+63 bits are available in the mantissa:
-        00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
+	   where 1+63 bits are available in the mantissa:
+	00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
      sparc: This is an 128bit longfloat,
-           where 112 bits are available in the mantissa:
-        seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm...
+	   where 112 bits are available in the mantissa:
+	seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm...
     "
 %{  /* NOCONTEXT */
 #if defined(__x86__) || defined(__x86_64__)
     if (sizeof(LONGFLOAT_t) == 10) {      /* x86 - WIN32: 80bit */
-        RETURN (__mkSmallInteger(64));
+	RETURN (__mkSmallInteger(64));
     }
     if (sizeof(LONGFLOAT_t) == 12) {      /* x86 some unixes: 96bit */
-        RETURN (__mkSmallInteger(64));
+	RETURN (__mkSmallInteger(64));
     }
     if (sizeof(LONGFLOAT_t) == 16) {
-        RETURN (__mkSmallInteger(64));  /* amd64, x86_64 */
+	RETURN (__mkSmallInteger(64));  /* amd64, x86_64 */
     }
 #else
     if (sizeof(LONGFLOAT_t) == 16) {
-        RETURN (__mkSmallInteger(112)); /* sparc */
+	RETURN (__mkSmallInteger(112)); /* sparc */
     }
 #endif
 %}.
     "systems without longFloat support use doubles instead"
     self basicNew basicSize == Float basicNew basicSize ifTrue:[
-        ^ Float numBitsInMantissa
+	^ Float numBitsInMantissa
     ].
     self error:'missing definition'  "ifdef missing in above primitive code for this architecture"
 
@@ -968,7 +964,7 @@
      1.0 asLongFloat eBias             16383
      1.0 asLongFloat emin              -16382
      1.0 asLongFloat emax              16383
-     1.0 asLongFloat fmin              
+     1.0 asLongFloat fmin
      1.0 asLongFloat fmax              1.189731495357231765E+4932
     "
 
@@ -2123,24 +2119,24 @@
     int len;
 
     if (__isStringLike(formatString)) {
-        /*
-         * actually only needed on sparc: since thisContext is
-         * in a global register, which gets destroyed by printf,
-         * manually save it here - very stupid ...
-         */
-        __BEGIN_PROTECT_REGISTERS__
-
-        len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __longFloatVal(self));
-
-        __END_PROTECT_REGISTERS__
-
-        if (len < 0) goto fail;
-        if (len >= sizeof(buffer)) goto fail;
-
-        s = __MKSTRING_L(buffer, len);
-        if (s != nil) {
-            RETURN (s);
-        }
+	/*
+	 * actually only needed on sparc: since thisContext is
+	 * in a global register, which gets destroyed by printf,
+	 * manually save it here - very stupid ...
+	 */
+	__BEGIN_PROTECT_REGISTERS__
+
+	len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __longFloatVal(self));
+
+	__END_PROTECT_REGISTERS__
+
+	if (len < 0) goto fail;
+	if (len >= sizeof(buffer)) goto fail;
+
+	s = __MKSTRING_L(buffer, len);
+	if (s != nil) {
+	    RETURN (s);
+	}
     }
 fail: ;
 #endif /* not __SCHTEAM__ */