#DOCUMENTATION by cg
class: LimitedPrecisionReal
comment/format in: #defaultNumberOfDigits
category of:
#exponent
#fractionalPart
#mantissa
--- a/LimitedPrecisionReal.st Tue Jun 20 12:23:11 2017 +0200
+++ b/LimitedPrecisionReal.st Tue Jun 20 12:59:54 2017 +0200
@@ -1136,135 +1136,6 @@
LongFloat infinity asTrueFraction
LongFloat negativeInfinity asTrueFraction
"
-!
-
-exponent
- "extract a normalized float's exponent.
- This is a fallback for systems which do not provide frexp in their math lib,
- als also for error reporting (NaN or Inf).
- The returned value depends on the float-representation of
- the underlying machine and is therefore highly unportable.
- This is not for general use.
- This assumes that the mantissa is normalized to
- 0.5 .. 1.0 and the float's value is mantissa * 2^exp"
-
- |shifty expPart exp numBytes numBitsInMantissa maskMantissa numBitsInExponent maskExponent
- biasExponent numIntegerBits fractionPart|
-
- (self isNaN or:[self isInfinite]) ifTrue:[
- ^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#exponent
- arguments:#()
- errorString:'bad receiver (Inf or NaN) in exponent'
- ].
-
- "Extract the bits of an IEEE anySize float "
- numBytes := self basicSize.
- numBitsInMantissa := self class numBitsInMantissa. maskMantissa := (1 bitShift:numBitsInMantissa) - 1.
- numBitsInExponent := self class numBitsInExponent. maskExponent := (1 bitShift:numBitsInExponent) - 1.
- numIntegerBits := self class numBitsInIntegerPart.
- biasExponent := maskExponent bitShift:-1.
-
- shifty := LargeInteger basicNew numberOfDigits:numBytes.
- UninterpretedBytes isBigEndian ifTrue:[
- 1 to:numBytes do:[:i | shifty digitAt:(numBytes+1-i) put:(self basicAt:i)].
- ] ifFalse:[
- 1 to:numBytes do:[:i | shifty digitAt:i put:(self basicAt:i)].
- ].
-
- " Extract the sign and the biased exponent "
- expPart := (shifty bitShift:numBitsInMantissa negated) bitAnd: maskExponent.
-
- " Extract fractional part; answer 0 if this is a true 0.0 value "
- fractionPart := shifty bitAnd:maskMantissa.
- ( expPart=0 and: [ fractionPart=0 ] ) ifTrue: [ ^ 0 ].
-
- exp := expPart - biasExponent + 1.
- ^ exp
-
- "
- 0.3 asFloat exponent
- 0.3 asShortFloat exponent
- 0.3 asLongFloat exponent
-
- 0.0 exponent2 0
- 1.0 exponent2 1
- 2.0 exponent2 2
- 3.0 exponent2 2
- 4.0 exponent2 3
- 0.5 exponent2 0
- 0.4 exponent2 -1
- 0.25 exponent2 -1
- 0.00000011111 exponent2 -23
- "
-
- "Modified (comment): / 20-06-2017 / 11:34:29 / cg"
-!
-
-fractionalPart
- "This has been renamed to #fractionPart for ST80 compatibility.
-
- extract the after-decimal fraction part.
- the floats value is
- float truncated + float fractionalPart"
-
- <resource:#obsolete>
-
- self obsoleteMethodWarning:'please use #fractionPart'.
- ^ self fractionPart
-
- "Modified: / 28.10.1998 / 17:10:12 / cg"
- "Created: / 28.10.1998 / 17:10:32 / cg"
-!
-
-mantissa
- "extract a normalized float's mantissa.
- This is a fallback for systems which do not provide frexp in their math lib,
- als also for error reporting (NaN or Inf)."
-
- |shifty expPart numBytes numBitsInMantissa maskMantissa numBitsInExponent maskExponent
- biasExponent numIntegerBits fractionPart|
-
- (self isNaN or:[self isInfinite]) ifTrue:[
- ^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#mantissa
- arguments:#()
- errorString:'bad receiver (Inf or NaN) in mantissa'
- ].
-
- "Extract the bits of an IEEE anySize float "
- numBytes := self basicSize.
- numBitsInMantissa := self class numBitsInMantissa. maskMantissa := (1 bitShift:numBitsInMantissa) - 1.
- numBitsInExponent := self class numBitsInExponent. maskExponent := (1 bitShift:numBitsInExponent) - 1.
- numIntegerBits := self class numBitsInIntegerPart.
- biasExponent := maskExponent bitShift:-1.
-
- shifty := LargeInteger basicNew numberOfDigits:numBytes.
- UninterpretedBytes isBigEndian ifTrue:[
- 1 to:numBytes do:[:i | shifty digitAt:(numBytes+1-i) put:(self basicAt:i)].
- ] ifFalse:[
- 1 to:numBytes do:[:i | shifty digitAt:i put:(self basicAt:i)].
- ].
-
- " Extract the sign and the biased exponent "
- expPart := (shifty bitShift:numBitsInMantissa negated) bitAnd: maskExponent.
-
- " Extract fractional part; answer 0 if this is a true 0.0 value "
- fractionPart := shifty bitAnd:maskMantissa.
- ^ fractionPart.
-
- "
- 0.3 asFloat mantissa
- 0.3 asShortFloat mantissa
- 0.3 asLongFloat mantissa
- 0.3 asQDouble mantissa
- "
-
- "Created: / 20-06-2017 / 11:36:51 / cg"
! !
!LimitedPrecisionReal methodsFor:'comparing'!
@@ -1411,7 +1282,139 @@
Float new defaultNumberOfDigits
LongFloat new defaultNumberOfDigits
ShortFloat new defaultNumberOfDigits
+ QDouble new defaultNumberOfDigits
"
+
+ "Modified (comment): / 20-06-2017 / 12:58:12 / cg"
+!
+
+exponent
+ "extract a normalized float's exponent.
+ This is a fallback for systems which do not provide frexp in their math lib,
+ als also for error reporting (NaN or Inf).
+ The returned value depends on the float-representation of
+ the underlying machine and is therefore highly unportable.
+ This is not for general use.
+ This assumes that the mantissa is normalized to
+ 0.5 .. 1.0 and the float's value is mantissa * 2^exp"
+
+ |shifty expPart exp numBytes numBitsInMantissa maskMantissa numBitsInExponent maskExponent
+ biasExponent numIntegerBits fractionPart|
+
+ (self isNaN or:[self isInfinite]) ifTrue:[
+ ^ self class
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#exponent
+ arguments:#()
+ errorString:'bad receiver (Inf or NaN) in exponent'
+ ].
+
+ "Extract the bits of an IEEE anySize float "
+ numBytes := self basicSize.
+ numBitsInMantissa := self class numBitsInMantissa. maskMantissa := (1 bitShift:numBitsInMantissa) - 1.
+ numBitsInExponent := self class numBitsInExponent. maskExponent := (1 bitShift:numBitsInExponent) - 1.
+ numIntegerBits := self class numBitsInIntegerPart.
+ biasExponent := maskExponent bitShift:-1.
+
+ shifty := LargeInteger basicNew numberOfDigits:numBytes.
+ UninterpretedBytes isBigEndian ifTrue:[
+ 1 to:numBytes do:[:i | shifty digitAt:(numBytes+1-i) put:(self basicAt:i)].
+ ] ifFalse:[
+ 1 to:numBytes do:[:i | shifty digitAt:i put:(self basicAt:i)].
+ ].
+
+ " Extract the sign and the biased exponent "
+ expPart := (shifty bitShift:numBitsInMantissa negated) bitAnd: maskExponent.
+
+ " Extract fractional part; answer 0 if this is a true 0.0 value "
+ fractionPart := shifty bitAnd:maskMantissa.
+ ( expPart=0 and: [ fractionPart=0 ] ) ifTrue: [ ^ 0 ].
+
+ exp := expPart - biasExponent + 1.
+ ^ exp
+
+ "
+ 0.3 asFloat exponent
+ 0.3 asShortFloat exponent
+ 0.3 asLongFloat exponent
+
+ 0.0 exponent2 0
+ 1.0 exponent2 1
+ 2.0 exponent2 2
+ 3.0 exponent2 2
+ 4.0 exponent2 3
+ 0.5 exponent2 0
+ 0.4 exponent2 -1
+ 0.25 exponent2 -1
+ 0.00000011111 exponent2 -23
+ "
+
+ "Modified (comment): / 20-06-2017 / 11:34:29 / cg"
+!
+
+fractionalPart
+ "This has been renamed to #fractionPart for ST80 compatibility.
+
+ extract the after-decimal fraction part.
+ the floats value is
+ float truncated + float fractionalPart"
+
+ <resource:#obsolete>
+
+ self obsoleteMethodWarning:'please use #fractionPart'.
+ ^ self fractionPart
+
+ "Modified: / 28.10.1998 / 17:10:12 / cg"
+ "Created: / 28.10.1998 / 17:10:32 / cg"
+!
+
+mantissa
+ "extract a normalized float's mantissa.
+ This is a fallback for systems which do not provide frexp in their math lib,
+ als also for error reporting (NaN or Inf)."
+
+ |shifty expPart numBytes numBitsInMantissa maskMantissa numBitsInExponent maskExponent
+ biasExponent numIntegerBits fractionPart|
+
+ (self isNaN or:[self isInfinite]) ifTrue:[
+ ^ self class
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#mantissa
+ arguments:#()
+ errorString:'bad receiver (Inf or NaN) in mantissa'
+ ].
+
+ "Extract the bits of an IEEE anySize float "
+ numBytes := self basicSize.
+ numBitsInMantissa := self class numBitsInMantissa. maskMantissa := (1 bitShift:numBitsInMantissa) - 1.
+ numBitsInExponent := self class numBitsInExponent. maskExponent := (1 bitShift:numBitsInExponent) - 1.
+ numIntegerBits := self class numBitsInIntegerPart.
+ biasExponent := maskExponent bitShift:-1.
+
+ shifty := LargeInteger basicNew numberOfDigits:numBytes.
+ UninterpretedBytes isBigEndian ifTrue:[
+ 1 to:numBytes do:[:i | shifty digitAt:(numBytes+1-i) put:(self basicAt:i)].
+ ] ifFalse:[
+ 1 to:numBytes do:[:i | shifty digitAt:i put:(self basicAt:i)].
+ ].
+
+ " Extract the sign and the biased exponent "
+ expPart := (shifty bitShift:numBitsInMantissa negated) bitAnd: maskExponent.
+
+ " Extract fractional part; answer 0 if this is a true 0.0 value "
+ fractionPart := shifty bitAnd:maskMantissa.
+ ^ fractionPart.
+
+ "
+ 0.3 asFloat mantissa
+ 0.3 asShortFloat mantissa
+ 0.3 asLongFloat mantissa
+ 0.3 asQDouble mantissa
+ "
+
+ "Created: / 20-06-2017 / 11:36:51 / cg"
!
precision