Fast square method using c++ templates
If you often need to calculate the square of a value you will realize that using pow(x, 2.0) from
math.h is not the fastest opportunity.
There are fastpow() implementions, some people use exp and log, and some people just write x*x in their code.
For the last case here is a small c++ template which reduces the effort to write x*x for long expressions of x:
template <class T>
inline T square(T value) {
return value*value;
}
Written by Daniel Wehner
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#C
Authors
Related Tags
#c
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#