#FEATURE by exept
class: Fraction
class definition
class: Fraction class
added: #phi
--- a/Fraction.st Wed Nov 20 16:32:58 2019 +0100
+++ b/Fraction.st Wed Nov 20 16:33:31 2019 +0100
@@ -17,7 +17,7 @@
Number subclass:#Fraction
instanceVariableNames:'numerator denominator'
- classVariableNames:'FractionOne FractionZero PrintWholeNumbers Pi Pi_1000 E'
+ classVariableNames:'FractionOne FractionZero PrintWholeNumbers Pi Pi_1000 E Phi'
poolDictionaries:''
category:'Magnitude-Numbers'
!
@@ -324,6 +324,28 @@
"Created: / 03-07-2017 / 17:21:38 / cg"
!
+phi
+ "return an approximation of the constant phi as Fraction.
+ The approx. returned here has an error smaller than representable by float instances
+ (roughly 26 valid digits)"
+
+ Phi isNil ifTrue:[
+ Phi := self
+ numerator: 161803398874989484820458683
+ denominator:100000000000000000000000000
+ ].
+ ^ Phi
+
+ "
+ Fraction phi
+ Fraction phi asFloat - Float phi
+ Fraction phi asLongFloat - LongFloat phi
+ Float phi
+ "
+
+ "Modified (comment): / 03-07-2017 / 13:21:03 / cg"
+!
+
pi
"return an approximation of the constant pi as Fraction.
The approx. returned here has an error smaller than representable by float instances