--- a/Fraction.st Wed Apr 29 22:19:08 2009 +0200
+++ b/Fraction.st Fri May 01 19:19:55 2009 +0200
@@ -145,10 +145,11 @@
!Fraction class methodsFor:'constants'!
pi
- "return the constant pi as Fraction"
+ "return an approximation of the constant pi as Fraction.
+ The approx. returned here has an error smaller than representable by float instances"
^ self
- numerator: 314159265358979323846264343
+ numerator:314159265358979323846264343
denominator:100000000000000000000000000
"/ ^ self
@@ -164,6 +165,23 @@
"Modified: 5.11.1996 / 11:11:44 / cg"
!
+pi_approximation
+ "return an approximation of the constant pi as Fraction.
+ The approx. returned is good for 6 valid digits and has an error of less than -2.67-07.
+ The value might be useful to avoid floating point numbers in graphic rendering code,
+ where 6 digits of precision are usually good enough."
+
+ ^ self
+ numerator:355
+ denominator:113
+
+ "
+ Fraction pi
+ Fraction pi asFloat
+ Float pi - Fraction pi_approximation asFloat
+ "
+!
+
unity
"return the neutral element for multiplication (1 / 1)"
@@ -1105,7 +1123,7 @@
!Fraction class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.75 2008-10-21 10:13:29 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.76 2009-05-01 17:19:55 cg Exp $'
! !
Fraction initialize!