Velocity Reviews > A Revised Rational Proposal

# A Revised Rational Proposal

John Roth
Guest
Posts: n/a

 12-27-2004

"Mike Meyer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Nick Coghlan <(E-Mail Removed)> writes:
>
>> Mike Meyer wrote:
>>> Yup. Thank you. This now reads:
>>> Regarding str() and repr() behaviour, repr() will be either
>>> ''rational(num)'' if the denominator is one, or ''rational(num,
>>> denom)'' if the denominator is not one. str() will be either ''num''
>>> if the denominator is one, or ''(num / denom)'' if the denominator is
>>> not one.
>>> Is that acceptable?

>>
>> Sounds fine to me.
>>
>> On the str() front, I was wondering if Rational("x / y") should be an
>> acceptable string input format.

>
> I don't think so, as I don't see it coming up often enough to warrant
> implementing. However, Rational("x" / "y") will be an acceptable
> string format as fallout from accepting floating point string
> representations.

How would that work? I though the divide would be
evaluated before the function call, resulting in an exception
(strings don't implement the / operator).

John Roth
>
> <mike
> --
> Mike Meyer <(E-Mail Removed)> http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more
> information.

Mike Meyer
Guest
Posts: n/a

 12-28-2004
"John Roth" <(E-Mail Removed)> writes:

> "Mike Meyer" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Nick Coghlan <(E-Mail Removed)> writes:
>>
>>> Mike Meyer wrote:
>>>> Yup. Thank you. This now reads:
>>>> Regarding str() and repr() behaviour, repr() will be either
>>>> ''rational(num)'' if the denominator is one, or ''rational(num,
>>>> denom)'' if the denominator is not one. str() will be either ''num''
>>>> if the denominator is one, or ''(num / denom)'' if the denominator is
>>>> not one.
>>>> Is that acceptable?
>>>
>>> Sounds fine to me.
>>>
>>> On the str() front, I was wondering if Rational("x / y") should be an
>>> acceptable string input format.

>>
>> I don't think so, as I don't see it coming up often enough to warrant
>> implementing. However, Rational("x" / "y") will be an acceptable
>> string format as fallout from accepting floating point string
>> representations.

>
> How would that work? I though the divide would be
> evaluated before the function call, resulting in an exception
> (strings don't implement the / operator).

That was a mistake on my part. It would be Rational("x", "y").

<mike

--
Mike Meyer <(E-Mail Removed)> http://www.mired.org/home/mwm/