REAL64

: 2014-07-22

: komatic

: SCL



add64



real64 (PCS7). 32 , - . real64 .





add64



PIDConR - .







Name: F354
Symbolic Name: AddR64
Symbol Comment: Addition of two 64-bit REAL variables
Family: System
Version: 2.0
Author: AdvLib80
Last modified: 07/04/2011
Use: FC353, FC362, FC370, FC371
Size: 1966 bytes
Signature: generiert vom SCL bersetzer Version: SCLCOMP K05.03.07.00_01.02.00.01 release



{
Scl_ResetOptions ;
Scl_OverwriteBlocks:= 'y' ;
Scl_GenerateReferenceData := 'y' ;
Scl_S7ServerActive:='y' ;
Scl_CreateObjectCode:= 'y' ;
Scl_OptimizeObjectCode:= 'y' ;
Scl_MonitorArrayLimits:= 'y' ;
Scl_CreateDebugInfo := 'n' ;
Scl_SetOKFlag:= 'n' ;
Scl_SetMaximumStringLength:= '254'
}

FUNCTION FC1354 : VOID
TITLE ='Addition of two 64-bit REAL variables'
AUTHOR : AdvLib80
FAMILY : System
NAME : AddR64
VERSION : '2.0'
 
 
VAR_INPUT
DPReal1 : STRUCT
Top4Bytes : DWORD ;
Bottom4Bytes : DWORD ;
END_STRUCT ;
DPReal1_w AT DPReal1: STRUCT
x0 : WORD ;
END_STRUCT ;
DPReal1_b AT DPReal1: STRUCT
x0 : BYTE ;
x1 : BYTE ;
END_STRUCT ;
DPReal1_di AT DPReal1: STRUCT
UpperDInt : DINT ;
LowerDInt : DINT ;
END_STRUCT ;
DPReal1_d AT DPReal1: STRUCT
x0 : INT ;
x1 : DWORD ;
END_STRUCT ;

DPReal2 : STRUCT
Top4Bytes : DWORD ;
Bottom4Bytes : DWORD ;
END_STRUCT ;
DPReal2_w AT DPReal2: STRUCT
x0 : WORD ;
END_STRUCT;
DPReal2_b AT DPReal2: STRUCT
x0 : BYTE ;
x1 : BYTE ;
END_STRUCT ;
DPReal2_di AT DPReal2: STRUCT
UpperDInt : DINT ;
LowerDInt : DINT ;
END_STRUCT ;
DPReal2_d AT DPReal2: STRUCT
x0 : INT ;
x1 : DWORD ;
END_STRUCT ;
END_VAR
 
VAR_OUTPUT
OutReal64 : STRUCT
Top4Bytes : DWORD ;
Bottom4Bytes : DWORD ;
END_STRUCT ;
END_VAR
 
VAR_TEMP
retval : STRUCT
Top4Bytes : DWORD ;
Bottom4Bytes : DWORD ;
END_STRUCT ;
retval_b AT retval : STRUCT
x0 : byte ;
END_STRUCT ;
retval_w AT retval : STRUCT
x0 : WORD ;
END_STRUCT ;
 

Expon1 : INT ;
Expon1_w AT Expon1: WORD ;
Expon1_b AT Expon1 : STRUCT
x0 : BYTE;
x1 : BYTE;
END_STRUCT;
 
Expon2 : INT ;
Expon2_w AT Expon2: WORD ;
Expon2_b AT Expon2 : STRUCT
x0 : BYTE;
x1 : BYTE;
END_STRUCT;
 
Int64_1 : STRUCT
UpperDInt : DINT ;
LowerDInt : DINT ;
END_STRUCT ;
Int64_1_dw AT Int64_1: STRUCT
x0 : DWORD ;
x1 : DWORD ;
END_STRUCT ;
 

Int64_2 : STRUCT
UpperDInt : DINT ;
LowerDInt : DINT ;
END_STRUCT ;
Int64_2_dw AT Int64_2: STRUCT
x0 : DWORD ;
x1 : DWORD ;
END_STRUCT ;
 
ExponDiff : INT ;
NegativeResult : BOOL ;
TestDInt : DINT ;
TestDInt_dw AT TestDInt : DWORD ;
BitAdjust : INT ;
TopMostBit : INT ;
IsZERO1 : BOOL ;
IsNAN1 : BOOL ;
IsINFINITY1 : BOOL ;
IsZERO2 : BOOL ;
IsNAN2 : BOOL ;
IsINFINITY2 : BOOL ;
END_VAR
BEGIN
 
IsZERO1:=(DPReal1_w.x0 AND W#16#7FF0) = W#16#0;
IsZERO2:=(DPReal2_w.x0 AND W#16#7FF0) = W#16#0;
 
IsNAN1:=(DPReal1_w.x0 AND W#16#7FF8) = W#16#7FF8;
IsNAN2:=(DPReal2_w.x0 AND W#16#7FF8) = W#16#7FF8;
 
IsINFINITY1:=((DPReal1.Top4Bytes AND DW#16#7FF00000) = DW#16#7FF00000) AND (DPReal1.Bottom4Bytes=DW#16#0);
IsINFINITY2:=(DPReal2.Top4Bytes AND DW#16#7FF00000) = DW#16#7FF00000 AND (DPReal2.Bottom4Bytes=DW#16#0);

IF IsZERO1
THEN
retval.Top4Bytes:=DINT_TO_DWORD(DPReal2_di.UpperDInt);
retval.Bottom4Bytes:=DINT_TO_DWORD(DPReal2_di.LowerDInt);
ELSE
IF IsZERO2
THEN
retval.Top4Bytes:=DPReal1.Top4Bytes;
retval.Bottom4Bytes:=DPReal1.Bottom4Bytes;
ELSE
IF IsNAN1
THEN
retval.Top4Bytes:=DPReal1.Top4Bytes;
retval.Bottom4Bytes:=DPReal1.Bottom4Bytes;
ELSE
IF IsNAN2
THEN
retval.Top4Bytes:=DPReal2.Top4Bytes;
retval.Bottom4Bytes:=DPReal2.Bottom4Bytes;
ELSE
IF IsINFINITY1
THEN
retval.Top4Bytes:=DPReal1.Top4Bytes;
retval.Bottom4Bytes:=DPReal1.Bottom4Bytes;
ELSE
IF IsINFINITY2
THEN
retval.Top4Bytes:=DPReal2.Top4Bytes;
retval.Bottom4Bytes:=DPReal2.Bottom4Bytes;
ELSE
Expon1_b.x0:=DPReal1_b.x0 AND B#16#7F;
Expon1_b.x1:=DPReal1_b.x1 AND B#16#F0;

Expon2_b.x0:=DPReal2_b.x0 AND B#16#7F;
Expon2_b.x1:=DPReal2_b.x1 AND B#16#F0;

Expon1:=WORD_TO_INT(SHR(IN:=INT_TO_WORD(Expon1),N:=4));
Expon2:=WORD_TO_INT(SHR(IN:=INT_TO_WORD(Expon2),N:=4));
 
ExponDiff:=Expon1-Expon2;
 
Int64_1_dw.x0:=DPReal1.Top4Bytes AND DW#16#FFFFF or DW#16#100000;
Int64_1_dw.x1:=DPReal1.Bottom4Bytes;
 
Int64_2_dw.x0:=DPReal2.Top4Bytes AND DW#16#FFFFF or DW#16#100000;
Int64_2_dw.x1:=DPReal2.Bottom4Bytes;

IF ExponDiff<0
THEN
ShRiIn64(IN :=Int64_1,
Shift := -ExponDiff,
OutInt64 :=Int64_1
);
Expon1:=Expon2;
 
ELSE
IF ExponDiff>0
THEN
ShRiIn64(IN :=Int64_2,
Shift := ExponDiff,
OutInt64 :=Int64_2
);
END_IF;
END_IF;

IF (DPReal1_b.x0 AND B#16#80) <> B#16#0
THEN
NegInt64(theInt64 := Int64_1
,OutInt64 := Int64_1
);
END_IF;

IF (DPReal2_b.x0 AND B#16#80) <> B#16#0
THEN
NegInt64(theInt64 := Int64_2
,OutInt64 := Int64_2);
END_IF;

AddInt64(Int64_1 := Int64_1
,Int64_2 := Int64_2
,OutInt64 := Int64_1
);
NegativeResult:=false;
 
IF (Int64_1_dw.x0 AND DW#16#80000000) <> DW#16#0
THEN
NegativeResult := true;
NegInt64(theInt64 := Int64_1
,OutInt64 :=Int64_1
);
END_IF;
TopMostBit:=0;
TestDInt:=Int64_1.LowerDInt;

IF Int64_1.UpperDInt <> 0
THEN
TopMostBit:=32;
TestDInt:=Int64_1.UpperDInt;
END_IF;

WHILE TestDInt<>0 DO
TestDInt_dw:=SHR(IN:=TestDInt_dw,N:=1);
TopMostBit:=TopMostBit+1;
END_WHILE;

IF TopMostBit>0
THEN
BitAdjust:=TopMostBit-53;
Expon1:=BitAdjust+Expon1;
 
IF BitAdjust>0
THEN

ShRiIn64(IN := Int64_1
,Shift := BitAdjust
,OutInt64 := Int64_1
);
ELSE
IF BitAdjust < 0
THEN
ShLeInt64(IN := Int64_1
,Shift := - BitAdjust
,OutInt64 := Int64_1
);
END_IF;
END_IF;

retval_w.x0:=SHL(IN:=INT_TO_WORD(Expon1),N:=4);
retval.Top4Bytes:=(Int64_1_dw.x0 AND DW#16#FFFFF) OR (retval.Top4Bytes AND DW#16#FFF00000);
retval.Bottom4Bytes:=Int64_1_dw.x1;

IF NegativeResult THEN retval_b.x0:=retval_b.x0 OR B#16#80; END_IF;
END_IF;
END_IF;
END_IF;
END_IF;
END_IF;
END_IF;
END_IF;
 
OutReal64.Top4Bytes:=retval.Top4Bytes;
OutReal64.Bottom4Bytes:=retval.Bottom4Bytes;

END_FUNCTION
 



add64

Block checksum .





:



add64

5.0 + 7.0 = 12.0 - :).





PCS7 (Advanced Process Library (V8.0 SP2) (zip, 3.5Mb)







: 3189

: kssergio    : 2020-04-25

- , .
- retval .

:

(4000 max):

: