Skip to content
Browse files

Try to make the rules and examples for Rat.perl, Rat.gist, and Rat.St…

…r consistent.
  • Loading branch information...
1 parent efa4c18 commit 1cbef9e02c00f42abd6c2b379df223472aaa6ca9 @colomon colomon committed May 11, 2012
Showing with 20 additions and 21 deletions.
  1. +15 −18 S02-bits.pod
  2. +5 −3 S32-setting-library/Numeric.pod
View
33 S02-bits.pod
@@ -787,24 +787,20 @@ unreduced values. You can use C<$rat.=norm> to normalize the fraction.
(This also forces the sign on the denominator to be positive.)
The C<.perl> method will produce a decimal number if the denominator is
a power of 10, or normalizable to a power of 10 (that is, having factors
-of only 2 and 5 (and -1)). Otherwise it will normalize and return a rational
-literal of the form C<-47/3>. Stringifying a rational does a similar
-calculation, with the same result on decimal-normalizable fractions,
-but where C<.perl> would produce the C<-47/3> form, stringification instead
-converts to a decimal notation with fractional precision determined by
-the size of the denominator, such that the rational internal form is
-somewhat hidden from the casual user, who would generally prefer
-to see pure decimal notation. C<Rat.gist> follows the same rules as
-stringification.
+of only 2 and 5 (and -1)). Otherwise it will normalize and return a rational
+literal of the form C<< <-47/3> >>. Stringifying a rational via C<.gist>
+or C<.Str> returns an exact decimal number if possible, and rounds off
+the repeated decimal otherwise. For full details see the documentation
+of C<Rat.gist> in S32.
C<Num.Str> and C<Num.gist> both produce valid Num literals, so they must
include the C<e> for the exponential.
- say 1/5; # 0.2 exactly (not via Num)
- say 1/3; # 0.333333333333333 via Num
-
+ say 1/5; # 0.2 exactly
+ say 1/3; # 0.333333
+
say <2/6>.perl
- # 1/3
+ # <1/3>
say 3.14159_26535_89793
# 3.141592653589793 including last digit
@@ -816,7 +812,7 @@ include the C<e> for the exponential.
# 111111111111111111111111111111111111111111111
say <555555555555555555555555555555555555555555555/5>.perl
- # 111111111111111111111111111111111111111111111/1
+ # <111111111111111111111111111111111111111111111/1>
say 2e2; # 200e0 or 2e2 or 200.0e0 or 2.0e2
=head2 Infinity and C<NaN>
@@ -4521,10 +4517,11 @@ automatically become a C<FatRat>, which would force all calculations
into the pessimal C<FatRat> type.
constant pi is export = 3.14159_26535_89793_23846_26433_83279_50288;
- say pi.perl; # 3141592653589793238/1000000000000000000 or so (Rat64)
- say pi.Num # 3.14159265358979
- say pi.Str; # 3.14159_26535_89793_23846_26433_83279_50288
- say pi.FatRat; # 3.14159265358979323846264338327950288
+ say pi.norm.nude # 1570796326794896619 500000000000000000 (as Rat, reduced)
+ say pi.perl; # 3.14159_26535_89793_23846_26433_83279_50288
+ say pi.Num # 3.14159265358979 (approximately)
+ say pi.Str; # 3.14159_26535_89793_23846_26433_83279_50288
+ say pi.FatRat; # 3.14159265358979323846264338327950288
=head1 Context
View
8 S32-setting-library/Numeric.pod
@@ -543,9 +543,11 @@ C<Str> coercion is identical to C<gist>.
multi method perl( --> Str )
Returns a string representation corresponding to the unambiguous
-C<val()>-based representation of rational literals, of the form "C<< <3/5> >>",
-without internal spaces, and including the angles that keep the C</>
-from being treated as a normal division operator.
+C<val()>-based representation of rational literals. If the
+number can be represented exactly in decimal, it will be. Otherwise uses
+the form "C<< <3/5> >>", without internal spaces, and including the
+angles that keep the C</> from being treated as a normal division
+operator.
=back

0 comments on commit 1cbef9e

Please sign in to comment.
Something went wrong with that request. Please try again.