Tilted Forum Project Discussion Community

Tilted Forum Project Discussion Community (https://thetfp.com/tfp/)
-   Tilted Technology (https://thetfp.com/tfp/tilted-technology/)
-   -   Is there a special character for squaring a number? (https://thetfp.com/tfp/tilted-technology/73951-there-special-character-squaring-number.html)

zero2 10-26-2004 04:23 PM

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)

theFez 10-26-2004 04:40 PM

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)

zero2 10-28-2004 11:21 AM

thanks for the help.

theFez 10-28-2004 04:31 PM

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.

jk777 10-28-2004 05:58 PM

The code is much faster if you use s*s (relatively speaking).

theFez 10-29-2004 06:43 AM

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.

archer 11-11-2004 11:22 PM

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.

nlong 11-12-2004 11:49 AM

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 03:50 PM.

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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54