Thread: Few question

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    3

    Few question

    I'm relatively new to programming in C, and i have some questions if I may.

    as i understood, log(q) for example will return a value of double nature with q being double as well, but i noticed i can use q as a floating variable, what difference is there is from using logf(q) or log(q) where q is a floating variable, what will happen if i'm using complex variables ? is this difference is the same between clog(q) and clogf(q) where q is complex floating variable ?

    finaly am i allowed to define a fucntion for example:
    Code:
    complex float example(q)
    {
    float q;
    }
    where q is a real floating variable ?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You can only specify one type for a function return - complex is not an "extension" to the existing float type, so that is not correct. Your overall function is also wrong, as you need to declare what q is OUTSIDE of the braces.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    3
    you mean something like this is wrong?
    as the q should be a complex floating variable?
    Code:
    complex float example( float q)
    {
    complex float Q;
    ...few lines of code
    return Q;
    }
    what about the first few questions?
    Last edited by ziad.sharif; 04-21-2009 at 06:34 AM.

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    3
    in the end how can i fix this code:
    mb,mu,ms are defined outside the function.
    Code:
    complex float hqmb(float q) /*this function will calculate h(mb,q) where mb is the mass of the b quark, and q is the lepton pair invariant mass */
    {
    	m~b=mb/mu;
    	complex float hq;
    	real(hq)=-(4/9)*(log((m~b)^2)-(2/3)-4*((mb/q)^2))-(4/9)*(2+4*((mb/q)^2))*sqrt(fabs(1-4*((mb/q)^2)));
    	if (4*ms^2>q^2)
    	{
    		real(hq)=real(hq)*atan(1/sqrt(4*((mb/q)^2))-1);
    		imag(hq)=0;
    	}
    	else 
    	{
    		real(hq)=real(hq)*(log((1+sqrt(1-4*((mb/q)^2)))/(sqrt(4*((mb/q)^2)))));
    		imag(hq)=(PI/2)*(4/9)*(log((m~b)^2)-(2/3)-4*((mb/q)^2))-(4/9)*(2+4*((mb/q)^2))*sqrt(fabs(1-4*((mb/q)^2)));
    	}
    	return hq;
    }

  5. #5
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    A type is ONE thing, one word. You cannot have a type complex float. You could have a type complex_float, or complexFloat or just complex.
    There is already a definition for complex numbers in a library, but you could also make your own type. For example
    Code:
    typedef struct complex_float
    {
    float real;
    float imaginary;
    } complex_float;
    Dunno if this code makes sense for you

    Then you would use lines like this:
    Code:
    complex_float* hqmb(float q)
    {
    ...
    complex_float* hq;
    //allocate space for hq
    hq->real -= ...    
    hq->imaginary -= ...
    ...
    return hq;
    }

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    For starters, the carat isn't a "power of" marker, so you're going to have to use something in its place. Basically, if you're passing that whole thing off as a string, you're going to need a parser. If you're not passing that whole thing off as a string, then you actually need to use C and not just "math speak".


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM