F_TryDivide()

F_TryDivide() 1:

Divides two values without throwing an exception.

F_TryDivide() 2:

Return value mathematically invalid

The function defines the mathematically invalid case x / 0 as 0. This is a mathematically invalid result, but is sufficient for many use cases. Check for your use case whether this definition does not lead to unforeseen misbehavior.

Syntax:

FUNCTION F_TryDivide : HRESULT
VAR_INPUT
    fNominator:      LREAL;                
    fDenominator:    LREAL;                
    refResult:       REFERENCE TO LREAL;    
END_VAR

F_TryDivide() 3: Inputs

Name

Type

Description

fNominator

LREAL

Value to be divided

fDenominator

LREAL

Value by which to divide

refResult

REFERENCE TO LREAL

Result of the division

F_TryDivide() 4: Outputs

Name

Type

Description

F_TryDivide

HRESULT

Return value with feedback on the success of the execution

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4024.42

PC or CX (x64, x86)

Tc3_PlasticBaseApplication (>= v3.12.5.4)