Skip to main content

valueIsMax

Short summary

This assertion method checks if the current value is less than or equal to the maximum value

Attention: Any comparsion to NaN is FALSE that means if currentValue OR maximumValue 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

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

Parameters

NameTypeCommentKind
currentValueREALcurrent value to checkinput
maximumValueREALupper limit for the current valueinput
messageAssertMessagemessage if the assertion is falseinput

Code

Declaration

METHOD valueIsMax
VAR_INPUT
(* current value to check *)
currentValue :REAL;
(* upper limit for the current value *)
maximumValue :REAL;
(* message if the assertion is false *)
message :AssertMessage;
END_VAR

Implementation

IF (
THIS^.isValueNaN(currentValue)
OR_ELSE THIS^.isValueNaN(maximumValue)
OR_ELSE (
THIS^.isValueNegativeInfinite(maximumValue)
AND_THEN (NOT THIS^.isValueNegativeInfinite(currentValue))
) OR_ELSE (
THIS^.isValuePositiveInfinite(currentValue)
AND_THEN (NOT THIS^.isValuePositiveInfinite(maximumValue))
)
) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('valueIsMax'));
ELSIF (
THIS^.isValuePositiveInfinite(maximumValue)
OR_ELSE THIS^.isValueNegativeInfinite(currentValue)
) THEN
RETURN;
ELSIF (currentValue > maximumValue) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('valueIsMax'));
END_IF