Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 10-26-2004, 04:23 PM   #1 (permalink)
Junkie
 
zero2's Avatar
 
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)
zero2 is offline  
Old 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
theFez is offline  
Old 10-28-2004, 11:21 AM   #3 (permalink)
Junkie
 
zero2's Avatar
 
thanks for the help.
zero2 is offline  
Old 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
theFez is offline  
Old 10-28-2004, 05:58 PM   #5 (permalink)
Upright
 
The code is much faster if you use s*s (relatively speaking).
jk777 is offline  
Old 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
theFez is offline  
Old 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.
archer is offline  
Old 11-12-2004, 11:49 AM   #8 (permalink)
Upright
 
pow = suck. Pow introduces a significant slowdown. hardocde the instruction s*s. unless you will be using an exponent other than 2.
nlong is offline  
 

Tags
character, number, special, squaring


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 08:43 PM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76