Floating point operand?

This is a discussion on Floating point operand? within the C Programming forums, part of the General Programming Boards category; I written a code to work out the coordinates on a bezier curve but i keep getting the same errors, ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    13

    Arrow Floating point operand?

    I written a code to work out the coordinates on a bezier curve but i keep getting the same errors,"0022/0023/0023/0024/0025 ERROR:A floating point operand to ^ is not permitted"

    Code:
    #include<stdio.h>
    #include<math.h>
    
    main()
    {
    float u,g,p,r,s,t,x,y;
    int xr0,xr1,xr2,xr3,yr0,yr1,yr2,yr3,w0,w1,w2,w3;
    
    u=0;
    
    
    printf("Enter in r values for the x coordinates e.g. xr0,xr1,xr2,xr3");
    scanf("%d,%d,%d,%d",&xr0,&xr1,&xr2,&xr3);
    printf("Enter in r values for the y coordinates e.g. yr0,yr1,yr2,yr3");
    scanf("%d,%d,%d,%d",&yr0,&yr1,&yr2,&yr3);
    printf("Enter in w values e.g. w0,w1,w2,w3");
    scanf("%d,%d,%d,%d",&w0,&w1,&w2,&w3);
    
    
    if (u>0,u<1,u+0.2)
    {
    p=((1-u)^3);//line 22//
    g=(3*(1-u)^2*u);//line 23//
    s=(3*(1-u)*u^2);//line 24//
    t=(u^3);//and surprisingly line 25//
    
    x=((p*w0*xr0)+(g*w1*xr1)+(s*w2*xr2)+(t*w3*xr3))/((p*w0)+(g*w1)+(s*w2)+(t*w3));
    printf("/n",x);
    
    y=((p*w0*yr0)+(g*w1*yr1)+(s*w2*yr2)+(t*w3*yr3))/((p*w0)+(g*w1)+(s*w2)+(t*w3));
    printf("/t",y);
    
    }
    else
    return 0;
    
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,823
    ^ isn't raise to power of in C, its exclusive-or. See also bitwise and(&) and or(|)

    Include math.h, and use things like
    pow(1-u,2)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    13
    I think the powers work fine now, thanks for the help. Now the program isnt workin right, it now works fine until it gets to the if statement which is now completely ignored and it just ends the program without printing any results.
    Code:
    #include<stdio.h>
    #include<math.h>
    
    main()
    {
    float u,g,p,s,t,x,y;
    int xr0,xr1,xr2,xr3,yr0,yr1,yr2,yr3,w0,w1,w2,w3;
    
    u=0;
    
    
    printf("Enter in r values for the x coordinates e.g. x0,x1,x2,x3\n");
    scanf("%d,%d,%d,%d",&xr0,&xr1,&xr2,&xr3);
    printf("Enter in r values for the y coordinates e.g. y0,y1,y2,y3\n");
    scanf("%d,%d,%d,%d",&yr0,&yr1,&yr2,&yr3);
    printf("Enter in w values e.g. w0,w1,w2,w3\n");
    scanf("%d,%d,%d,%d",&w0,&w1,&w2,&w3);
    
    
    if (u=0,u<1)
            {
            p=(pow(1-u,3));
            g=(3*(pow(1-u,2)*u));
            s=(3*pow((1-u)*u,2));
            t=pow(u,3);
    
            x=((p*w0*xr0)+(g*w1*xr1)+(s*w2*xr2)+(t*w3*xr3))/((p*w0)+(g*w1)+(s*w2)+(t*w3));
            printf("\n",x);
    
            y=((p*w0*yr0)+(g*w1*yr1)+(s*w2*yr2)+(t*w3*yr3))/((p*w0)+(g*w1)+(s*w2)+(t*w3));
            printf("\t",y);
            u=(u+0.2);
            }
    else
    return 0;
    
    }

  4. #4
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Code:
    #include<stdio.h>
    #include<math.h>
    
    int main(void) /* main returns an int */
    {
        float u, g, p, s, t, x, y;
        int xr0, xr1, xr2, xr3, yr0, yr1, yr2, yr3, w0, w1, w2, w3;
    
        u = 0;
    
    
        printf("Enter in r values for the x coordinates e.g. x0,x1,x2,x3\n");
        scanf("%d,%d,%d,%d", &xr0, &xr1, &xr2, &xr3);
        printf("Enter in r values for the y coordinates e.g. y0,y1,y2,y3\n");
        scanf("%d,%d,%d,%d", &yr0, &yr1, &yr2, &yr3);
        printf("Enter in w values e.g. w0,w1,w2,w3\n");
        scanf("%d,%d,%d,%d", &w0, &w1, &w2, &w3);
    
    
        if (u = 0, u < 1) {
    	p = (pow(1 - u, 3));
    	g = (3 * (pow(1 - u, 2) * u));
    	s = (3 * pow((1 - u) * u, 2));
    	t = pow(u, 3);
    
    	x = ((p * w0 * xr0) + (g * w1 * xr1) + (s * w2 * xr2) +
    	     (t * w3 * xr3)) / ((p * w0) + (g * w1) + (s * w2) + (t * w3));
    	printf("\n%f", x); /* you might want a format specifier here */ 
    
    	y = ((p * w0 * yr0) + (g * w1 * yr1) + (s * w2 * yr2) +
    	     (t * w3 * yr3)) / ((p * w0) + (g * w1) + (s * w2) + (t * w3));
    	printf("\t%f\n\n", y); /* another format specifier here */ 
    	u = (u + 0.2);
        }
    
    /* You don't have to use the 'else' clause with an if statement */
    
        return 0;
    
    }
    Also, you should consider getting your input in another way besides using scanf(). But that's another story.

    ~/

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    12
    Sorry to go off topic but how does

    if(u = 0, u < 1) work? What does ',' do here ? Is it the same as
    if(u = 0 && u < 1) ?

    Also shouldn't it be u == 0 rather than u = 0 ?
    Life is a piece of chocolates

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,823
    > if(u = 0, u < 1) work?
    Probably not as they wanted
    Assign u the value of 0, then compare u to 1

    Since it is now 0, the comparison is true, so its really
    u = 0;
    if ( 1 )

    But then u started off with the value of 0, and was unmodified by any of the scanf() calls, so the whole 'u' and if() thing is redundant.

    However, looking further on, it seems they really want
    Code:
    for ( u = 0 ; u < 1 ; u += 0.2 ) {
    	p = (pow(1 - u, 3));
    	g = (3 * (pow(1 - u, 2) * u));
    	s = (3 * pow((1 - u) * u, 2));
    	t = pow(u, 3);
    	// etc...
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Jan 2004
    Posts
    13
    Thanks for all the help, the program works perfectly now:
    Code:
    #include<stdio.h>
    #include<math.h>
    
    int main(void) 
    {
        float u, g, p, s, t, x, y;
        int xr0, xr1, xr2, xr3, yr0, yr1, yr2, yr3, w0, w1, w2, w3;
        u = 0;
    
        printf("Enter in r values for the x coordinates e.g. x0,x1,x2,x3\n");
        scanf("%d,%d,%d,%d", &xr0, &xr1, &xr2, &xr3);
        printf("Enter in r values for the y coordinates e.g. y0,y1,y2,y3\n");
        scanf("%d,%d,%d,%d", &yr0, &yr1, &yr2, &yr3);
        printf("Enter in w values in the format w0,w1,w2,w3\n");
        scanf("%d,%d,%d,%d", &w0, &w1, &w2, &w3);
    
    for ( u = 0 ; u < 1 ; u += 0.2 ) {
            p = (pow(1 - u, 3));
            g = (3 * (pow(1 - u, 2) * u));
            s = (3 * pow((1 - u) * u, 2));
            t = pow(u, 3);
    
            x = ((p * w0 * xr0) + (g * w1 * xr1) + (s * w2 * xr2) + (t * w3 * xr3)) / ((p * w0) + (g * w1) + (s * w2) + (t * w3));
            printf("For u = %f:   ", u);
            printf("\nx  =  %f", x); 
    
            y = ((p * w0 * yr0) + (g * w1 * yr1) + (s * w2 * yr2) + (t * w3 * yr3)) / ((p * w0) + (g * w1) + (s * w2) + (t * w3));
            printf("\ty  =  %f\n\n", y);
            }
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal places on Floating point number
    By manutdfan in forum C Programming
    Replies: 1
    Last Post: 10-29-2006, 12:56 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  3. floating point question
    By Eric Cheong in forum C Programming
    Replies: 8
    Last Post: 09-10-2004, 11:48 PM
  4. 2 questions about floating point and %
    By ams80 in forum C Programming
    Replies: 2
    Last Post: 08-14-2002, 11:55 AM
  5. Replies: 2
    Last Post: 09-10-2001, 01:00 PM

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