I tried your class, iMalc, and everything seems to work like it does for floats or doubles, except from the ?: operator, just like for the class I defined.
Also, I had to change the return value for the conversion operator to value, since it returned retVal which was undefined. And to generate a NaN, on all machines that support IEEE floating point there is a macro defined in <math.h> called NAN that will do that (maybe that is what you would use in practice).
As of the problem with the ?: operator: I have the following code
where b, c and d are ftype objects, where ftype is defined as
ftype a = MIN(b - c, d);
and MIN is a macro defined as
typedef nanInit<float> ftype
However, the code won't compile, and the message I'm getting from the compiler is:
#define MIN(x, y) ((x) <= (y) ? (x) : (y))
Converting d to float works but is bad, because the definition of ftype may change.
error: operands to ?: have different types 'double' and 'pftype'
I may instead convert b - c back to ftype, so I have
which is better, because that code is independent of the definition of ftype.
ftype a = MIN(ftype(b - c), d);
However, my project is quite small and I have already had to change on 21 places in the code just becase I changed the definition of ftype from float to nanInit<float>. For larger projects, there could be a lot more work than this that would be necessary just for changing the typedef of ftype (or a corresponding typename), which kind of feels unnecessary. Is there really no way to get around this problem?