|
Boost : |
Subject: Re: [boost] [Boost-users] [Review] ITL review starts today, February 18th
From: Joachim Faulhaber (afojgo_at_[hidden])
Date: 2010-03-04 12:05:19
2010/3/4 John Reid <j.reid_at_[hidden]>:
>
>
> Joachim Faulhaber wrote:
>>>
>>> What is the meaning of the cardinality of a continuous interval? It seems
>>> to
>>> be defined to be 0? Why not make it only available for discrete domains?
>>
>> Try this:
>>
>> interval<double> x(0.0, 1.0);
>> if(x.cardinality() ==
>> numeric_limits<interval<double>::size_type>::infinity())
>> cout << "cardinality is infinite\n";
>>
>> for doubles a, b with a < b:
>> [a,b).cardinality() == infinity but
>> {[a,a],[b,b]}.cardinality() == 2
>>
>> Function cardinality() has been introduced to make clear: This
>> function yields the number of *elements*, and not the number of
>> iteratable entities in the interval container. For continuous
>> domain_types the cardinality of an interval container can be infinite
>> but it can be finite as well.
>
> This seems to make the cardinality of empty intervals infinite!
> I get this
> output from the code below:
>
> empty interval cardinality is 0
> empty interval cardinality is infinite
> unit interval cardinality is 0
> unit interval cardinality is infinite
> singleton interval cardinality is 1
>
>
> {
> const interval< double > empty_interval;
> cout << "empty interval cardinality is " <<
> empty_interval.cardinality() << "\n";
> if( empty_interval.cardinality() == numeric_limits< interval<
> double >::size_type >::infinity() )
> cout << "empty interval cardinality is infinite\n";
> }
>
> {
> const interval< double > unit_interval( 0.0, 1.0 );
> cout << "unit interval cardinality is " <<
> unit_interval.cardinality() << "\n";
> if( unit_interval.cardinality() == numeric_limits< interval<
> double >::size_type >::infinity() )
> cout << "unit interval cardinality is infinite\n";
> }
>
> {
> const interval< double > singleton_interval( 0.0 );
> cout << "singleton interval cardinality is " <<
> singleton_interval.cardinality() << "\n";
> if( singleton_interval.cardinality() == numeric_limits<
> interval< double >::size_type >::infinity() )
> cout << "singleton interval cardinality is
> infinite\n";
> }
Well, I've looked at my code. It looks correct. The problem seems to be, that
numeric_limits< interval<double >::size_type >::infinity()
maps infinity() to 0.
if(numeric_limits< std::size_t >::infinity()==0)
cout << "infinity()==0";
Sine the test code, that I have done for that only checks for that value
numeric_limits< interval<double >::size_type >::infinity() against
cardinality(),
I didn't detect the problem.
Is there a standard way to deal with this kind of problem?
Regards,
Joachim
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk