L
lcl_003
Unregistered / Unconfirmed
GUEST, unregistred user!
谁帮我看看这段C代码是啥意思?
我这里有段C代码,不太明白意思,好象是转换浮点数的。
哪位老大给解释一下?
我想在DELPHI里用,谁能帮我该该吗?
S51float FtoS(float f)
{
S51float Sf;
unsigned int temp;
float ftemp;
char exp;
Sf.Exp=Sf.Dflag=Sf.HVal=Sf.LVal=0;
if (f==0)
return(Sf);
if (f<0)
SSf.Dflag=1;
else Sf.Dflag=0;
if (f<0)
f=-f;;
ftemp=f;
exp=0;
if (ftemp>=1)
while(ftemp>=1) {
exp ++;
ftemp=ftemp/2.0;
}
else {
while (ftemp<1) {
exp --;
ftemp=ftemp * 2;
exp = exp + 1;
}
exp +=128;
Sf.Exp=exp;
ftemp=ftemp*65536;
temp=(unsigned int)ftemp;
Sf.HVal = (unsigned char)(temp/256);
Sf.LVal = (unsigned char)(temp%256);
return(Sf);
}
typedef struct {
signed exp:7;
unsigned Dflag:1;
unsinged HVal:8;
unsinged LVal:8;
}S51float;
我这里有段C代码,不太明白意思,好象是转换浮点数的。
哪位老大给解释一下?
我想在DELPHI里用,谁能帮我该该吗?
S51float FtoS(float f)
{
S51float Sf;
unsigned int temp;
float ftemp;
char exp;
Sf.Exp=Sf.Dflag=Sf.HVal=Sf.LVal=0;
if (f==0)
return(Sf);
if (f<0)
SSf.Dflag=1;
else Sf.Dflag=0;
if (f<0)
f=-f;;
ftemp=f;
exp=0;
if (ftemp>=1)
while(ftemp>=1) {
exp ++;
ftemp=ftemp/2.0;
}
else {
while (ftemp<1) {
exp --;
ftemp=ftemp * 2;
exp = exp + 1;
}
exp +=128;
Sf.Exp=exp;
ftemp=ftemp*65536;
temp=(unsigned int)ftemp;
Sf.HVal = (unsigned char)(temp/256);
Sf.LVal = (unsigned char)(temp%256);
return(Sf);
}
typedef struct {
signed exp:7;
unsigned Dflag:1;
unsinged HVal:8;
unsinged LVal:8;
}S51float;