Error: extra parameters when calling function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • astri
    New Member
    • Feb 2007
    • 10

    Error: extra parameters when calling function

    Code:
    #include "Unit1.h"
    #include "math.h"
    #include "fixed_math.hpp"
    #include "algorithm.h"
    #define MBIT 0x4000
    #define CBIT 16
    
    long    constbl[CBIT];
    
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    
            AnsiString buf;
    
    
            int i;
            long lx,ly, lz;
            float fz,x,y;
            void cordic();
    
            x=1.0;
            for (i=0; i<CBIT; i++)
            {
    
            constbl[i]=atan(x)*MBIT;
            x *=0.5;
    
            }
    
            Memo1->Lines->Add("CORDICのよるarctanの計算");
            Memo1->Lines->Add("tanの値はYとXの比で入力する");
            Memo1->Lines->Add("正し 0<=Y<=1, 0<=X<=1とする");
    
    
            for(;;)
            {
            Memo1->Lines->Add("Y=?");
            Memo1->Lines->Add(buf.sprintf("%5.2f",y));
            Memo1->Lines->Add("X=?");
            Memo1->Lines->Add(buf.sprintf("%5.2f",x));
    
    
            if ( x>1.0 || x<0.0) exit (0);
            if ( y>1.0 || y<0.0) exit (0);
    
            lx = x*MBIT;
            ly = y*MBIT;
            lz = 0;
            [B]cordic(lx,ly,lz);[/B]  ------> in this line causing error
            fz = (float)lz/MBIT;
    
            Memo1->Lines->Add(buf.sprintf("arctan(y/x)=%5.2f",fz));
    
    
            }
    
    }
    
    /* CORDIC m=1, y-->0 */
    
    void cordic(x,y,z)
    long *x, *y, *z;
    {
            int i;
            long xx, yy, zz;
    
            for(i=0; i<CBIT ; i++)
            {
    
                    if( *y>=0)
                    {
                            xx = *x + (*y>>i);
                            yy = *y - (*x>>i);
                            zz = *z + constbl[i];
    
                    }
                    else
                    {
                            xx = *x - (*y>>i);
                            yy = *y + (*x>>i);
                            zz = *z - constbl[i];
                    }
            *x = xx;
            *y = yy;
            *z = zz;
    
            }
    
    }
    I keep getting error message when calling CORDIC function. It is said that "There`s an extra parameters when calling function"

    I dont understand? because in the cordic function i declare it with three parameters and i`m calling cordic function with 3 parameters too..so where`s the problem??
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    the cordic() function prototype shows it as having no parameters, e.g.
    Code:
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    
            AnsiString buf;
    
    
            int i;
            long lx,ly, lz;
            float fz,x,y;
            void cordic();    <<<<<<   ???

    Comment

    • astri
      New Member
      • Feb 2007
      • 10

      #3
      Originally posted by horace1
      the cordic() function prototype shows it as having no parameters, e.g.
      Code:
      void __fastcall TForm1::Button1Click(TObject *Sender)
      {
      
              AnsiString buf;
      
      
              int i;
              long lx,ly, lz;
              float fz,x,y;
              void cordic();    <<<<<<   ???
      i try to declare function prototype with

      Code:
      void cordic(x,y,fz);
      but error comes up and said that x was not declared

      i try to erase the function prototype

      Code:
      long    constbl[CBIT];
      
      /* CORDIC m=1, y-->0 */
      
      void cordic(long *x, long *y, long *z)
      {
      
              int i;
              long xx, yy, zz;
      
      
              for(i=0; i<CBIT ; i++)
              {
      
                      if( *y>=0)
                      {
                              xx = *x + (*y>>i);
                              yy = *y - (*x>>i);
                              zz = *z + constbl[i];
      
                      }
                      else
                      {
                              xx = *x - (*y>>i);
                              yy = *y + (*x>>i);
                              zz = *z - constbl[i];
                      }
              *x = xx;
              *y = yy;
              *z = zz;
      
              }
      
      }
      
      
      void __fastcall TForm1::Button1Click(TObject *Sender)
      {
      
              AnsiString buf;
      
      
              int i;
              long lx,ly, lz;
              float fz,x,y;
              void cordic(x,y,fz);
      
              x=1.0;
              for (i=0; i<CBIT; i++)
              {
      
                  constbl[i]=atan(x)*MBIT;
                  x *=0.5;
      
              }
      
              Memo1->Lines->Add("CORDICのよるarctanの計算");
              Memo1->Lines->Add("tanの値はYとXの比で入力する");
              Memo1->Lines->Add("正し 0<=Y<=1, 0<=X<=1とする");
      
      
              for(float y=0.0; y<= 1.0 ; y=y+0.1)
              {
                  Memo1->Lines->Add("Y=?");
                  Memo1->Lines->Add(buf.sprintf("%5.2f",y));
                  Memo1->Lines->Add("X=?");
                  Memo1->Lines->Add(buf.sprintf("%5.2f",x));
      
      
                  if ( x>1.0 || x<0.0) exit (0);
                  if ( y>1.0 || y<0.0) exit (0);
      
                  lx = x*MBIT;
                  ly = y*MBIT;
                  lz = 0;
                  cordic(&lx,&ly,&lz);
                  fz = (float)lz/MBIT;
      
                  Memo1->Lines->Add(buf.sprintf("arctan(y/x)=%5.2f",fz));
      
      
              }
      
      }
      the program works but i think the calculation is not right. What i m trying to make is arctan function with CORDIC algorithm. Is that my program counting wrong?

      does anyone had making this kind of program?

      *ps i m using Borland c++ Builder

      Comment

      • horace1
        Recognized Expert Top Contributor
        • Nov 2006
        • 1510

        #4
        Originally posted by astri
        i try to declare function prototype with
        Code:
        void cordic(x,y,fz);
        but error comes up and said that x was not declared
        in the above statement the compiler thinks you are trying to call the function

        in the function prototype you must declare the parameter types (names are not necessary)
        Code:
        void cordic(l ong *x, long *y,  long *z);

        Comment

        • horace1
          Recognized Expert Top Contributor
          • Nov 2006
          • 1510

          #5
          if I run a cut down version of your program
          Code:
          #include <math.h>
          
          #define CBIT 50
          #define MBIT 50
          long    constbl[CBIT];
          
          /* CORDIC m=1, y-->0 */
          
          void cordic(long *x, long *y, long *z)
          {
                  int i;
                  long xx, yy, zz;
                  for(i=0; i<CBIT ; i++)
                  {
                          if( *y>=0)
                          {
                                  xx = *x + (*y>>i);
                                  yy = *y - (*x>>i);
                                  zz = *z + constbl[i];
                          }
                          else
                          {
                                  xx = *x - (*y>>i);
                                  yy = *y + (*x>>i);
                                  zz = *z - constbl[i];
                          }
                  *x = xx;
                  *y = yy;
                  *z = zz;
                  }
          }
          
          
          int main()
          {
          
                  int i;
                  long lx,ly, lz;
                  float fz,x,y;
               //   void cordic(x,y,fz);
          
                  x=1.0;
                  for (i=0; i<CBIT; i++)
                  {
                      constbl[i]=atan(x)*MBIT;
                      x *=0.5;
                  }
          
                 // printf("CORDIC???arctan???");
                //  printf("tan???Y?X???????");
                 // printf("??0<=Y<=1, 0<=X<=1???");
          
          
                 // for(float y=0.0; y<= 1.0 ; y=y+0.1)
                  {
                      printf("Y=?");
                      scanf("%f", &y);
                      printf("%5.2f\n",y);
                      printf("X=?");
                      scanf("%f", &x);
                      printf("%5.2f\n",x);
          
                      if ( x>1.0 || x<0.0) exit (0);
                      if ( y>1.0 || y<0.0) exit (0);
          
                      lx = x*MBIT;
                      ly = y*MBIT;
                      lz = 0;
                      cordic(&lx,&ly,&lz);
                      fz = (float)lz/MBIT;
          
                      printf("arctan(y/x)=%5.2f\n",fz);
                      printf("atan(y/x)=%5.2f\n", (float) atan(y/x));
                  }
          getchar();getchar();
          }
          it seems to give answers similar to the atan() from <math.h>, e.g. a few runs
          Y=? .2
          0.20
          X=? .8
          0.80
          arctan(y/x)= 0.24

          Y=? 0.50
          X=? 0.50
          arctan(y/x)= 0.80
          atan(y/x)= 0.79

          Y=? 0.80
          X=? 0.20
          arctan(y/x)= 1.32
          atan(y/x)= 1.33

          atan(y/x)= 0.24

          Comment

          Working...