20 May 18:14
[math] pow redux and observations
From: John Moeller <fishcorn <at> gmail.com>
Subject: [math] pow redux and observations
Newsgroups: gmane.comp.lib.boost.devel
Date: 2008-05-20 16:18:27 GMT
Subject: [math] pow redux and observations
Newsgroups: gmane.comp.lib.boost.devel
Date: 2008-05-20 16:18:27 GMT
I noticed that the trunk now has corrections for pow<N> to reduce template instantiations. However, the "N=1" specialization isn't correct. The second template parameter (bool odd) should be "true," not "false." I could be mistaken that 1 is an odd number, though.As it is now, the whole template would work, but would ignore the 1/false specialization and create a new 1/true specialization that just multiplies "base" by the result of 0/false. Changing 1/false to 1/true will just cause it to return "base," as desired. Note also, please, that positive_power<0,false> returns 1 when base is 0. Since 0^0 is technically undefined, the "N=0" case should probably be handled at a higher level (in power_if_positive, perhaps), and cause an error, just like negative powers of 0. If that is done, the 0/false case could be removed from positive_power. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
As it is now, the whole template would work, but would ignore the 1/false
specialization and create a new 1/true specialization that just multiplies
"base" by the result of 0/false. Changing 1/false to 1/true will just cause it
to return "base," as desired.
Note also, please, that positive_power<0,false> returns 1 when base is 0. Since
0^0 is technically undefined, the "N=0" case should probably be handled at a
higher level (in power_if_positive, perhaps), and cause an error, just like
negative powers of 0. If that is done, the 0/false case could be removed from
positive_power.
_______________________________________________
Unsubscribe & other changes:
Indeed they seem to contradict themselves a bit...
> Grrr, still not sure what to do here, how about:
>
RSS Feed