how to put an array character into the equation?

0

i try to put 8 byte character into the equation causing a lot of error,what i'm supposed to do to make sure the equation can take the static value and produce output in the 8 bytes.

#include <math.h>
#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */

void voltage_measure(void);

void main(void) {

  voltage_measure();

}

void voltage_measure(void) {
   char Van1[8],VA;
   char Vbn[8],VB;
   char Vcn[8],VC;
   char AC[4],ac;
   char BC[4],bc;
   char AB[4],ab;    
   double Vab1,Vab2,Vbc1,Vbc2,Vac1,Vac2;
   double Vab[8],Vbc[8],Vac[8];

   Van1[0]=0xF0;   
   Van1[1]=0x00;
   Van1[2]=0x00;                                  
   Van1[3]=0x00;

   VA=0x000000F0;

   Vbn[0]=0x78;
   Vbn[1]=0x00;
   Vbn[2]=0x00;
   Vbn[3]=0x00;

   VB=0x78;

   Vcn[0]=0x3C;
   Vcn[1]=0x00;
   Vcn[2]=0x00;
   Vcn[3]=0x00;

   VC=0x3C;

   AB[0]=0xB4;
   AB[1]=0x00;

   ab=0xB4;

   AC[0]=0x2D;
   AC[1]=0x00;

   ac=0x2D;

   BC[0]=0x5A;
   BC[1]=0x00;

   bc=0x5A;
   Vab1=(VB*sin(ab))*(VB*sin(ab))  ;
   Vab2=(VA+(VB*cos(ab)))*(VA+(VB*cos(ab)));
   Vab[4]=sqrt(Vab1+Vab2);

   Vbc1=(VC*sin(bc))*(VC*sin(bc));
   Vbc2=(VB+(VC*cos(bc)))*(VB+(VC*cos(bc))) ;
   Vbc[4]=sqrt(Vbc1+Vbc2);

   Vac1=(VC*sin(ac))*(VC*sin(ac));
   Vac2=(VA+(VC*cos(ac)))*(VA+(VC*cos(ac)));
   Vac[4]=sqrt(Vac1+Vac2);
}
c
arrays
asked on Stack Overflow Aug 6, 2009 by (unknown user) • edited Aug 6, 2009 by Chris Lutz

3 Answers

1

This is what I have understood as yet,

  1. you want to do arithmetic with double precision that has several parameters
    • you would like to store the parameters in char variables (maybe to save on space?)
    • I don't know why you try to write VA=0x000000F0; when its a char (1 byte) variable
    • the static value you refer are probably the constants VA etc
    • It might be useful to have all these working in the arithmetic at double precision
    • when you use the sin and sqrt kind of functions, they will work at double anyways
    • you do not have a main function listed here;
    • it would be there in your actual file (that compiles this code)
    • so, i am also assuming you have things like math.h included
      and the math library on the compile command
    • that is, you do get the binary compiled without errors

maybe you can elaborate the problem you are facing a little more?


  1. Update from comment 1.
    When you say, "character with 8 byte array" -- are you trying to create a double with an 8 char array?

    • Update from comment 2. If your answer is in double, you can catch it in a double variable.
      A double is already 8-bytes (on most platforms).
      Is there a special reason to get it into a char array or a byte array?

    • Update from comment 3.
      The link error implies you did include a math library for the linking.
      The header just gives function prototypes for compilation.
      With gcc, it would be -lm on the command line.

    • Update from comment 4.
      To convert a double to an integer value check this page,
      How can I convert a floating-point value to an integer in C?

answered on Stack Overflow Aug 6, 2009 by nik • edited Aug 6, 2009 by nik
0

Is the trouble that plain char on your machine is signed, so numbers such as 0xF0 are treated as -16 instead of +240? Did you know that on some machines, this is what will happen?

answered on Stack Overflow Aug 6, 2009 by Jonathan Leffler
0

Concerning your link error you mentioned in the comments: including math.h is not enough, you have to tell the linker to add the library as well. Try adding "-lm" in your command line.

answered on Stack Overflow Aug 6, 2009 by groovingandi

User contributions licensed under CC BY-SA 3.0