10-26-2004, 04:40 PM | #2 (permalink) |
Crazy
Location: here and there
|
POW(3) Linux Programmer's Manual POW(3)
NAME pow, powf, powl - power functions SYNOPSIS #include <math.h> double pow(double x, double y); float powf(float x, float y); long double powl(long double x, long double y); DESCRIPTION The pow() function returns the value of x raised to the power of y. ERRORS The pow() function can return the following error: EDOM The argument x is negative and y is not an integral value. This would result in a complex number. CONFORMING TO SVID 3, POSIX, BSD 4.3, ISO 9899. The float and the long double vari- ants are C99 requirements. SEE ALSO sqrt(3), cbrt(3) 2002-07-27 POW(3) (END)
__________________
# chmod 111 /bin/Laden |
10-28-2004, 04:31 PM | #4 (permalink) |
Crazy
Location: here and there
|
of course if you are using C++ you could overload say ^ to implement the pow function and it would be as easy as s^2 to square s. but i dont really know anything about operator overloading in C and quick searches really provided no information.
__________________
# chmod 111 /bin/Laden |
10-29-2004, 06:43 AM | #6 (permalink) |
Crazy
Location: here and there
|
yeah, in the case of straight up squaring the s*s is definitely faster. but for situations where you need to raise to higher powers or to an unknown power (variable) the pow function would be better.
from what i understand there is no exponentation operator in c because few processors have exponentation instructions.
__________________
# chmod 111 /bin/Laden |
11-11-2004, 11:22 PM | #7 (permalink) |
Upright
Location: Australia
|
Efficiency depends on the implementation of the power raising function.
This is generally done via logarithmic operations. So for small powers like s^2 are done much more quickly as s*s, since this is a quicker operation in itself and saves the setup for a new method call. Once you get into higher powers, it becomes much more efficient to use logarithms, and it gives you an easy way to calculate non-integer powers. |
Tags |
character, number, special, squaring |
|
|