--- a/LargeFloat.st Mon Jul 17 14:51:09 2017 +0200
+++ b/LargeFloat.st Mon Jul 17 15:51:50 2017 +0200
@@ -15,7 +15,8 @@
LimitedPrecisionReal subclass:#LargeFloat
instanceVariableNames:'exponent mantissa precision'
- classVariableNames:'Zero One NaN PositiveInfinity NegativeInfinity Pi_1000 E_1000'
+ classVariableNames:'Zero One NaN PositiveInfinity NegativeInfinity Pi_1000 E_1000
+ Ln10'
poolDictionaries:''
category:'Magnitude-Numbers'
!
@@ -130,9 +131,21 @@
^ self basicNew
mantissa:(fraction * sign)
exponent:(exp negated)
+ precision:(aLimitedPrecisionReal precision)
"
- 1.0 asLargeFloat
+ 1.0 asLargeFloat
+
+ take a look at the precision...
+
+ 1.0 asShortFloat asLargeFloat
+ 1.0 asLongFloat asLargeFloat
+ 1.0 asQDouble asLargeFloat
+ 1 asLargeFloat
+ (5/3) asLargeFloat
+ (3/5) asLargeFloat
+ (1/2) asLargeFloat
+
2.0 asLargeFloat
20000.0 asLargeFloat
2e6 asLargeFloat
@@ -152,6 +165,8 @@
Float infinity asLargeFloat
Float negativeInfinity asLargeFloat
"
+
+ "Modified (comment): / 17-07-2017 / 15:09:30 / cg"
!
mantissa:m exponent:e
@@ -186,6 +201,14 @@
"
! !
+!LargeFloat class methodsFor:'coercing & converting'!
+
+coerce:aNumber
+ "return the argument as a LargeFloat"
+
+ ^ aNumber asLargeFloat
+! !
+
!LargeFloat class methodsFor:'constants'!
NaN
@@ -206,6 +229,21 @@
"
!
+ln10
+ "return the Ln10ln(10) as largeFloat with approx. 500 bits of precision"
+
+ Ln10 isNil ifTrue:[
+ Ln10 := 10.0 asLargeFloat ln_withAccuracy:(LargeFloat readFrom:'1e-500')
+ ].
+ ^ Ln10
+
+ "
+ LargeFloat ln10
+ "
+
+ "Created: / 17-07-2017 / 15:15:25 / cg"
+!
+
negativeInfinity
^ NegativeInfinity
@@ -274,8 +312,19 @@
^ aNumber sumFromLargeFloat:self
"
- 1.0 asLargeFloat
+ 1.0 asLargeFloat + 20 asLargeFloat
+ 1.0 asLargeFloat + 20
+ 1.0 asLargeFloat + 20.0
+ 1.0 asLargeFloat + ( 2 / 5 )
+ 1.0 asLargeFloat + 0.4 asLargeFloat
+
+ 20 asLargeFloat + 1.0 asLargeFloat
+ 20 + 1.0 asLargeFloat
+ 20.0 + 1.0 asLargeFloat
+ ( 2 / 5 ) + 1.0 asLargeFloat
"
+
+ "Modified (comment): / 17-07-2017 / 15:06:20 / cg"
!
- aNumber
@@ -581,7 +630,7 @@
"Return the quotient of the argument, aLargeFloat and the receiver.
Sent when aLargeFloat does not know how to divide by the receiver."
- |otherMantissa otherExponent q|
+ |otherMantissa otherExponent q e p limit prec|
otherMantissa := aLargeFloat mantissa.
otherExponent := aLargeFloat exponent.
@@ -600,13 +649,30 @@
aLargeFloat negative ifTrue:[^ self negated].
^ self
].
+ e := (otherExponent - exponent).
q := (otherMantissa / mantissa).
+ p := Infinity positive.
+
q isInteger ifFalse:[
- self halt.
+ limit := precision isFinite ifTrue:[ precision ] ifFalse:[ 200 ].
+
+ prec := 0.
+ [ q isInteger or:[ limit >= 0 ]] whileTrue:[
+ q := q * 2. e := e - 1.
+ prec := prec + 1.
+ limit := limit - 1.
+ ].
+ q isInteger ifFalse:[
+ p := prec.
+ q := q asInteger.
+ ].
].
^ self class
mantissa:q
- exponent:(otherExponent - exponent)
+ exponent:e
+ precision:p
+
+ "Modified: / 17-07-2017 / 15:11:33 / cg"
!
sumFromLargeFloat:aLargeFloat
@@ -791,6 +857,10 @@
version
^ '$Header$'
+!
+
+version_CVS
+ ^ '$Header$'
! !