> +Although most rational implementations normalize or "reduce" fractions
> +to their smallest representation immediately through a gcd algorithm,
> +Perl allows a rational datatype to do so lazily at need, such as
> +whenever the denominator would run out of precision, but avoid the
> +overhead otherwise.  Hence, if you are adding a bunch of C<Rat>s that
> +represent, say, dollars and cents, the denominator may stay 100 the
> +entire way through.  The C<.nu> and C<.de> methods will return these
> +unreduced values.  You can use C<$rat.=norm> to normalize the fraction.
> +The C<.perl> method will produce a decimal number if the denominator is
> +a multiple of 10.  Otherwise it will normalize and return a rational
> +literal of the form -47/3.  Stringifying a rational always converts
> +to C<Num> and stringifies that, so the rational internal form is
> +somewhat hidden from the casual user, who would generally prefer
> +to see decimal notation.

Wouldn't it be better to produce a decimal number if the denominator
equals of 2**n * 5**m for n,m unsigned int? Before displaying the
value should be "decimal-normalized" by multiplying numerator and
denominator by 2**|n-m| or 5**|n-m| depending on sign(n-m).
Otherwise adding Rats representing dollars and cents which are
immediately normalized could produce flapping between rational literal
form and decimal number form.
Aside from that the specification should be: if the denominator equals
10**n, with n unsigned integer, .perl will produce a decimal number.
Otherwise 1/30 would produce a decimal number like 0.0333333..., which
was probably not intended.

Regards,
Ron

Reply via email to