恭喜,你发布的帖子
发布于 2015-12-10 23:58:49
3楼
增加了SCL的程序:已测试
FUNCTION FC6 : REAL
// Block Parameters
VAR_INPUT
IN:ARRAY[1..2]OF DWORD;
END_VAR
VAR_IN_OUT
// I/O Parameters
END_VAR
VAR_OUTPUT
// Output Parameters
END_VAR
VAR_TEMP
S:DWORD;
E:REAL;
M:REAL;
M_TMP:REAL;
TEMP0:DWORD;
TEMP1:INT;
i:INT;
END_VAR
BEGIN
//***********************S*********************//
TEMP0:=SHR(IN:=IN[1],N:=31) ;
IF TEMP0 = 1 THEN
S:=DW#16#80000000;
ELSE
S:=0;
END_IF;
//**********************E***************************//
TEMP0:=SHR(IN:=IN[1],N:=20);
TEMP1:=DWORD_TO_INT(w#16#7ff & TEMP0);
E:=2**(TEMP1-1023);//E:=EXP(TEMP1*LN(2));
//*************************M**************************8
TEMP0:=IN[1] AND DW#16#FFFFF;
M:=0;
FOR i:=20 TO 1 BY -1 DO
IF DWORD_TO_BOOL(TEMP0 AND DW#16#1) = TRUE THEN
M_TMP:=1/2**i;
M:=M+M_TMP;
END_IF;
TEMP0:=SHR(IN:=TEMP0,N:=1);
END_FOR;
//********************************************8
TEMP0:=IN[2];
FOR i:=32 TO 1 BY -1 DO
IF DWORD_TO_BOOL(TEMP0 AND DW#16#1) = TRUE THEN
M_TMP:=1/2**(i+20);
M:=M+M_TMP;
END_IF;
TEMP0:=SHR(IN:=TEMP0,N:=1);
END_FOR;
//**********************************
FC6 := DWORD_TO_REAL(S OR REAL_TO_DWORD(E*(1.0+M)));
END_FUNCTION
请填写推广理由:
分享
只看
楼主