![]() |
Is there a special character for squaring a number?
Im using c as the programming language, and the formula I have calls for s to be squared {s*s}, other than just typing s*s is there a special symbol for squaring?
s2 + p * (s - x) * (p + y) |
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) |
thanks for the help.
|
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.
|
The code is much faster if you use s*s (relatively speaking).
|
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. |
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. |
pow = suck. Pow introduces a significant slowdown. hardocde the instruction s*s. unless you will be using an exponent other than 2.
|
All times are GMT -8. The time now is 04:18 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project