--- a/IEEEFloat.st Sun Dec 08 04:10:28 2019 +0100
+++ b/IEEEFloat.st Sun Dec 08 21:07:40 2019 +0100
@@ -189,6 +189,10 @@
!IEEEFloat class methodsFor:'constants'!
+pi
+ ^ Float pi
+!
+
unity
^ 1.0
!
@@ -874,6 +878,52 @@
!IEEEFloat methodsFor:'mathematical functions'!
+ln
+ "return the natural logarithm of myself.
+ Raises an exception, if the receiver is less or equal to zero.
+
+ Not sure if this is really faster than using a taylor right away:
+ the three exp-computations at the end are done in qDouble and are tailors themself..."
+
+ |x|
+
+ self = self class zero ifFalse:[
+ self positive ifTrue:[
+ "/ initial approx.
+ x := self coerce:(self asFloat ln).
+ "/ three more iterations of newton...
+ x := x + (self * (x negated exp)) - 1.0.
+ x := x + (self * (x negated exp)) - 1.0.
+ x := x + (self * (x negated exp)) - 1.0.
+
+ ^ x
+ ].
+ ].
+
+ "/ now done via trapInfinity; was:
+ "/ d0 = 0.0 ifTrue:[
+ "/ ^ Infinity negative
+ "/ ].
+
+ "/ 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)'
+
+ "
+ Number trapInfinity:[ 0.0 ln ]
+ Number trapInfinity:[ 0.0 asIEEEFloat ln ]
+ 1.0 asIEEEFloat ln
+
+ 2.7 asIEEEFloat ln
+ 100 asIEEEFloat ln
+ 3.0 asIEEEFloat ln printfPrintString:'%10.8f'
+ "
+!
+
log10
"return log base-10 of the receiver.
Raises an exception, if the receiver is less or equal to zero.