--- a/Float.st Sun Nov 24 16:18:23 2019 +0100
+++ b/Float.st Sun Nov 24 16:18:50 2019 +0100
@@ -2,7 +2,7 @@
"
COPYRIGHT (c) 1988 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -16,12 +16,12 @@
"{ NameSpace: Smalltalk }"
LimitedPrecisionReal variableByteSubclass:#Float
- instanceVariableNames:''
- classVariableNames:'DefaultPrintFormat DefaultPrintfFormat E Epsilon Halfpi
- HalfpiNegative Ln10 Ln2 MaxSmallInteger NaN NegativeInfinity Pi
- PositiveInfinity RadiansPerDegree Sqrt2 Twopi'
- poolDictionaries:''
- category:'Magnitude-Numbers'
+ instanceVariableNames:''
+ classVariableNames:'DefaultPrintFormat DefaultPrintfFormat E Epsilon Halfpi
+ HalfpiNegative Ln10 Ln2 MaxSmallInteger NaN NegativeInfinity Pi
+ PositiveInfinity RadiansPerDegree Sqrt2 Twopi'
+ poolDictionaries:''
+ category:'Magnitude-Numbers'
!
!Float primitiveDefinitions!
@@ -127,26 +127,26 @@
*/
# ifndef isnan
# define isnan(x) \
- ((((unsigned int *)(&x))[0] == 0x00000000) && \
- (((unsigned int *)(&x))[1] == 0xFFF80000))
+ ((((unsigned int *)(&x))[0] == 0x00000000) && \
+ (((unsigned int *)(&x))[1] == 0xFFF80000))
# endif
# ifndef isPositiveInfinity
# define isPositiveInfinity(x) \
- ((((unsigned int *)(&x))[0] == 0x00000000) && \
- (((unsigned int *)(&x))[1] == 0x7FF00000))
+ ((((unsigned int *)(&x))[0] == 0x00000000) && \
+ (((unsigned int *)(&x))[1] == 0x7FF00000))
# endif
# ifndef isNegativeInfinity
# define isNegativeInfinity(x) \
- ((((unsigned int *)(&x))[0] == 0x00000000) && \
- (((unsigned int *)(&x))[1] == 0xFFF00000))
+ ((((unsigned int *)(&x))[0] == 0x00000000) && \
+ (((unsigned int *)(&x))[1] == 0xFFF00000))
# endif
# ifndef isinf
# define isinf(x) \
- ((((unsigned int *)(&x))[0] == 0x00000000) && \
- ((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000))
+ ((((unsigned int *)(&x))[0] == 0x00000000) && \
+ ((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000))
# endif
# ifndef isfinite
@@ -193,7 +193,7 @@
copyright
"
COPYRIGHT (c) 1988 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -272,14 +272,14 @@
easily, if there is sufficient customer interest, though.
Try:
- |f1 f2|
-
- f1 := 1.0.
- f2 := 0.0.
- f1 / f2
+ |f1 f2|
+
+ f1 := 1.0.
+ f2 := 0.0.
+ f1 / f2
or:
- 2 arcSin
+ 2 arcSin
"
! !
@@ -320,16 +320,16 @@
int idx = __intVal(startIndex) - 1;
if (__isStringLike(aString) && __isSmallInteger(startIndex)) {
- char *cp = (char *)(__stringVal(aString));
- double atof();
- double val;
- OBJ newFloat;
-
- if ((unsigned)idx < __stringSize(aString)) {
- val = atof(cp + idx);
- __qMKFLOAT(newFloat, val);
- RETURN (newFloat);
- }
+ char *cp = (char *)(__stringVal(aString));
+ double atof();
+ double val;
+ OBJ newFloat;
+
+ if ((unsigned)idx < __stringSize(aString)) {
+ val = atof(cp + idx);
+ __qMKFLOAT(newFloat, val);
+ RETURN (newFloat);
+ }
}
%}.
self primitiveFailed.
@@ -363,17 +363,17 @@
"
Time millisecondsToRun:[
- 1000000 timesRepeat:[
- Float readFrom:'123.45'
- ]
+ 1000000 timesRepeat:[
+ Float readFrom:'123.45'
+ ]
]
"
"
Time millisecondsToRun:[
- 1000000 timesRepeat:[
- Float fastFromString:'123.45' at:1
- ]
+ 1000000 timesRepeat:[
+ Float fastFromString:'123.45' at:1
+ ]
]
"
@@ -387,8 +387,8 @@
%{ /* NOCONTEXT */
#ifndef __SCHTEAM__
REGISTER union {
- unsigned int i;
- float f;
+ unsigned int i;
+ float f;
} r;
r.i = __unsignedLongIntVal( anInteger );
@@ -412,19 +412,19 @@
extern int __unsignedLong64IntVal(OBJ o, __uint64__ *pI);
REGISTER union {
- __uint64__ u64;
- double d;
+ __uint64__ u64;
+ double d;
} r;
if (__unsignedLong64IntVal(anInteger, &r.u64)) {
- RETURN( __MKFLOAT(r.d) );
+ RETURN( __MKFLOAT(r.d) );
}
#endif
%}.
self primitiveFailed.
"
- Float fromIEEE64Bit:((Float pi digitBytesMSB:true) asIntegerMSB:true)
+ Float fromIEEE64Bit:((Float pi digitBytesMSB:true) asIntegerMSB:true)
"
"Modified: / 21-06-2017 / 09:37:47 / cg"
@@ -436,15 +436,15 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (anInteger.isSmallInteger()) {
- return __c__._RETURN( STDouble._new( (double)(anInteger.longValue()) ));
+ return __c__._RETURN( STDouble._new( (double)(anInteger.longValue()) ));
}
#else
OBJ newFloat;
if (__isSmallInteger(anInteger)) {
- double f = (double)__smallIntegerVal(anInteger);
- __qMKFLOAT(newFloat, f); /* OBJECT ALLOCATION */
- RETURN (newFloat);
+ double f = (double)__smallIntegerVal(anInteger);
+ __qMKFLOAT(newFloat, f); /* OBJECT ALLOCATION */
+ RETURN (newFloat);
}
#endif /* not SCHTEAM */
%}.
@@ -475,9 +475,9 @@
%{ /* NOCONTEXT */
#ifndef __SCHTEAM__
REGISTER union {
- unsigned char b[4];
- unsigned int l;
- float f;
+ unsigned char b[4];
+ unsigned int l;
+ float f;
} r;
# ifdef __LSBFIRST__
@@ -492,15 +492,15 @@
r.b[3] = __intVal( b3 );
# endif
if( (r.l & 0xff800000) != 0x80000000 ) {
- if( (r.l & 0x7f800000) > 0x01000000 )
- r.l -= 0x01000000;
- else
- r.l = 0;
-
- RETURN( __MKFLOAT(r.f) );
+ if( (r.l & 0x7f800000) > 0x01000000 )
+ r.l -= 0x01000000;
+ else
+ r.l = 0;
+
+ RETURN( __MKFLOAT(r.f) );
} else {
- // add code to handle NaN and Inf
- RETURN( nil );
+ // add code to handle NaN and Inf
+ RETURN( nil );
}
#endif
%}.
@@ -586,14 +586,14 @@
self isIEEEFormat ifFalse:[self error:'unsupported operation'].
(UninterpretedBytes isBigEndian == msb) ifFalse:[
- "swap the bytes"
- 8 to:1 by:-1 do:[:i |
- aFloat basicAt:i put:(aStream next)
- ].
- ^ self
+ "swap the bytes"
+ 8 to:1 by:-1 do:[:i |
+ aFloat basicAt:i put:(aStream next)
+ ].
+ ^ self
].
1 to:8 do:[:i |
- aFloat basicAt:i put:aStream next
+ aFloat basicAt:i put:aStream next
]
"not part of libboss, as this is also used by others (TIFFReader)"
@@ -622,14 +622,14 @@
self isIEEEFormat ifFalse:[self error:'unsupported operation'].
(UninterpretedBytes isBigEndian == msb) ifFalse:[
- "swap the bytes"
- 8 to:1 by:-1 do:[:i |
- aStream nextPut:(aFloat basicAt:i).
- ].
- ^ self
+ "swap the bytes"
+ 8 to:1 by:-1 do:[:i |
+ aStream nextPut:(aFloat basicAt:i).
+ ].
+ ^ self
].
1 to:8 do:[:i |
- aStream nextPut:(aFloat basicAt:i).
+ aStream nextPut:(aFloat basicAt:i).
].
"not part of libboss, as this is also used by others (TIFFReader)"
@@ -641,19 +641,19 @@
initialize
Pi isNil ifTrue:[
- DefaultPrintFormat := '.15'. "/ print 15 valid digits
- DefaultPrintfFormat := '%15f'.
-
- Pi := 3.14159265358979323846264338327950288419716939937510582097494459.
- Halfpi := Pi / 2.0.
- HalfpiNegative := Halfpi negated.
- Twopi := Pi * 2.0.
- E := 2.7182818284590452353602874713526625.
- Sqrt2 := 1.41421356237309504880168872420969808.
- RadiansPerDegree := Pi / 180.0.
- Ln2 := 0.69314718055994530941723212145817657.
- Ln10 := 10.0 ln.
- MaxSmallInteger := super maxSmallInteger.
+ DefaultPrintFormat := '.15'. "/ print 15 valid digits
+ DefaultPrintfFormat := '%15f'.
+
+ Pi := 3.14159265358979323846264338327950288419716939937510582097494459.
+ Halfpi := Pi / 2.0.
+ HalfpiNegative := Halfpi negated.
+ Twopi := Pi * 2.0.
+ E := 2.7182818284590452353602874713526625.
+ Sqrt2 := 1.41421356237309504880168872420969808.
+ RadiansPerDegree := Pi / 180.0.
+ Ln2 := 0.69314718055994530941723212145817657.
+ Ln10 := 10.0 ln.
+ MaxSmallInteger := super maxSmallInteger.
].
"
@@ -689,15 +689,15 @@
%{
#if defined(LINUX) && defined(__i386__)
# ifdef NAN
- @global(Float:NaN) = __MKFLOAT(NAN);
+ @global(Float:NaN) = __MKFLOAT(NAN);
# else
- @global(Float:NaN) = __MKFLOAT(_SNAN);
+ @global(Float:NaN) = __MKFLOAT(_SNAN);
# endif
#endif
%}.
- NaN isNil ifTrue:[
- NaN := super NaN.
- ].
+ NaN isNil ifTrue:[
+ NaN := super NaN.
+ ].
].
^ NaN
@@ -724,18 +724,6 @@
^ 2.7182818284590452353602874713526625
!
-emax
- "Answer the maximum exponent for this representation."
-
- ^1023
-!
-
-emin
- "Answer the minimum exponent for this representation."
-
- ^ -1022
-!
-
halfpi
"return the constant pi/2 as Float"
@@ -917,6 +905,25 @@
!Float class methodsFor:'queries'!
+eBias
+ "Answer the exponent's bias;
+ that is the offset of the zero exponent when stored"
+
+ ^ 1023
+!
+
+emax
+ "Answer the maximum exponent for this representation."
+
+ ^1023
+!
+
+emin
+ "Answer the minimum exponent for this representation."
+
+ ^ -1022
+!
+
epsilon
"return the maximum relative spacing of instances of mySelf
(i.e. the value-delta of the least significant bit).
@@ -958,7 +965,7 @@
numBitsInExponent
"answer the number of bits in the exponent
This is an IEEE float, where 11 bits are available:
- seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
+ seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
"
^ 11
@@ -973,7 +980,7 @@
numBitsInMantissa
"answer the number of bits in the mantissa.
This is an IEEE double, where 52 bits (the hidden one is not counted here) are available:
- seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
+ seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
"
^ 52
@@ -1012,7 +1019,7 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (aNumber.isNumber()) {
- return context._RETURN( self.times(aNumber) );
+ return context._RETURN( self.times(aNumber) );
}
#else
@@ -1029,23 +1036,23 @@
double result;
if (__isSmallInteger(aNumber)) {
- result = __floatVal(self) * (double)(__intVal(aNumber));
+ result = __floatVal(self) * (double)(__intVal(aNumber));
retResult:
- __qMKFLOAT(newFloat, result);
- RETURN ( newFloat );
+ __qMKFLOAT(newFloat, result);
+ RETURN ( newFloat );
}
/* knowing that aNumber is not a SmallInt, we only need to check for nil;
* then can use qIsXXX macros which saves us some checks
*/
if (aNumber != nil) {
- if (__qIsFloatLike(aNumber)) {
- result = __floatVal(self) * __floatVal(aNumber);
- goto retResult;
- }
- if (__qIsShortFloat(aNumber)) {
- result = __floatVal(self) * (double)(__shortFloatVal(aNumber));
- goto retResult;
- }
+ if (__qIsFloatLike(aNumber)) {
+ result = __floatVal(self) * __floatVal(aNumber);
+ goto retResult;
+ }
+ if (__qIsShortFloat(aNumber)) {
+ result = __floatVal(self) * (double)(__shortFloatVal(aNumber));
+ goto retResult;
+ }
}
#endif
%}.
@@ -1058,7 +1065,7 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (aNumber.isNumber()) {
- return context._RETURN( self.plus(aNumber) );
+ return context._RETURN( self.plus(aNumber) );
}
#else
/*
@@ -1074,23 +1081,23 @@
double result;
if (__isSmallInteger(aNumber)) {
- result = __floatVal(self) + (double)(__intVal(aNumber));
+ result = __floatVal(self) + (double)(__intVal(aNumber));
retResult:
- __qMKFLOAT(newFloat, result);
- RETURN ( newFloat );
+ __qMKFLOAT(newFloat, result);
+ RETURN ( newFloat );
}
/* knowing that aNumber is not a SmallInt, we only need to check for nil;
* then can use qIsXXX macros which saves us some checks
*/
if (aNumber != nil) {
- if (__qIsFloatLike(aNumber)) {
- result = __floatVal(self) + __floatVal(aNumber);
- goto retResult;
- }
- if (__qIsShortFloat(aNumber)) {
- result = __floatVal(self) + (double)(__shortFloatVal(aNumber));
- goto retResult;
- }
+ if (__qIsFloatLike(aNumber)) {
+ result = __floatVal(self) + __floatVal(aNumber);
+ goto retResult;
+ }
+ if (__qIsShortFloat(aNumber)) {
+ result = __floatVal(self) + (double)(__shortFloatVal(aNumber));
+ goto retResult;
+ }
}
#endif
%}.
@@ -1103,7 +1110,7 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (aNumber.isNumber()) {
- return context._RETURN( self.minus(aNumber) );
+ return context._RETURN( self.minus(aNumber) );
}
#else
@@ -1120,23 +1127,23 @@
double result;
if (__isSmallInteger(aNumber)) {
- result = __floatVal(self) - (double)(__intVal(aNumber));
+ result = __floatVal(self) - (double)(__intVal(aNumber));
retResult:
- __qMKFLOAT(newFloat, result);
- RETURN ( newFloat );
+ __qMKFLOAT(newFloat, result);
+ RETURN ( newFloat );
}
/* knowing that aNumber is not a SmallInt, we only need to check for nil;
* then can use qIsXXX macros which saves us some checks
*/
if (aNumber != nil) {
- if (__qIsFloatLike(aNumber)) {
- result = __floatVal(self) - __floatVal(aNumber);
- goto retResult;
- }
- if (__qIsShortFloat(aNumber)) {
- result = __floatVal(self) - (double)(__shortFloatVal(aNumber));
- goto retResult;
- }
+ if (__qIsFloatLike(aNumber)) {
+ result = __floatVal(self) - __floatVal(aNumber);
+ goto retResult;
+ }
+ if (__qIsShortFloat(aNumber)) {
+ result = __floatVal(self) - (double)(__shortFloatVal(aNumber));
+ goto retResult;
+ }
}
#endif
%}.
@@ -1149,7 +1156,7 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (aNumber.isNumber()) {
- return context._RETURN( self.quotient(aNumber) );
+ return context._RETURN( self.quotient(aNumber) );
}
#else
@@ -1166,32 +1173,32 @@
double result, val;
if (__isSmallInteger(aNumber)) {
- if (aNumber != __mkSmallInteger(0)) {
- result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
+ if (aNumber != __mkSmallInteger(0)) {
+ result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
retResult:
- __qMKFLOAT(newFloat, result);
- RETURN ( newFloat );
- }
+ __qMKFLOAT(newFloat, result);
+ RETURN ( newFloat );
+ }
} else if (__isFloatLike(aNumber)) {
- val = __floatVal(aNumber);
- if (val != 0.0) {
- result = __floatVal(self) / val;
- goto retResult;
- }
+ val = __floatVal(aNumber);
+ if (val != 0.0) {
+ result = __floatVal(self) / val;
+ goto retResult;
+ }
} else if (__isShortFloat(aNumber)) {
- val = (double)(__shortFloatVal(aNumber));
- if (val != 0.0) {
- result = __floatVal(self) / val;
- goto retResult;
- }
+ val = (double)(__shortFloatVal(aNumber));
+ if (val != 0.0) {
+ result = __floatVal(self) / val;
+ goto retResult;
+ }
}
#endif
%}.
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
- "
- No, you shalt not divide by zero
- "
- ^ ZeroDivide raiseRequestWith:thisContext.
+ "
+ No, you shalt not divide by zero
+ "
+ ^ ZeroDivide raiseRequestWith:thisContext.
].
^ aNumber quotientFromFloat:self
!
@@ -1209,8 +1216,8 @@
double val =__floatVal(self);
if (val < 0.0) {
- __qMKFLOAT(newFloat, -val);
- RETURN ( newFloat );
+ __qMKFLOAT(newFloat, -val);
+ RETURN ( newFloat );
}
RETURN (self);
#endif
@@ -1256,43 +1263,43 @@
double result, val;
if (__isSmallInteger(aNumber)) {
- if (aNumber != __mkSmallInteger(0)) {
- val = (double)__intVal(aNumber);
+ if (aNumber != __mkSmallInteger(0)) {
+ val = (double)__intVal(aNumber);
computeResult:
- result = fmod(__floatVal(self), val) ;
- __qMKFLOAT(newFloat, result);
- RETURN ( newFloat );
- }
+ result = fmod(__floatVal(self), val) ;
+ __qMKFLOAT(newFloat, result);
+ RETURN ( newFloat );
+ }
} else if (__isFloatLike(aNumber)) {
- val = __floatVal(aNumber);
- if (val != 0.0) {
- goto computeResult;
- }
+ val = __floatVal(aNumber);
+ if (val != 0.0) {
+ goto computeResult;
+ }
} else if (__isShortFloat(aNumber)) {
- val = (double)(__shortFloatVal(aNumber));
- if (val != 0.0) {
- goto computeResult;
- }
+ val = (double)(__shortFloatVal(aNumber));
+ if (val != 0.0) {
+ goto computeResult;
+ }
#ifdef LONGFLOAT_KNOWN_HERE
} else if (__isLongFloat(aNumber)) {
- long double lval;
-
- lval = (long double)(__longFloatVal(aNumber));
- if (val != 0.0) {
- long double lResult;
-
- lResult = fmodl((long double)(__floatVal(self)), lval);
- __qMKLFLOAT(newFloat, lResult);
- RETURN (newFloat);
- }
+ long double lval;
+
+ lval = (long double)(__longFloatVal(aNumber));
+ if (val != 0.0) {
+ long double lResult;
+
+ lResult = fmodl((long double)(__floatVal(self)), lval);
+ __qMKLFLOAT(newFloat, lResult);
+ RETURN (newFloat);
+ }
#endif
}
%}.
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
- "
- No, you shalt not divide by zero
- "
- ^ ZeroDivide raiseRequestWith:thisContext.
+ "
+ No, you shalt not divide by zero
+ "
+ ^ ZeroDivide raiseRequestWith:thisContext.
].
^ aNumber remainderFromFloat:self
!
@@ -1310,20 +1317,20 @@
double result, val;
if (__isSmallInteger(aNumber)) {
- result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
+ result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
retResult:
- __qMKFLOAT(newFloat, result);
- RETURN ( newFloat );
+ __qMKFLOAT(newFloat, result);
+ RETURN ( newFloat );
}
if (__isFloatLike(aNumber)) {
- val = __floatVal(aNumber);
- result = __floatVal(self) / val;
- goto retResult;
+ val = __floatVal(aNumber);
+ result = __floatVal(self) / val;
+ goto retResult;
}
if (__isShortFloat(aNumber)) {
- val = (double)(__shortFloatVal(aNumber));
- result = __floatVal(self) / val;
- goto retResult;
+ val = (double)(__shortFloatVal(aNumber));
+ result = __floatVal(self) / val;
+ goto retResult;
}
%}.
^ aNumber quotientFromFloat:self
@@ -1364,9 +1371,9 @@
if (! isnan(dVal))
#endif
{
- if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
- RETURN ( __mkSmallInteger( (INT)dVal) );
- }
+ if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
+ RETURN ( __mkSmallInteger( (INT)dVal) );
+ }
}
%}.
^ super asInteger
@@ -1537,7 +1544,7 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (aNumber.isNumber()) {
- return context._RETURN( self.ltP(aNumber) );
+ return context._RETURN( self.ltP(aNumber) );
}
#else
/*
@@ -1550,15 +1557,15 @@
* (see the message send at the bottom)
*/
if (__isSmallInteger(aNumber)) {
- RETURN ( (__floatVal(self) < (double)(__intVal(aNumber))) ? true : false );
+ RETURN ( (__floatVal(self) < (double)(__intVal(aNumber))) ? true : false );
}
if (aNumber != nil) {
- if (__qIsFloatLike(aNumber)) {
- RETURN ( (__floatVal(self) < __floatVal(aNumber)) ? true : false );
- }
- if (__qIsShortFloat(aNumber)) {
- RETURN ( (__floatVal(self) < (double)(__shortFloatVal(aNumber))) ? true : false );
- }
+ if (__qIsFloatLike(aNumber)) {
+ RETURN ( (__floatVal(self) < __floatVal(aNumber)) ? true : false );
+ }
+ if (__qIsShortFloat(aNumber)) {
+ RETURN ( (__floatVal(self) < (double)(__shortFloatVal(aNumber))) ? true : false );
+ }
}
#endif
%}.
@@ -1571,7 +1578,7 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (aNumber.isNumber()) {
- return context._RETURN( self.leP(aNumber) );
+ return context._RETURN( self.leP(aNumber) );
}
#else
/*
@@ -1584,15 +1591,15 @@
* (see the message send at the bottom)
*/
if (__isSmallInteger(aNumber)) {
- RETURN ( (__floatVal(self) <= (double)(__intVal(aNumber))) ? true : false );
+ RETURN ( (__floatVal(self) <= (double)(__intVal(aNumber))) ? true : false );
}
if (aNumber != nil) {
- if (__qIsFloatLike(aNumber)) {
- RETURN ( (__floatVal(self) <= __floatVal(aNumber)) ? true : false );
- }
- if (__qIsShortFloat(aNumber)) {
- RETURN ( (__floatVal(self) <= (double)(__shortFloatVal(aNumber))) ? true : false );
- }
+ if (__qIsFloatLike(aNumber)) {
+ RETURN ( (__floatVal(self) <= __floatVal(aNumber)) ? true : false );
+ }
+ if (__qIsShortFloat(aNumber)) {
+ RETURN ( (__floatVal(self) <= (double)(__shortFloatVal(aNumber))) ? true : false );
+ }
}
#endif
%}.
@@ -1606,7 +1613,7 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (aNumber.isNumber()) {
- return context._RETURN( self.eqNrP(aNumber) );
+ return context._RETURN( self.eqNrP(aNumber) );
}
#else
@@ -1620,17 +1627,17 @@
* (see the message send at the bottom)
*/
if (__isSmallInteger(aNumber)) {
- RETURN ( (__floatVal(self) == (double)(__intVal(aNumber))) ? true : false );
+ RETURN ( (__floatVal(self) == (double)(__intVal(aNumber))) ? true : false );
}
if (aNumber != nil) {
- if (__qIsFloatLike(aNumber)) {
- RETURN ( (__floatVal(self) == __floatVal(aNumber)) ? true : false );
- }
- if (__qIsShortFloat(aNumber)) {
- RETURN ( (__floatVal(self) == (double)(__shortFloatVal(aNumber))) ? true : false );
- }
+ if (__qIsFloatLike(aNumber)) {
+ RETURN ( (__floatVal(self) == __floatVal(aNumber)) ? true : false );
+ }
+ if (__qIsShortFloat(aNumber)) {
+ RETURN ( (__floatVal(self) == (double)(__shortFloatVal(aNumber))) ? true : false );
+ }
} else {
- RETURN (false);
+ RETURN (false);
}
#endif
%}.
@@ -1643,7 +1650,7 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (aNumber.isNumber()) {
- return context._RETURN( self.gtP(aNumber) );
+ return context._RETURN( self.gtP(aNumber) );
}
#else
/*
@@ -1656,15 +1663,15 @@
* (see the message send at the bottom)
*/
if (__isSmallInteger(aNumber)) {
- RETURN ( (__floatVal(self) > (double)(__intVal(aNumber))) ? true : false );
+ RETURN ( (__floatVal(self) > (double)(__intVal(aNumber))) ? true : false );
}
if (aNumber != nil) {
- if (__qIsFloatLike(aNumber)) {
- RETURN ( (__floatVal(self) > __floatVal(aNumber)) ? true : false );
- }
- if (__qIsShortFloat(aNumber)) {
- RETURN ( (__floatVal(self) > (double)(__shortFloatVal(aNumber))) ? true : false );
- }
+ if (__qIsFloatLike(aNumber)) {
+ RETURN ( (__floatVal(self) > __floatVal(aNumber)) ? true : false );
+ }
+ if (__qIsShortFloat(aNumber)) {
+ RETURN ( (__floatVal(self) > (double)(__shortFloatVal(aNumber))) ? true : false );
+ }
}
#endif
%}.
@@ -1677,7 +1684,7 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (aNumber.isNumber()) {
- return context._RETURN( self.geP(aNumber) );
+ return context._RETURN( self.geP(aNumber) );
}
#else
/*
@@ -1690,15 +1697,15 @@
* (see the message send at the bottom)
*/
if (__isSmallInteger(aNumber)) {
- RETURN ( (__floatVal(self) >= (double)(__intVal(aNumber))) ? true : false );
+ RETURN ( (__floatVal(self) >= (double)(__intVal(aNumber))) ? true : false );
}
if (aNumber != nil) {
- if (__qIsFloatLike(aNumber)) {
- RETURN ( (__floatVal(self) >= __floatVal(aNumber)) ? true : false );
- }
- if (__qIsShortFloat(aNumber)) {
- RETURN ( (__floatVal(self) >= (double)(__shortFloatVal(aNumber))) ? true : false );
- }
+ if (__qIsFloatLike(aNumber)) {
+ RETURN ( (__floatVal(self) >= __floatVal(aNumber)) ? true : false );
+ }
+ if (__qIsShortFloat(aNumber)) {
+ RETURN ( (__floatVal(self) >= (double)(__shortFloatVal(aNumber))) ? true : false );
+ }
}
#endif
%}.
@@ -1713,10 +1720,10 @@
|i|
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[
- i := self asInteger.
- self = i ifTrue:[
- ^ i hash
- ].
+ i := self asInteger.
+ self = i ifTrue:[
+ ^ i hash
+ ].
].
"
@@ -1755,7 +1762,7 @@
"
Epsilon isNil ifTrue:[
- Epsilon := self class computeEpsilon.
+ Epsilon := self class computeEpsilon.
].
%{ /* NOCONTEXT */
@@ -1772,29 +1779,29 @@
INT64 ulpDiff;
union {
- double d;
- INT64 i;
+ double d;
+ INT64 i;
} myself, otherFloat;
int nEpsilon;
double scaledEpsilon;
if (!__isSmallInteger(nE)) {
- goto tryHarder;
+ goto tryHarder;
}
nEpsilon = __intVal(nE);
scaledEpsilon = nEpsilon *__floatVal(@global(Epsilon));
if (__isSmallInteger(aNumber)) {
- otherFloat.d = (double)(__intVal(aNumber));
+ otherFloat.d = (double)(__intVal(aNumber));
} else if (aNumber == nil) {
- RETURN(false)
+ RETURN(false)
} else if (__qIsFloatLike(aNumber)) {
- otherFloat.d = (double)(__floatVal(aNumber));
+ otherFloat.d = (double)(__floatVal(aNumber));
} else if (__qIsShortFloat(aNumber)) {
- otherFloat.d = (double)(__shortFloatVal(aNumber));
+ otherFloat.d = (double)(__shortFloatVal(aNumber));
} else {
- goto tryHarder;
+ goto tryHarder;
}
myself.d = __floatVal(self);
@@ -1802,12 +1809,12 @@
// Check if the numbers are really close -- needed
// when comparing numbers near zero (ULP method below fails for numbers near 0!).
if (fabs(myself.d - otherFloat.d) <= scaledEpsilon) {
- RETURN(true);
+ RETURN(true);
}
// if the signs differ, the numbers are different
if ((myself.d >= 0) != (otherFloat.d >= 0)) {
- RETURN(false);
+ RETURN(false);
}
// compute the difference of the 'units in the last place" ULP
@@ -1815,28 +1822,28 @@
ulpDiff = myself.i - otherFloat.i;
if (ulpDiff < 0) ulpDiff = -ulpDiff;
if (ulpDiff <= nEpsilon) {
- RETURN(true);
+ RETURN(true);
} else {
- RETURN(false)
+ RETURN(false)
}
tryHarder:;
%}.
nE isInteger ifFalse:[
- self error:'nEpsilon argument must be an integer'.
+ self error:'nEpsilon argument must be an integer'.
].
^ aNumber isAlmostEqualToFromFloat:self nEpsilon:nE
"
- 67329.234 isAlmostEqualTo:67329.23400000001 nEpsilon:1
- 1.0 isAlmostEqualTo:1.0001 nEpsilon:1
- 1.0 isAlmostEqualTo:-1.0 nEpsilon:1
- 1 isAlmostEqualTo:1.000000000000001 nEpsilon:1
- 1 isAlmostEqualTo:1.000000000000001 nEpsilon:10
- 1.0 isAlmostEqualTo:1 nEpsilon:1
- 1.0 isAlmostEqualTo:1 asFraction nEpsilon:1
- 0.0 isAlmostEqualTo:0 nEpsilon:1
- 0.0 isAlmostEqualTo:self epsilon nEpsilon:1
+ 67329.234 isAlmostEqualTo:67329.23400000001 nEpsilon:1
+ 1.0 isAlmostEqualTo:1.0001 nEpsilon:1
+ 1.0 isAlmostEqualTo:-1.0 nEpsilon:1
+ 1 isAlmostEqualTo:1.000000000000001 nEpsilon:1
+ 1 isAlmostEqualTo:1.000000000000001 nEpsilon:10
+ 1.0 isAlmostEqualTo:1 nEpsilon:1
+ 1.0 isAlmostEqualTo:1 asFraction nEpsilon:1
+ 0.0 isAlmostEqualTo:0 nEpsilon:1
+ 0.0 isAlmostEqualTo:self epsilon nEpsilon:1
"
"Modified: / 10-05-2018 / 00:48:57 / stefan"
@@ -1857,17 +1864,17 @@
* (see the message send at the bottom)
*/
if (__isSmallInteger(aNumber)) {
- RETURN ( (__floatVal(self) != (double)(__intVal(aNumber))) ? true : false );
+ RETURN ( (__floatVal(self) != (double)(__intVal(aNumber))) ? true : false );
}
if (aNumber != nil) {
- if (__qIsFloatLike(aNumber)) {
- RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false );
- }
- if (__qIsShortFloat(aNumber)) {
- RETURN ( (__floatVal(self) != (double)(__shortFloatVal(aNumber))) ? true : false );
- }
+ if (__qIsFloatLike(aNumber)) {
+ RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false );
+ }
+ if (__qIsShortFloat(aNumber)) {
+ RETURN ( (__floatVal(self) != (double)(__shortFloatVal(aNumber))) ? true : false );
+ }
} else {
- RETURN ( true );
+ RETURN ( true );
}
%}.
^ super ~= aNumber
@@ -1952,18 +1959,18 @@
rslt = exp(__floatVal(self));
if (! isnan(rslt)) /* Currently all our systems support isnan() */
{
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
}
%}.
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#exp
- arguments:#()
- errorString:'bad receiver in exp'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#exp
+ arguments:#()
+ errorString:'bad receiver in exp'
"Modified: / 16.11.2001 / 14:14:29 / cg"
!
@@ -2028,15 +2035,15 @@
* to avoid returning -INF from some unix math libs (__osx__)
*/
if (val > 0.0) {
- __threadErrno = 0;
- rslt = log(val);
- if (! isnan(rslt)) /* Currently all our systems support isnan() */
- {
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
- }
+ __threadErrno = 0;
+ rslt = log(val);
+ if (! isnan(rslt)) /* Currently all our systems support isnan() */
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
#endif
%}.
@@ -2045,11 +2052,11 @@
if you need -INF for a zero receiver, try Number trapInfinity:[...]
"
^ self class
- raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal])
- receiver:self
- selector:#ln
- arguments:#()
- errorString:'bad receiver in ln (not strictly positive)'
+ raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal])
+ receiver:self
+ selector:#ln
+ arguments:#()
+ errorString:'bad receiver in ln (not strictly positive)'
"Modified (comment): / 03-07-2017 / 15:58:17 / cg"
!
@@ -2073,15 +2080,15 @@
* to avoid returning -INF from some unix math libs (__osx__)
*/
if (val > 0.0) {
- __threadErrno = 0;
- rslt = log10(val);
- if (! isnan(rslt)) /* Currently all our systems support isnan() */
- {
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
- }
+ __threadErrno = 0;
+ rslt = log10(val);
+ if (! isnan(rslt)) /* Currently all our systems support isnan() */
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
#endif
%}.
@@ -2090,11 +2097,11 @@
if you need -INF for a zero receiver, try Number trapInfinity:[...]
"
^ self class
- raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal])
- receiver:self
- selector:#log10
- arguments:#()
- errorString:'bad receiver in log10 (not strictly positive)'
+ raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal])
+ receiver:self
+ selector:#log10
+ arguments:#()
+ errorString:'bad receiver in log10 (not strictly positive)'
"Modified (comment): / 03-07-2017 / 15:58:21 / cg"
!
@@ -2107,19 +2114,19 @@
OBJ newFloat;
if (__isFloatLike(aNumber)) {
- _n = __floatVal(aNumber);
+ _n = __floatVal(aNumber);
} else if (__isSmallInteger(aNumber)) {
- _n = (double)__intVal(aNumber);
+ _n = (double)__intVal(aNumber);
} else {
- goto notEasy;
+ goto notEasy;
}
__threadErrno = 0;
rslt = pow(__floatVal(self), _n);
if (! isnan(rslt)) { /* Currently all our systems support isnan() */
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
}
notEasy: ;
%}.
@@ -2128,7 +2135,7 @@
"/ I.e. it raises an error on -8^(1/3) instead of returning a negative -2
"/ work around with a kludge:
self < 0 ifTrue:[
- ^ (self negated raisedTo:aNumber) negated
+ ^ (self negated raisedTo:aNumber) negated
].
^ aNumber raisedFromFloat:self
@@ -2136,6 +2143,14 @@
"Modified: / 01-07-2017 / 21:58:26 / cg"
!
+reciprocalLogBase2
+ "optimized for self = 10, for use in conversion for printing"
+
+ ^ self = 10.0s
+ ifTrue: [Ln2 / Ln10]
+ ifFalse: [Ln2 / self ln]
+!
+
sqrt
"return the square root of myself.
Raises an exception, if the receiver is less than zero."
@@ -2151,23 +2166,23 @@
if (val >= 0.0)
#endif
{
- __threadErrno = 0;
- rslt = sqrt(val);
- if (! isnan(rslt)) /* Currently all our systems support isnan() */
- {
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
- }
+ __threadErrno = 0;
+ rslt = sqrt(val);
+ if (! isnan(rslt)) /* Currently all our systems support isnan() */
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
%}.
^ self class
- raise:#imaginaryResultSignal
- receiver:self
- selector:#sqrt
- arguments:#()
- errorString:'bad (negative) receiver in sqrt'
+ raise:#imaginaryResultSignal
+ receiver:self
+ selector:#sqrt
+ arguments:#()
+ errorString:'bad (negative) receiver in sqrt'
"
10 sqrt
@@ -2200,26 +2215,26 @@
^ self printStringWithFormat:self class defaultPrintFormat
"
- Float pi printString.
- 1.0 printString
- 1.234 printString
- 1e10 printString
- 1e-60 printString
- 1.2e3 printString
- 1.2e30 printString
- (1.0 uncheckedDivide:0) printString
- (0.0 uncheckedDivide:0) printString
- self pi printString.
-
- DecimalPointCharacter := $,.
- 1.234 printString.
- 1.0 printString.
- 1e10 printString.
- 1.2e3 printString.
- 1.2e30 printString.
- (1.0 uncheckedDivide:0) printString.
- (0.0 uncheckedDivide:0) printString.
- DecimalPointCharacter := $.
+ Float pi printString.
+ 1.0 printString
+ 1.234 printString
+ 1e10 printString
+ 1e-60 printString
+ 1.2e3 printString
+ 1.2e30 printString
+ (1.0 uncheckedDivide:0) printString
+ (0.0 uncheckedDivide:0) printString
+ self pi printString.
+
+ DecimalPointCharacter := $,.
+ 1.234 printString.
+ 1.0 printString.
+ 1e10 printString.
+ 1.2e3 printString.
+ 1.2e30 printString.
+ (1.0 uncheckedDivide:0) printString.
+ (0.0 uncheckedDivide:0) printString.
+ DecimalPointCharacter := $.
"
"Modified (comment): / 21-06-2017 / 09:46:01 / cg"
@@ -2242,12 +2257,12 @@
int len;
if (__isStringLike(format)) {
- fmt = (char *) __stringVal(format);
+ fmt = (char *) __stringVal(format);
} else {
- /*
- * in case we get called with garbage ...
- */
- fmt = ".15";
+ /*
+ * in case we get called with garbage ...
+ */
+ fmt = ".15";
}
/*
@@ -2266,33 +2281,33 @@
__END_PROTECT_REGISTERS__
if (len >= 0 && len < sizeof(buffer)-3) {
- /*
- * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
- * (i.e. look if string contains '.' or 'e' and append '.0' if not)
- */
- for (cp = buffer; *cp; cp++) {
- if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break;
- }
- if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
- if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
- *cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
- } else {
- *cp++ = '.';
- }
- *cp++ = '0';
- *cp = '\0';
- } else {
- if (cp && ((*cp == '.') || (*cp == ','))) {
- if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
- *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
- }
- }
- }
-
- s = __MKSTRING(buffer);
- if (s != nil) {
- RETURN (s);
- }
+ /*
+ * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
+ * (i.e. look if string contains '.' or 'e' and append '.0' if not)
+ */
+ for (cp = buffer; *cp; cp++) {
+ if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break;
+ }
+ if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
+ if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
+ *cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
+ } else {
+ *cp++ = '.';
+ }
+ *cp++ = '0';
+ *cp = '\0';
+ } else {
+ if (cp && ((*cp == '.') || (*cp == ','))) {
+ if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
+ *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
+ }
+ }
+ }
+
+ s = __MKSTRING(buffer);
+ if (s != nil) {
+ RETURN (s);
+ }
}
%}.
"
@@ -2305,24 +2320,24 @@
^ AllocationFailure raise.
"
- 1.0 printString
- 1.234 printString
- 1e10 printString
- 1.2e3 printString
- 1.2e30 printString
- (1.0 uncheckedDivide:0) printString
- (0.0 uncheckedDivide:0) printString
- self pi printString.
-
- DecimalPointCharacter := $,.
- 1.234 printString.
- 1.0 printString.
- 1e10 printString.
- 1.2e3 printString.
- 1.2e30 printString.
- (1.0 uncheckedDivide:0) printString.
- (0.0 uncheckedDivide:0) printString.
- DecimalPointCharacter := $.
+ 1.0 printString
+ 1.234 printString
+ 1e10 printString
+ 1.2e3 printString
+ 1.2e30 printString
+ (1.0 uncheckedDivide:0) printString
+ (0.0 uncheckedDivide:0) printString
+ self pi printString.
+
+ DecimalPointCharacter := $,.
+ 1.234 printString.
+ 1.0 printString.
+ 1e10 printString.
+ 1.2e3 printString.
+ 1.2e30 printString.
+ (1.0 uncheckedDivide:0) printString.
+ (0.0 uncheckedDivide:0) printString.
+ DecimalPointCharacter := $.
"
!
@@ -2436,23 +2451,23 @@
__END_PROTECT_REGISTERS__
if (len >= 0 && len < sizeof(buffer)-3) {
- /*
- * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
- * (i.e. look if string contains '.' or 'e' and append '.0' if not)
- */
- for (cp = buffer; *cp; cp++) {
- if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break;
- }
- if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
- *cp++ = '.';
- *cp++ = '0';
- *cp = '\0';
- }
-
- s = __MKSTRING(buffer);
- if (s != nil) {
- RETURN (s);
- }
+ /*
+ * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
+ * (i.e. look if string contains '.' or 'e' and append '.0' if not)
+ */
+ for (cp = buffer; *cp; cp++) {
+ if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break;
+ }
+ if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
+ *cp++ = '.';
+ *cp++ = '0';
+ *cp = '\0';
+ }
+
+ s = __MKSTRING(buffer);
+ if (s != nil) {
+ RETURN (s);
+ }
}
%}.
"
@@ -2465,28 +2480,28 @@
^ AllocationFailure raise.
"
- 1.0 storeString
- 0.1 storeString
- ((Array new:10 withAll:0.1) inject:0 into:[:v :sumSoFar| sumSoFar + v]) storeString
- 1.234 storeString
- 1e10 storeString
- 1.2e3 storeString
- 1.2e30 storeString
- Float pi storeString
- (1.0 uncheckedDivide:0) storeString
- (0.0 uncheckedDivide:0) storeString
+ 1.0 storeString
+ 0.1 storeString
+ ((Array new:10 withAll:0.1) inject:0 into:[:v :sumSoFar| sumSoFar + v]) storeString
+ 1.234 storeString
+ 1e10 storeString
+ 1.2e3 storeString
+ 1.2e30 storeString
+ Float pi storeString
+ (1.0 uncheckedDivide:0) storeString
+ (0.0 uncheckedDivide:0) storeString
notice that the storeString is NOT affected by DecimalPointCharacterForPrinting:
- DecimalPointCharacterForPrinting := $,.
- 1.234 storeString.
- 1.0 storeString.
- 1e10 storeString.
- 1.2e3 storeString.
- 1.2e30 storeString.
- (1.0 uncheckedDivide:0) storeString.
- (0.0 uncheckedDivide:0) storeString.
- DecimalPointCharacterForPrinting := $.
+ DecimalPointCharacterForPrinting := $,.
+ 1.234 storeString.
+ 1.0 storeString.
+ 1e10 storeString.
+ 1.2e3 storeString.
+ 1.2e30 storeString.
+ (1.0 uncheckedDivide:0) storeString.
+ (0.0 uncheckedDivide:0) storeString.
+ DecimalPointCharacterForPrinting := $.
"
! !
@@ -2499,12 +2514,12 @@
Therefore, this method should be used strictly private.
Notice:
- the need to redefine this method here is due to the
- inability of many machines to store floats in non-double aligned memory.
- Therefore, on some machines, the first 4 bytes of a float are left unused,
- and the actual float is stored at index 5 .. 12.
- To hide this at one place, this method knows about that, and returns
- values as if this filler wasnt present."
+ the need to redefine this method here is due to the
+ inability of many machines to store floats in non-double aligned memory.
+ Therefore, on some machines, the first 4 bytes of a float are left unused,
+ and the actual float is stored at index 5 .. 12.
+ To hide this at one place, this method knows about that, and returns
+ values as if this filler wasnt present."
%{ /* NOCONTEXT */
@@ -2517,11 +2532,11 @@
* and SmallInteger
*/
if (__isSmallInteger(index)) {
- indx = __intVal(index) - 1;
- if (((unsigned)(indx)) < sizeof(double)) {
- cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
- RETURN ( __mkSmallInteger(cp[indx] & 0xFF) );
- }
+ indx = __intVal(index) - 1;
+ if (((unsigned)(indx)) < sizeof(double)) {
+ cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
+ RETURN ( __mkSmallInteger(cp[indx] & 0xFF) );
+ }
}
%}.
^ self indexNotIntegerOrOutOfBounds:index
@@ -2533,12 +2548,12 @@
Therefore, this method should be used strictly private.
Notice:
- the need to redefine this method here is due to the
- inability of many machines to store floats in non-double aligned memory.
- Therefore, on some machines, the first 4 bytes of a float are left unused,
- and the actual float is stored at index 5 .. 12.
- To hide this at one place, this method knows about that, and returns
- values as if this filler wasnt present."
+ the need to redefine this method here is due to the
+ inability of many machines to store floats in non-double aligned memory.
+ Therefore, on some machines, the first 4 bytes of a float are left unused,
+ and the actual float is stored at index 5 .. 12.
+ To hide this at one place, this method knows about that, and returns
+ values as if this filler wasnt present."
%{ /* NOCONTEXT */
register int indx, val;
@@ -2550,28 +2565,28 @@
* and SmallInteger
*/
if (__bothSmallInteger(index, value)) {
- val = __intVal(value);
- if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
- indx = __intVal(index) - 1;
- if (((unsigned)(indx)) < sizeof(double)) {
- cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
- cp[indx] = val;
- RETURN ( value );
- }
- }
+ val = __intVal(value);
+ if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
+ indx = __intVal(index) - 1;
+ if (((unsigned)(indx)) < sizeof(double)) {
+ cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
+ cp[indx] = val;
+ RETURN ( value );
+ }
+ }
}
%}.
value isInteger ifFalse:[
- "
- the object to store should be an integer number
- "
- ^ self elementNotInteger
+ "
+ the object to store should be an integer number
+ "
+ ^ self elementNotInteger
].
(value between:0 and:255) ifFalse:[
- "
- the object to store must be a bytes value
- "
- ^ self elementBoundsError:value
+ "
+ the object to store must be a bytes value
+ "
+ ^ self elementBoundsError:value
].
^ self indexNotIntegerOrOutOfBounds:index
!
@@ -2580,12 +2595,12 @@
"return the size in bytes of the float.
Notice:
- the need to redefine this method here is due to the
- inability of many machines to store floats in non-double aligned memory.
- Therefore, on some machines, the first 4 bytes of a float are left unused,
- and the actual float is stored at index 5 .. 12.
- To hide this at one place, this method knows about that, and returns
- values as if this filler wasn't present."
+ the need to redefine this method here is due to the
+ inability of many machines to store floats in non-double aligned memory.
+ Therefore, on some machines, the first 4 bytes of a float are left unused,
+ and the actual float is stored at index 5 .. 12.
+ To hide this at one place, this method knows about that, and returns
+ values as if this filler wasn't present."
%{ /* NOCONTEXT */
@@ -2608,16 +2623,16 @@
%{
union {
- double d;
- INT64 i;
+ double d;
+ INT64 i;
} this;
if (__isSmallInteger(count)) {
- this.d = __floatVal(self);
- if (isfinite(this.d))
- this.i += __intVal(count);
-
- RETURN(__MKFLOAT(this.d));
+ this.d = __floatVal(self);
+ if (isfinite(this.d))
+ this.i += __intVal(count);
+
+ RETURN(__MKFLOAT(this.d));
}
%}.
self primitiveFailed:#badArgument
@@ -2634,7 +2649,7 @@
!Float methodsFor:'special access'!
exponent
- "extract a normalized float's exponent.
+ "extract a normalized float's (unbiased) exponent.
The returned value depends on the float-representation of
the underlying machine and is therefore highly unportable.
This is not for general use.
@@ -2660,10 +2675,12 @@
^ super exponent
"
- 1.0 exponent
- 2.0 exponent
+ 1.0 exponent
+ 2.0 exponent
3.0 exponent
- 4.0 exponent
+ 3.0 mantissa
+ 3.0 mantissa * (2 raisedTo:3.0 exponent)
+ 4.0 exponent
0.5 exponent
0.4 exponent
0.25 exponent
@@ -2696,8 +2713,8 @@
if (! (isnan(myVal) || isinf(myVal)))
#endif
{
- frac = frexp(myVal, &exp);
- RETURN (__MKFLOAT(frac));
+ frac = frexp(myVal, &exp);
+ RETURN (__MKFLOAT(frac));
}
%}.
^ super mantissa
@@ -2945,24 +2962,24 @@
if ((val >= -1.0) && (val <= 1.0))
# endif
{
- __threadErrno = 0;
- rslt = acos(val);
- if (! isnan(rslt)) /* Currently all our systems support isnan() */
- {
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
- }
+ __threadErrno = 0;
+ rslt = acos(val);
+ if (! isnan(rslt)) /* Currently all our systems support isnan() */
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
#endif
%}.
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#arcCos
- arguments:#()
- errorString:'bad receiver in arcCos'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#arcCos
+ arguments:#()
+ errorString:'bad receiver in arcCos'
"
-10 arcCos
@@ -2990,28 +3007,28 @@
if (val >= 1.0)
# endif
{
- __threadErrno = 0;
- rslt = acosh(val);
- if (! isnan(rslt)) /* Currently all our systems support isnan() */
- {
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
- }
+ __threadErrno = 0;
+ rslt = acosh(val);
+ if (! isnan(rslt)) /* Currently all our systems support isnan() */
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
#endif
%}.
useFallBack notNil ifTrue:[
- ^ super arcCosh
+ ^ super arcCosh
].
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#arcCosh
- arguments:#()
- errorString:'bad receiver in arcCosh'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#arcCosh
+ arguments:#()
+ errorString:'bad receiver in arcCosh'
"
-10.0 arcCosh
@@ -3039,24 +3056,24 @@
if ((val >= -1.0) && (val <= 1.0))
# endif
{
- __threadErrno = 0;
- rslt = asin(val);
- if (! isnan(rslt)) /* Currently all our systems support isnan() */
- {
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
- }
+ __threadErrno = 0;
+ rslt = asin(val);
+ if (! isnan(rslt)) /* Currently all our systems support isnan() */
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
#endif
%}.
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#arcSin
- arguments:#()
- errorString:'bad receiver in arcSin'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#arcSin
+ arguments:#()
+ errorString:'bad receiver in arcSin'
"
-10 arcSin
@@ -3083,27 +3100,27 @@
if (val >= 1.0)
# endif
{
- __threadErrno = 0;
- rslt = asinh(val);
- if (! isnan(rslt)) /* Currently all our systems support isnan() */
- {
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
- }
+ __threadErrno = 0;
+ rslt = asinh(val);
+ if (! isnan(rslt)) /* Currently all our systems support isnan() */
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
#endif
%}.
useFallBack notNil ifTrue:[
- ^ super arcSinh
+ ^ super arcSinh
].
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#arcSinh
- arguments:#()
- errorString:'bad receiver in arcSinh'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#arcSinh
+ arguments:#()
+ errorString:'bad receiver in arcSinh'
"
-10.0 arcSinh
@@ -3126,19 +3143,19 @@
rslt = atan(__floatVal(self));
if (! isnan(rslt)) /* Currently all our systems support isnan() */
{
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
}
#endif
%}.
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#arcTan
- arguments:#()
- errorString:'bad receiver in arcTan'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#arcTan
+ arguments:#()
+ errorString:'bad receiver in arcTan'
"Modified: / 16.11.2001 / 14:14:22 / cg"
!
@@ -3152,45 +3169,45 @@
OBJ newFloat;
if (__isFloat(x)) {
- __threadErrno = 0;
- rslt = atan2(__floatVal(self),__floatVal(x));
- if (! isnan(rslt)) /* Currently all our systems support isnan() */
- {
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
- }
+ __threadErrno = 0;
+ rslt = atan2(__floatVal(self),__floatVal(x));
+ if (! isnan(rslt)) /* Currently all our systems support isnan() */
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
%}.
x isFloat ifFalse:[
- ^ self arcTan2:(x asFloat).
+ ^ self arcTan2:(x asFloat).
].
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#arcTan2:
- arguments:(Array with:x)
- errorString:'bad receiver in arcTan2:'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#arcTan2:
+ arguments:(Array with:x)
+ errorString:'bad receiver in arcTan2:'
!
arcTan: denominator
"Evaluate the four quadrant arc tangent of the argument denominator (x) and the receiver (y)."
(self = 0.0) ifTrue: [
- (denominator > 0.0)
- ifTrue: [ ^ 0 ]
- ifFalse: [ ^ Pi ]
+ (denominator > 0.0)
+ ifTrue: [ ^ 0 ]
+ ifFalse: [ ^ Pi ]
].
(denominator = 0.0) ifTrue: [
- (self > 0.0)
- ifTrue: [ ^ Halfpi ]
- ifFalse: [ ^ HalfpiNegative ]
+ (self > 0.0)
+ ifTrue: [ ^ Halfpi ]
+ ifFalse: [ ^ HalfpiNegative ]
].
(denominator > 0)
- ifTrue: [ ^ (self / denominator) arcTan ]
- ifFalse: [ ^ ((self / denominator) arcTan) + Pi ]
+ ifTrue: [ ^ (self / denominator) arcTan ]
+ ifFalse: [ ^ ((self / denominator) arcTan) + Pi ]
"Created: / 07-06-2007 / 21:10:32 / cg"
"Modified: / 11-06-2007 / 12:58:34 / cg"
@@ -3213,29 +3230,29 @@
if ((val >= -1.0) && (val <= 1.0))
# endif
{
- rslt = atanh(val);
- if (! isnan(rslt)) /* Currently all our systems support isnan() */
+ rslt = atanh(val);
+ if (! isnan(rslt)) /* Currently all our systems support isnan() */
# ifdef __osx__
- if (! isinf(rslt))
+ if (! isinf(rslt))
# endif
- {
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
- }
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
#endif
%}.
useFallBack notNil ifTrue:[
- ^ super arcTanh
+ ^ super arcTanh
].
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#arcTanh
- arguments:#()
- errorString:'bad receiver in arcTanh'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#arcTanh
+ arguments:#()
+ errorString:'bad receiver in arcTanh'
!
cos
@@ -3253,19 +3270,19 @@
rslt = cos(__floatVal(self));
if (! isnan(rslt)) /* Currently all our systems support isnan() */
{
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
}
#endif
%}.
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#cos
- arguments:#()
- errorString:'bad receiver in cos'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#cos
+ arguments:#()
+ errorString:'bad receiver in cos'
"Modified: / 16.11.2001 / 14:14:26 / cg"
!
@@ -3285,19 +3302,19 @@
rslt = cosh(__floatVal(self));
if (! isnan(rslt)) /* Currently all our systems support isnan() */
{
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
}
#endif
%}.
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#cosh
- arguments:#()
- errorString:'bad receiver in cosh'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#cosh
+ arguments:#()
+ errorString:'bad receiver in cosh'
!
sin
@@ -3315,19 +3332,19 @@
rslt = sin(__floatVal(self));
if (! isnan(rslt)) /* Currently all our systems support isnan() */
{
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
}
#endif
%}.
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#sin
- arguments:#()
- errorString:'bad receiver in sin'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#sin
+ arguments:#()
+ errorString:'bad receiver in sin'
"Modified: / 16.11.2001 / 14:14:37 / cg"
!
@@ -3347,19 +3364,19 @@
rslt = sinh(__floatVal(self));
if (! isnan(rslt)) /* Currently all our systems support isnan() */
{
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
}
#endif
%}.
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#sinh
- arguments:#()
- errorString:'bad receiver in sinh'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#sinh
+ arguments:#()
+ errorString:'bad receiver in sinh'
!
tan
@@ -3377,19 +3394,19 @@
rslt = tan(__floatVal(self));
if (! isnan(rslt)) /* Currently all our systems support isnan() */
{
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
}
#endif
%}.
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#tan
- arguments:#()
- errorString:'bad receiver in tan'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#tan
+ arguments:#()
+ errorString:'bad receiver in tan'
"Modified: / 16.11.2001 / 14:14:49 / cg"
!
@@ -3406,18 +3423,18 @@
rslt = tanh(__floatVal(self));
if (! isnan(rslt)) /* Currently all our systems support isnan() */
{
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
- }
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
}
%}.
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#tanh
- arguments:#()
- errorString:'bad receiver in tanh'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#tanh
+ arguments:#()
+ errorString:'bad receiver in tanh'
! !
!Float methodsFor:'truncation & rounding'!
@@ -3438,7 +3455,7 @@
* ST-80 (and X3J20) returns integer.
*/
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
- RETURN ( __mkSmallInteger( (INT) dVal ) );
+ RETURN ( __mkSmallInteger( (INT) dVal ) );
}
__qMKFLOAT(val, dVal);
#endif
@@ -3487,7 +3504,7 @@
* ST-80 (and X3J20) returns integer.
*/
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
- RETURN ( __mkSmallInteger( (INT) dVal ) );
+ RETURN ( __mkSmallInteger( (INT) dVal ) );
}
__qMKFLOAT(val, dVal);
#endif
@@ -3541,17 +3558,17 @@
__threadErrno = 0;
frac = modf(__floatVal(self), &trunc);
if (! isnan(frac)) {
- if (__threadErrno == 0) {
- RETURN (__MKFLOAT(frac));
- }
+ if (__threadErrno == 0) {
+ RETURN (__MKFLOAT(frac));
+ }
}
%}.
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#fractionPart
- arguments:#()
- errorString:'bad receiver in fractionPart'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#fractionPart
+ arguments:#()
+ errorString:'bad receiver in fractionPart'
"
1.6 fractionPart + 1.6 truncated
@@ -3588,15 +3605,15 @@
dVal = __floatVal(self);
if (dVal < 0.0) {
- dVal = ceil(dVal - 0.5);
+ dVal = ceil(dVal - 0.5);
} else {
- dVal = floor(dVal + 0.5);
+ dVal = floor(dVal + 0.5);
}
/*
* ST-80 (and X3J20) returns integer.
*/
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
- RETURN ( __mkSmallInteger( (INT) dVal ) );
+ RETURN ( __mkSmallInteger( (INT) dVal ) );
}
__qMKFLOAT(val, dVal);
#endif
@@ -3631,9 +3648,9 @@
dVal = __floatVal(self);
if (dVal < 0.0) {
- dVal = ceil(dVal - 0.5);
+ dVal = ceil(dVal - 0.5);
} else {
- dVal = floor(dVal + 0.5);
+ dVal = floor(dVal + 0.5);
}
__qMKFLOAT(v, dVal);
RETURN (v);
@@ -3661,16 +3678,16 @@
dVal = __floatVal(self);
if (dVal < 0.0) {
- dVal = ceil(dVal);
+ dVal = ceil(dVal);
} else {
- dVal = floor(dVal);
+ dVal = floor(dVal);
}
/*
* ST-80 (and X3J20) returns integer.
*/
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
- RETURN ( __mkSmallInteger( (INT) dVal ) );
+ RETURN ( __mkSmallInteger( (INT) dVal ) );
}
__qMKFLOAT(val, dVal);
#endif
@@ -3702,9 +3719,9 @@
dVal = __floatVal(self);
if (dVal < 0.0) {
- dVal = ceil(dVal);
+ dVal = ceil(dVal);
} else {
- dVal = floor(dVal);
+ dVal = floor(dVal);
}
__qMKFLOAT(v, dVal);
RETURN (v);