# LGF_CompareLReal (FC / 3.0.2)

Overview

Author: Siemens Digital Industry

## Short description

This function checks floating point numbers for equality, by using an approximation formula and a fixed precision by constant 1.0E-12 (pico)

### Block Interface

| LGF_CompareLReal (FC) |
--- | --- | ---
LReal |  |  | valueA |  | Ret_Val |  |  | Bool
LReal |  |  | valueB |  |  |  |  |

### Input parameter

Identifier | Data type | Description
--- | --- | ---
valueA | LReal | First LREAL number to be compared.
valueB | LReal | Second LREAL number to be compared.

### Output parameter

Identifier | Data type | Description
--- | --- | ---
Ret_Val | Bool | FALSE: not equal TRUE: approximately the same

## Functional description

The comparison of the LREAL numbers is based on an fixed accuracy of 1.0E-12. The difference between the two input values must be smaller than the `PRECISION` accuracy multiplied by one of the two input values.

Equation:

result := FALSE OR ((#valueA = 0.0) AND (ABS(#valueB) <= #precision)) OR ((#valueB = 0.0) AND (ABS(#valueA) <= #precision)) OR (ABS(valueA - valueB) <= (PRECISION * ABS(valueA));

Note
  If your application requires a different accuracy when comparing the numbers, adapt the “PRECISION” constant in the function to your requirements.
  Or you may use the FC `LGF_CompareLRealByPrecision`.

## Change log

Version & Date | Change description
--- | ---
| 1.0.0 | Siemens Industry Online Support
| 13.01.2017 | First released version
| 1.0.1 | Siemens Industry Online Support
| 17.08.2018 | Upgrade: TIA V15 Update 2
| 1.0.2 | Siemens Industry Online Support
| 23.11.2018 | Upgrade: TIA V15.1
| 1.0.3 | Simatic Systems Support
| 03.06.2019 | Refactoring and performance improvment Delete Error and Status there is no need for, because of changed / adjusted algorithm add eno handling
| 3.0.0 | Simatic Systems Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 3.0.1 | Simatic Systems Support
| 19.01.2020 | Insert documentation
| 3.0.2 | Simatic Systems Support
| 21.12.2023 | Fix compare error if one value is exactly zero