Re: Whose idea to make it a function?
"Alf P. Steinbach" wrote:
* kanze:
[...]
Oh, let's have back the good old days of emulation and a
zillion different floating point types, it was much more /interesting/!
FWIW: at least one platform I'm aware of does have two distinct
floating point implementations for double. Modern avatars of
the IBM 390 support both IEEE floating point and the classical
IBM floating point. I'm not too familiar with the details of
how you select; I think it is a flag in a program status word
somewhere. If you can change the selection during program
execution, however, it should lead to some interesting
questions:
setFloatingPointMode( IBM_special::classic ) ;
double d1 = std::numeric_limits<double>::max() ;
setFloatingPointMode( IBM_special::IEEE ) ;
double d2 = std::numeric_limits<double>::max() ;
assert( d1 == d2 ) ; // Will fail !!!
or
setFloatingPointMode( IBM_special::IEEE ) ;
double d1 = std::numeric_limits<double>::max() ;
setFloatingPointMode( IBM_special::classic ) ;
// What is the value of d1 now? The max value of an IEEE
// double is not representable in a classic IBM double.
I rather suspect that in such an implementation, the effect of
calling the implementation defined function setFloatingPointMode
would be to invalidate all existing floating point values in the
program, so that both of these examples would display undefined
behavior. (I can't see any other way to define it. Changing
the floating point mode will not change the bit patterns in
variables in memory.)
Of course, there's still something I don't understand here. By
my reasoning, the same logic which leads to declaring max a
function also applies to digits and digits10 (and in the case
above, to radix). None of which are functions.
Note that the C standard handles this a bit differently. All of
the values in <limits.h>, and all of the integral values in
<float.h> (with one exception), must be constant expressions
suitable for use in #if preprocessing directives, and all
floating values in <float.h> must be constant expressions.
Given this, I'm not sure why the function in C++.
Unless, of course, the real reason is to allow instantiation for
user defined types, for which constant expressions may not be
possible. Looking at it, the values with type T are functions,
and the others not, so this is possibly a more likely
explination.
--
James Kanze GABI Software
Conseils en informatique orient9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S9mard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]