tags:

views:

219

answers:

3

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);
}
+1  A: 

This is what I have understood as yet,

  1. you want to do arithmetic with double precision that has several parameters
  2. you would like to store the parameters in char variables (maybe to save on space?)
  3. I don't know why you try to write VA=0x000000F0; when its a char (1 byte) variable
  4. the static value you refer are probably the constants VA etc
  5. 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
  6. 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?

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

  3. 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.

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

nik
actually in this programming i try to created character with 8 byte array,and than the value Va is only the combination of the array,so what can i do so that the char value can be put into the equation.
from the calculation the answer must be in double.so i need to created a double with an 8 char array.is that possible..
@kiki: double VA = Van[0] + (Van[1] * pow(2, 8)) + (Van[2] * pow(2,16)) + (Van[3] * pow(2,24)) ...;
Inshallah
i also do not know what the special reason..i just been asked to do it so.i was facing the link error when i try to compile..it say that "sin"is undefined but i already include the math.h
do you know ow to assign values to a UINT8 variable?
A: 

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?

Jonathan Leffler
A: 

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.

groovingandi