GMP suggestions

Nic Schraudolph nic at schraudolph.org
Mon May 24 12:34:46 CEST 2010


>>> This already works currently: is_bounded and has_infinity are  
>>> false by default for types without an explicit specialization.
>>
>> No. Without explicit specialization, is_specialized is false, which  
>> implies that the correct interpretation should be "unknown" for all  
>> other numeric_limits info.
>
> In your code snippet, you only care about true vs "not known to be  
> true", so unknown or false are equivalent, and unknown happens to  
> imply the thing is set to false :-)

This happens to work for my code snippet, but not in general. For  
instance, there's a huge difference between "unbounded" and "bounded  
but I don't know the bound", but without a numeric_limits  
specialization the two cases are indistinguishable.

IMO the default template should really return is_bounded = true and  
max() = 0 to indicate that the bound is unknown, but that's an issue  
for the standards committees...

In the code I'm converting I'm at present reduced to using an  
arbitrary "large" number as upper bound, which for mpq is an idiotic  
waste of memory and CPU cycles, in addition to being a ticking time  
bomb a la "640kB should be enough for anyone". In short, I do have a  
use case where implementing infinity for mpq is the most viable  
solution. I'll look into it.

> The C++0X standard says that the information provided by  
> numeric_limits has to be compile-time constants. The situation is  
> clear for digits, less so for min/max/epsilon/round_error (constants  
> don't really make sense for a complex type like mpf_class).

Didn't know that, thanks. I agree that for mpf_class the situation is  
much murkier than for mpz_class and mpq_class, due to the mismatch  
with the preconceptions encoded into numeric_limits.

Best,

- nic



More information about the gmp-discuss mailing list