--- a/Float.st Thu Nov 15 15:05:36 2001 +0100
+++ b/Float.st Thu Nov 15 23:12:01 2001 +0100
@@ -569,24 +569,24 @@
!Float methodsFor:'Compatibility - Squeak'!
closeTo: num
- "are these two numbers close?"
- | fuzz ans |
- num isNumber ifFalse: [
- [ans:=self = num] ifError: [:aString :aReceiver | ^ false].
- ^ ans].
- self = 0.0 ifTrue: [^ num abs < 0.0001].
- num = 0.0 ifTrue: [^ self abs < 0.0001].
- self isNaN == num isNaN ifFalse: [^ false].
- self isInfinite == num isInfinite ifFalse: [^ false].
+ "are these two numbers close?"
+ | fuzz ans |
+ num isNumber ifFalse: [
+ [ans:=self = num] ifError: [:aString :aReceiver | ^ false].
+ ^ ans].
+ self = 0.0 ifTrue: [^ num abs < 0.0001].
+ num = 0.0 ifTrue: [^ self abs < 0.0001].
+ self isNaN == num isNaN ifFalse: [^ false].
+ self isInfinite == num isInfinite ifFalse: [^ false].
- fuzz := (self abs max: num abs) * 0.0001.
- ^ (self - num) abs <= fuzz
+ fuzz := (self abs max: num abs) * 0.0001.
+ ^ (self - num) abs <= fuzz
- "9.0 closeTo: 8.9999
- 9.9 closeTo: 9
- (9/3) closeTo: 2.9999
- "
+ "9.0 closeTo: 8.9999
+ 9.9 closeTo: 9
+ (9/3) closeTo: 2.9999
+ "
! !
!Float methodsFor:'arithmetic'!
@@ -609,18 +609,18 @@
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 );
}
if (__isFloatLike(aNumber)) {
- result = __floatVal(self) * __floatVal(aNumber);
- goto retResult;
+ result = __floatVal(self) * __floatVal(aNumber);
+ goto retResult;
}
if (__isShortFloat(aNumber)) {
- result = __floatVal(self) * (double)(__shortFloatVal(aNumber));
- goto retResult;
+ result = __floatVal(self) * (double)(__shortFloatVal(aNumber));
+ goto retResult;
}
%}.
^ aNumber productFromFloat:self
@@ -644,18 +644,18 @@
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 );
}
if (__isFloatLike(aNumber)) {
- result = __floatVal(self) + __floatVal(aNumber);
- goto retResult;
+ result = __floatVal(self) + __floatVal(aNumber);
+ goto retResult;
}
if (__isShortFloat(aNumber)) {
- result = __floatVal(self) + (double)(__shortFloatVal(aNumber));
- goto retResult;
+ result = __floatVal(self) + (double)(__shortFloatVal(aNumber));
+ goto retResult;
}
%}.
^ aNumber sumFromFloat:self
@@ -679,18 +679,18 @@
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 );
}
if (__isFloatLike(aNumber)) {
- result = __floatVal(self) - __floatVal(aNumber);
- goto retResult;
+ result = __floatVal(self) - __floatVal(aNumber);
+ goto retResult;
}
if (__isShortFloat(aNumber)) {
- result = __floatVal(self) - (double)(__shortFloatVal(aNumber));
- goto retResult;
+ result = __floatVal(self) - (double)(__shortFloatVal(aNumber));
+ goto retResult;
}
%}.
^ aNumber differenceFromFloat:self
@@ -714,31 +714,31 @@
double result, val;
if (__isSmallInteger(aNumber)) {
- if (aNumber != __MKSMALLINT(0)) {
- result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
+ if (aNumber != __MKSMALLINT(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;
+ }
}
%}.
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
- "
- No, you shalt not divide by zero
- "
- ^ DivisionByZeroSignal raiseRequestWith:thisContext.
+ "
+ No, you shalt not divide by zero
+ "
+ ^ DivisionByZeroSignal raiseRequestWith:thisContext.
].
^ aNumber quotientFromFloat:self
!
@@ -754,9 +754,9 @@
double rslt;
if (val < 0.0) {
- rslt = -val;
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
+ rslt = -val;
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
}
RETURN (self);
%}.
@@ -1129,17 +1129,29 @@
%{ /* NOCONTEXT */
- double rslt;
+ double val, rslt;
OBJ newFloat;
- __threadErrno = 0;
- rslt = acos(__floatVal(self));
+ val = __floatVal(self);
+
+#ifdef WIN32
+ /* dont know (yet) how to suppress the warnBox
+ * opened by windows ...
+ */
+ if ((val >= -1.0) && (val <= 1.0))
+#endif
+ {
+ __threadErrno = 0;
+ rslt = acos(val);
#ifdef LINUX /* and maybe others */
- if (! isnan(rslt))
+ if (! isnan(rslt))
#endif
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
%}.
^ self class
@@ -1159,17 +1171,29 @@
%{ /* NOCONTEXT */
- double rslt;
+ double val, rslt;
OBJ newFloat;
- __threadErrno = 0;
- rslt = asin(__floatVal(self));
+ val = __floatVal(self);
+
+#ifdef WIN32
+ /* dont know (yet) how to suppress the warnBox
+ * opened by windows ...
+ */
+ if ((val >= -1.0) && (val <= 1.0))
+#endif
+ {
+ __threadErrno = 0;
+ rslt = asin(val);
#ifdef LINUX /* and maybe others */
- if (! isnan(rslt))
+ if (! isnan(rslt))
#endif
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
%}.
^ self class
@@ -1265,17 +1289,29 @@
%{ /* NOCONTEXT */
- double rslt;
+ double val, rslt;
OBJ newFloat;
- __threadErrno = 0;
- rslt = log(__floatVal(self));
+ val = __floatVal(self);
+
+#ifdef WIN32
+ /* dont know (yet) how to suppress the warnBox
+ * opened by windows ...
+ */
+ if (val > 0.0)
+#endif
+ {
+ __threadErrno = 0;
+ rslt = log(val);
#ifdef LINUX /* and maybe others */
- if (! isnan(rslt))
+ if (! isnan(rslt))
#endif
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
}
%}.
"
@@ -1353,21 +1389,25 @@
%{ /* NOCONTEXT */
- double rslt;
+ double val, rslt;
OBJ newFloat;
+ val = __floatVal(self);
+
#ifdef WIN32
- if (__floatVal(self) >= 0.0)
+ if (val >= 0.0)
#endif
{
__threadErrno = 0;
- rslt = sqrt(__floatVal(self));
+ rslt = sqrt(val);
#ifdef LINUX /* and maybe others */
if (! isnan(rslt))
#endif
- if (__threadErrno == 0) {
- __qMKFLOAT(newFloat, rslt);
- RETURN ( newFloat );
+ {
+ if (__threadErrno == 0) {
+ __qMKFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
}
}
%}.
@@ -1426,12 +1466,12 @@
char fmtBuffer[20];
if (__isString(@global(DefaultPrintFormat))) {
- fmt = (char *) __stringVal(@global(DefaultPrintFormat));
+ fmt = (char *) __stringVal(@global(DefaultPrintFormat));
} else {
- /*
- * in case we get called before #initialize ...
- */
- fmt = ".6";
+ /*
+ * in case we get called before #initialize ...
+ */
+ fmt = ".6";
}
/*
@@ -1452,17 +1492,17 @@
* (i.e. look if string contains '.' or 'e' and append '.0' if not)
*/
for (cp = buffer; *cp; cp++) {
- if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break;
+ if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break;
}
if (! *cp) {
- *cp++ = '.';
- *cp++ = '0';
- *cp = '\0';
+ *cp++ = '.';
+ *cp++ = '0';
+ *cp = '\0';
}
s = __MKSTRING(buffer COMMA_SND);
if (s != nil) {
- RETURN (s);
+ RETURN (s);
}
%}.
"
@@ -1475,13 +1515,13 @@
^ ObjectMemory allocationFailureSignal 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
+ 1.0 printString
+ 1.234 printString
+ 1e10 printString
+ 1.2e3 printString
+ 1.2e30 printString
+ (1.0 uncheckedDivide:0) printString
+ (0.0 uncheckedDivide:0) printString
"
!
@@ -2050,23 +2090,23 @@
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 ( __MKSMALLINT( (INT) dVal ) );
+ RETURN ( __MKSMALLINT( (INT) dVal ) );
}
__qMKFLOAT(val, dVal);
%}.
val notNil ifTrue:[
- ^ val asInteger
+ ^ val asInteger
].
self < 0.0 ifTrue:[
- ^ (self - 0.5) ceiling asInteger
+ ^ (self - 0.5) ceiling asInteger
].
^ (self + 0.5) floor asInteger
@@ -2178,6 +2218,6 @@
!Float class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.119 2001-11-05 15:34:06 james Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.120 2001-11-15 22:12:01 cg Exp $'
! !
Float initialize!