floats

This is a discussion on floats within the C Programming forums, part of the General Programming Boards category; Please... is this sentence right? whats wrong here? i have 2 floats, and i want to operate, like an exponencial, ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    18

    floats

    Please...

    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!!!

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    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).

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    18

    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???

    Please....

    Thanks in advance

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >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
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    385
    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?
    Last edited by damonbrinkley; 07-07-2003 at 08:14 PM.
    Wandering aimlessly through C.....

    http://dbrink.phpwebhosting.com

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    18

    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!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. variables larger than floats
    By a.mlw.walker in forum C Programming
    Replies: 13
    Last Post: 04-23-2009, 02:28 AM
  2. Reading errors in floats
    By Improvolone in forum C++ Programming
    Replies: 8
    Last Post: 03-21-2006, 02:20 PM
  3. % and floats
    By confuted in forum C++ Programming
    Replies: 2
    Last Post: 08-04-2003, 09:41 PM
  4. comparing two arrays of floats
    By COBOL2C++ in forum C++ Programming
    Replies: 7
    Last Post: 07-16-2003, 03:22 AM
  5. Using floats in conditional statements
    By DBB in forum C++ Programming
    Replies: 3
    Last Post: 09-12-2001, 07:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21