[reSIProcate] representing qvalues as integers instead of floats

Dan Weber dan at mirrorlynx.com
Thu Aug 11 19:09:31 CDT 2005


Adam Roach wrote:

>
> I am trying to suss out what *Dan* is proposing -- in particular what 
> he means by "use an enum".
>
> /a

I was merely proposing to use a way where the compiler could keep type 
checking.  Another way would be to use a little bit of templates to keep 
type checking working, however, I'm not sure how to trigger a compiler 
warning/error when the number is out of range.  So you could just return 0.


template <float f> inline int func() {
    if (f <= 1.0 && f >= 0)
         return static_cast<int>(f*1000.0);
    else
         return 0;
}

template <int i> inline int func() {
    if (i <=  1000 && i >= 0)
        return i;
    else
        return 0;
}

Dan



More information about the resiprocate-devel mailing list