# floats

• 07-07-2003
phptech
floats

is this sentence right?
whats wrong here?

i have 2 floats, and i want to operate, like an exponencial, or
float 1 elevated to float2.

example:

float1=2
float2=1.5

float3 = float1^float2;

is this right/possible? my compiler says thats a wrong sentence, but, how is the right way to do that?

Thanks!!!
• 07-07-2003
ygfperson
Quote:

float3 = float1^float2;

is this right/possible? my compiler says thats a wrong sentence, but, how is the right way to do that?
Just FYI, bitwise operations are only possible on integral types (int, long, char, short int).
• 07-07-2003
phptech
floats again
Could someone help me?

Imagine that i have the case:

int a = 2;

int b = 2;

int c;

so, once c = a^b, then c = 4, right?

but, when i make this-like operation with two floats, like:

float a = 1.25;
float b = 2.53;
float c;

and i want the same thing, like

c = a^b;

but with floats it does not work.

so, is there any way to do that? i tried to use pow(), but i`ve had the message: function has no prototype, even including the math.h library. is there any other way???

• 07-07-2003
Dave_Sinkula
>so, once c = a^b, then c = 4, right?

No, 2 XORed with 2 is 0. In C, you get x to the power of y with the pow() function.
Code:

```#include <stdio.h> #include <math.h> int main(void) {   double x = 2.0, y = 1.5, z = pow(x,y);   printf("pow(%g,%g) = %g\n", x, y, z);   return 0; } /* my output pow(2,1.5) = 2.82843 */```
• 07-07-2003
damonbrinkley
Thise code works just fine for me using cygwin.

Code:

```#include <math.h> #include <stdio.h> int main() {         double x = 1.25;         double y = 2.22;                 printf("x raised to y is %f\n", pow(x,y));         return 0; }```
For future reference, the ^ symbol in C means bitwise exclusive OR and not exponentiation.

Also, why create another thread on the exact same topic?
• 07-07-2003
quzah
Quote:

Originally posted by damonbrinkley
Also, why create another thread on the exact same topic?
Because they either:
a) Didn't care enough to actually read their post again.
b) Didn't like the answer they got in the first thread, telling them the exact same thing they were told in this one.

Quzah.
• 07-07-2003
phptech
not really...
Not really like that....i`ve made that (2 questions of the exact same topic) just because i thought the other one was old (i posted it on the morning), and i thought the most actual were read first. (at least, this is the way other discussion boards i know work).

But i`m taking the way of this one. And i dont want to be boring, but u really are helpful, and all i have to say is thank you all....

you are helping me to turn myself in a person which tomorrow will be here helping other dummies =)

so, i`ll be less repetitive, ok =)

thanks, and sorry!