Skip to main content

valueIsInRangeOf

Short summary

This assertion method checks if the current value is inside a limit

Attention: limits are included: valueIsInRangeOf(3.0, 3.0, 3.0) is a true assertion

Attention: Any comparsion to NaN is FALSE that means if lowerLimit OR currentValue OR upperLimit is NaN then is the assertion false. For details check IEEE 754_ and the truth table below.

Attention: Every number is smaller than infinity except infinity, it's equal. Every number is greater than -infinity except -infinity, it's equal. For details check IEEE 754 and the truth table below.

truth table for special values

+--------------------+----------------------+--------------------+---------------+ | lowerLimit | currentValue | upperLimit | assertion | +====================+======================+====================+===============+ | NaN | Any value | Any value | FASLE | +--------------------+----------------------+--------------------+---------------+ | Any value | NaN | Any value | FALSE | +--------------------+----------------------+--------------------+---------------+ | Any value | Any value | NaN | FALSE | +--------------------+----------------------+--------------------+---------------+ | -infinity | NOT NaN | infinity | TRUE | +--------------------+----------------------+--------------------+---------------+ | infinity | Any value | -infinity | FALSE | +--------------------+----------------------+--------------------+---------------+ | NOT -infinity | -infinity | Any value | FALSE | +--------------------+----------------------+--------------------+---------------+ | Any value | infinity | NOT infinity | FALSE | +--------------------+----------------------+--------------------+---------------+ | -infinity | -infinity | -infinity | TRUE | +--------------------+----------------------+--------------------+---------------+ | infinity | infinity | infinity | TRUE | +--------------------+----------------------+--------------------+---------------+ | -infinity | NOT -infinity | -infinity | FALSE | +--------------------+----------------------+--------------------+---------------+ | infinity | NOT infinity | infinity | FALSE | +--------------------+----------------------+--------------------+---------------+

Parameters

NameTypeCommentKind
lowerLimitLREALlower limit for the current valueinput
currentValueLREALcurrent value to checkinput
upperLimitLREALupper limit for the current valueinput
messageAssertMessagemessage if the assertion is falseinput

Code

Declaration

METHOD valueIsInRangeOf
VAR_INPUT
(* lower limit for the current value *)
lowerLimit :LREAL;
(* current value to check *)
currentValue :LREAL;
(* upper limit for the current value *)
upperLimit :LREAL;
(* message if the assertion is false *)
message :AssertMessage;
END_VAR

Implementation

IF (
THIS^.isValueNaN(lowerLimit)
OR_ELSE THIS^.isValueNaN(currentValue)
OR_ELSE THIS^.isValueNaN(upperLimit)
OR_ELSE (
THIS^.isValueNegativeInfinite(upperLimit)
AND_THEN THIS^.isValuePositiveInfinite(lowerLimit)
) OR_ELSE (
THIS^.isValueNegativeInfinite(currentValue)
AND_THEN (NOT THIS^.isValueNegativeInfinite(lowerLimit))
) OR_ELSE (
THIS^.isValuePositiveInfinite(currentValue)
AND_THEN (NOT THIS^.isValuePositiveInfinite(upperLimit))
) OR_ELSE (
THIS^.isValuePositiveInfinite(lowerLimit)
AND_THEN (NOT THIS^.isValuePositiveInfinite(currentValue))
AND_THEN THIS^.isValuePositiveInfinite(upperLimit)
) OR_ELSE (
THIS^.isValueNegativeInfinite(lowerLimit)
AND_THEN (NOT THIS^.isValueNegativeInfinite(currentValue))
AND_THEN THIS^.isValueNegativeInfinite(upperLimit))
) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('valueIsInRangeOf'));
ELSIF ((
THIS^.isValuePositiveInfinite(lowerLimit)
AND_THEN THIS^.isValuePositiveInfinite(currentValue)
AND_THEN THIS^.isValuePositiveInfinite(upperLimit)
) OR_ELSE (
THIS^.isValueNegativeInfinite(lowerLimit)
AND_THEN THIS^.isValueNegativeInfinite(currentValue)
AND_THEN THIS^.isValueNegativeInfinite(upperLimit)
) OR_ELSE (
THIS^.isValueNegativeInfinite(lowerLimit)
AND_THEN THIS^.isValuePositiveInfinite(upperLimit))
) THEN
RETURN;
ELSIF ((currentValue < lowerLimit) OR (currentValue > upperLimit)) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('valueIsInRangeOf'));
END_IF