--- a/ShortFloat.st Sat Jun 17 03:03:37 2017 +0200
+++ b/ShortFloat.st Sat Jun 17 03:09:38 2017 +0200
@@ -15,7 +15,7 @@
LimitedPrecisionReal variableByteSubclass:#ShortFloat
instanceVariableNames:''
- classVariableNames:'DefaultPrintFormat Pi E Epsilon'
+ classVariableNames:'DefaultPrintFormat Pi E Epsilon Ln10'
poolDictionaries:''
category:'Magnitude-Numbers'
!
@@ -351,7 +351,6 @@
"Modified (comment): / 12-06-2017 / 18:52:18 / cg"
! !
-
!ShortFloat class methodsFor:'binary storage'!
readBinaryIEEESingleFrom:aStream
@@ -501,6 +500,21 @@
^-126
!
+ln10
+ "return the natural logarithm of 10 as a shortFloat"
+
+ Ln10 isNil ifTrue:[
+ Ln10 := Float ln10 asShortFloat
+ ].
+ ^ Ln10
+
+ "
+ self ln10
+ "
+
+ "Created: / 16-06-2017 / 11:09:37 / cg"
+!
+
pi
"return the constant pi as ShortFloat"
@@ -526,8 +540,21 @@
"Modified: 23.4.1996 / 09:26:45 / cg"
! !
+!ShortFloat class methodsFor:'queries'!
-!ShortFloat class methodsFor:'queries'!
+defaultPrintPrecision
+ "return the number of decimal digits printed by default"
+
+ ^ 5
+
+ "
+ ShortFloat defaultPrintPrecision
+ Float defaultPrintPrecision
+ LongFloat defaultPrintPrecision
+ "
+
+ "Created: / 17-06-2017 / 02:59:31 / cg"
+!
exponentCharacter
^ $e
@@ -1211,6 +1238,58 @@
Transcript show:'fast: '; showCR:t1.
Transcript show:'regular: '; showCR:t2.
"
+!
+
+log10
+ "return the base-10 logarithm of the receiver.
+ Raises an exception, if the receiver is less or equal to zero."
+
+%{ /* NOCONTEXT */
+#ifndef __SCHTEAM__
+ float val, rslt;
+ OBJ newFloat;
+
+ val = __shortFloatVal(self);
+
+# ifdef __win32__ /* to suppress the warnBox opened by win32 */
+ if (val > 0.0)
+# endif
+ {
+ __threadErrno = 0;
+ rslt = log10f(val);
+ if (! isnanf(rslt)) /* Currently all our systems support isnan() */
+ {
+ if (__threadErrno == 0) {
+ __qMKSFLOAT(newFloat, rslt);
+ RETURN ( newFloat );
+ }
+ }
+ }
+#endif
+%}.
+ "
+ an invalid value for logarithm
+ "
+ ^ self class
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#log10
+ arguments:#()
+ errorString:'bad receiver in log10'
+
+ "
+ 10 asFloat log10 1.0
+ 10 asShortFloat log10 1.0
+ 10 asLongFloat log10 1.0
+ 10 asQDouble log10 1.00000000000000000000000000000000000000000
+
+ 50 asFloat log10 1.69897000433602
+ 50 asShortFloat log10 1.69897
+ 50 asLongFloat log10 1.698970004336018805
+ 50 asQDouble log10 1.69897000433601880478626110527550697323181
+ "
+
+ "Created: / 16-06-2017 / 10:47:53 / cg"
! !
!ShortFloat methodsFor:'printing & storing'!