|
Boost : |
From: Paul Moore (gustav_at_[hidden])
Date: 2001-01-21 17:33:27
On 15 Jan 2001, at 21:43, Stephen Silver wrote:
> I've written a program that runs a hundred or so simple tests on
> boost::rational. In addition to the operator< bugs that I posted
> yesterday, this test program found problems with lcm() (sometimes
> returns negative numbers, and lcm(0,0) causes division by zero),
> and with operator>> (input errors not always handled correctly).
lcm bugs fixed. However, I think you are mistaken over the
operator>> errors - remember that >> consumes as much input as
it can, only setting the error state if it cannot construct a valid value.
Your example
std::istringstream iss("57A");
iss >> r0;
consumes "57". This is a valid representation of a rational, namely
57/1, so r0 is set to this, and the stream is in a good state.
Similarly,
std::istringstream iss("20-20");
iss >> r0;
sets r0 to 20, and leaves "-20" to be read, without signalling an
error.
I don't see how I could give behaviour consistent with other types,
unless I disallowed constructing a rational from a stream containing
a plain integer (which I don't want to do).
Paul.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk