Generated reference › Compare To Constant — Control Systems/Logic And Bit Operations
kind: generated#block#control-systems-logic-and-bit-operations

Compare To Constant — Control Systems/Logic And Bit Operations

Control_Systems/Logic_And_Bit_Operations/Compare_To_Constant · 1 input / 1 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Description#

The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.

Compare To Constant

Control Systems / Logic And Bit Operations

Tests every entry of its input against a fixed value with one relational operator and answers 1 where the test holds and 0 where it does not: y = (u <relop> c), where c is the Constant Value. The comparison is applied entry by entry, so a matrix signal is treated element for element and the signal's size is unchanged.

Ports

  • Input – the signal u to be tested, of any size [m,n].
  • Output – y, of the SAME size [m,n] as the input. Every entry is 1 or 0. It is carried as an ordinary real signal, not a boolean type – every port in this library is a real matrix – so it can be fed straight into arithmetic as a 0/1 mask.

Parameters

  • Operator – which comparison is made against the constant. This selects the test rather than retuning it, so each option is a separate code path.
    • == (equal to the constant) – 1 where the entry is exactly c.
    • ~= (not equal to the constant) – the complement of the above.
    • < (less than the constant).
    • <= (less than or equal to the constant) – the default, as in Simulink.
    • >= (greater than or equal to the constant).
    • > (greater than the constant).
  • Constant Value – the scalar c every entry of the input is compared against. Defaults to 3, as in Simulink. A per-entry constant sized like the input is not implemented and is reported rather than broadcast from its first entry.
  • Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.

Code export

All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text. Both choices are baked into the generated code at export time rather than exposed as tunable parameters: the operator is emitted as the comparison itself, and the constant as a literal. The three HDL targets are fully synthesizable – comparing two Q16.16 words needs no arithmetic, so nothing is evaluated in real.

Simulink bridge

Import and export, mapped to simulink/Logic and Bit Operations/Compare To Constant. "Operator" to relop, one option for one option (==, ~=, <, <=, >=, >), so that round trip is lossless; "Constant Value" to const as a plain pass-through value. OutDataTypeStr is always written as boolean and ZeroCross as off: this block has no data-type choice to offer and no zero-crossing detection, and pinning both is what keeps the two sides comparing the same thing.

The Simulink block defines no SampleTime parameter, so "Sampling Time (s)" does not cross – a block left at the inheriting default loses nothing, and one given an explicit period is reported rather than silently dropped.

Notes

  • Algebraic, with no state: the output depends only on the current input.
  • Not linear – the output is a two-valued step function of the input – so the block deliberately carries no state space and model reduction reports it as unmergeable.
  • == and ~= test for EXACT equality with c. On a signal that arrived through any arithmetic that is a test almost nothing passes; they are useful on a signal that is quantized, counted or held, not on a continuous one.
  • An HDL core sees its input already quantized to one part in 1.5×10⁻⁵, and rounds c to the nearest value on the same lattice, so a constant that is not exactly representable in Q16.16 moves the boundary by up to half a quantum. A constant that is a whole number, or a multiple of a negative power of two, is exact.
  • To compare against zero, Compare To Zero says so on the block face; to compare two signals, use Relational Operator.

Code facts#

FactValue
registered typeControl_Systems/Logic_And_Bit_Operations/Compare_To_Constant
familyControl_Systems/Logic_And_Bit_Operations
solver environment classICoreBlock_0_Control_Systems_1_Logic_And_Bit_Operations_2_Compare_To_Constant
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Logic_And_Bit_Operations/Compare_To_Constant/ICoreBlock_0_Control_Systems_1_Logic_And_Bit_Operations_2_Compare_To_Constant.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Logic_And_Bit_Operations/Compare_To_Constant/ICoreBlock_0_Control_Systems_1_Logic_And_Bit_Operations_2_Compare_To_Constant.h
default size on canvas80 × 70 px
ports at insert1 in, 1 out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDouble—
2outICoreDouble—

Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.

Configuration variables#

Config variableDefaultSimulink parameter
Operator== (equal to the constant)%~%~= (not equal to the constan…relop
Constant Value3const

Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.

supportSupport::Both
Simulink pathsimulink/Logic and Bit Operations/Compare To Constant
port-count rulePortsParam::None
SampleTime parameterno — the counterpart defines none; the rate stays on the ICore side
always setOutDataTypeStr = boolean, ZeroCross = off
ICore configSimulink parameterValue translation
Operatorrelop== (equal to the constant) → ==, ~= (not equal to the constant) → ~=, < (less than the constant) → <, <= (less than or equal to the constant) → <=, >= (greater than or equal to the constant) → >=, > (greater than the constant) → >
Constant Valueconstpasses through

Caveat (shown to the user): the six operators map 1:1 onto Simulink's relop values, so the choice is lossless in both directions; the Simulink block has NO SampleTime parameter, so "Sampling Time (s)" does not cross

Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h

Description vs code#

The checker has a blind spot here — it could not resolve something (a grouped port bullet, a computed config name), which is reported and never counted as a pass. A reader has to settle it:

  • B0 no sample under docs/generated/samples/ — nothing to cross-check (P8.1)

The verdict above is tools/docs/check_block_descriptions.py (P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.

File banner (developer view)#

The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).

Compare To Constant block -- one relational test against a fixed value, entry by entry y = 1 where (u <relop> c) holds and y = 0 where it does not, with <relop> one of ==, ~=, <, <=, >= and > chosen by the "Operator" config and c the scalar "Constant Value". Applied INDEPENDENTLY to every entry of the input signal, so the output keeps the input's size. Compare To Zero is this block with c pinned to zero.

The output is a REAL signal carrying 1.0 and 0.0, not a boolean type -- every port in this library is ICoreDouble. Simulink's counterpart emits a boolean, which logs as 1/0, so the two agree numerically; the bridge pins OutDataTypeStr to boolean so that stays true.

Code export: BOTH choices are structural. The operator is emitted as the comparison itself and the constant is inlined as an export-time literal rather than exposed as a tunable parameter, matching Wrap To Zero's threshold and the rest of this family.

HDL: fully synthesizable. Comparing two Q16.16 words is a signed compare and needs no arithmetic, so the three HDL cores stay in the fixed-point datapath. Two caveats follow from that datapath rather than from the block, and both are in the description: the INPUT arrives already quantized to 1.5e-5, and the CONSTANT is rounded to the nearest Q16.16 value by to_fx, so a constant that is not exactly representable moves the boundary by up to half a quantum.

Algebraic and stateless. No state space -- see the header.

Sample results#

No sample run is committed for this block. Samples come from the headless harness (DOCS_PLAN.md P8.1) into docs/generated/samples/; until one exists this block's behaviour is witnessed by the parity and export-verification suites, not by a plot here.