Generated reference › Math Function — Control Systems/Base Blocks
kind: generated#block#control-systems-base-blocks

Math Function — Control Systems/Base Blocks

f u

Control_Systems/Base_Blocks/Math_Function · 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.

Math Function

Control Systems / Base Blocks

Applies one of fifteen mathematical functions to its input, entry by entry. Which function is applied is chosen by the Function parameter, and that choice decides the block's shape as well as its arithmetic: four of the functions take a second input, and two of them transpose the signal.

Ports

  • u1 – the signal the function is applied to, of any size [m,n]. For the four two-input functions this is the first operand.
  • u2 – present only for Power, Hypotenuse, Remainder and Modulus. Either the SAME size [m,n] as u1, or a scalar [1,1], which is then applied to every entry of u1. Any other size is an error rather than a guess. The port is not added or removed for you: set the input port count to match the function you chose.
  • Output – the result y. The SAME size [m,n] as u1 for thirteen of the functions, and [n,m] for Transpose and Hermitian Transpose, which are the only two that reshape a signal.

Parameters

  • Function – which function is applied. This selects the arithmetic rather than retuning it, so each option is a separate code path.
    • Exponential (e^u) – y = eu. This is the default, as in Simulink. Defined for every real input.
    • Natural Logarithm (log(u)) – y = ln(u). Defined for u > 0; zero yields −Inf and a negative entry yields NaN.
    • Power of Two (2^u) – y = 2u. Defined everywhere.
    • Power of Ten (10^u) – y = 10u. Defined everywhere.
    • Base 10 Logarithm (log10(u)) – y = log₁₀(u), with the same domain as the natural logarithm.
    • Magnitude Squared (|u|^2) – y = |u|². On the real signals ICore carries this is u², so it computes the same thing as Square; the two are kept apart because they are separate options in Simulink and differ there on a complex signal.
    • Square (u^2) – y = u².
    • Power (u1^u2) – y = u1u2. Two inputs. A negative base with a fractional exponent has no real value and yields NaN.
    • Complex Conjugate (conj(u)) – y = u̅. On a real signal the conjugate is the signal itself, so this option is the identity. It is offered so that a Simulink model using it crosses without loss.
    • Reciprocal (1/u) – y = 1/u. Zero yields ±Inf.
    • Hypotenuse (sqrt(u1^2+u2^2)) – y = √(u1²+u2²). Two inputs. Defined everywhere.
    • Remainder (rem(u1,u2))two inputs. The remainder after division, TRUNCATED toward zero, so its sign follows u1. A zero divisor yields NaN.
    • Modulus (mod(u1,u2))two inputs. The remainder after division, FLOORED, so its sign follows u2. This is the one difference from Remainder, and it shows only when the two operands have opposite signs. A zero divisor returns u1 unchanged.
    • Transpose (u') – y = uᵀ. Reshapes: a [m,n] input leaves as [n,m].
    • Hermitian Transpose (u') – the conjugate transpose, which on a real signal is the plain transpose. Reshapes, and is offered for the same round-trip reason Complex Conjugate is.
  • 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. The function is fixed into the generated arithmetic at export time rather than exposed as a tunable parameter: it selects which code is emitted, so there is nothing left to retune on the generated core.

The seven software targets agree exactly, including out of domain, where they all produce IEEE NaN or ±Inf. MATLAB needs one extra step to get there: its log, log10 and .^ return a complex number where the others return NaN, so the generated MATLAB maps those entries to NaN first and keeps the result real.

The three HDL targets are simulation-only for twelve of the fifteen functions. There is no exponential, logarithm or power in the Q16.16 datapath to call, so the generated cores convert at the port boundary and evaluate in real arithmetic – correct in simulation, but not offered as synthesizable. They also carry neither NaN nor infinity, so out of domain they answer 0 where the software targets answer NaN or ±Inf. Complex Conjugate, Transpose and Hermitian Transpose are the exception: they are pure data movement, stay in the fixed-point datapath, and are synthesizable.

Simulink bridge

Import and export, mapped to simulink/Math Operations/Math Function. "Function" to Operator, one option for one option (exp, log, 2^u, 10^u, log10, magnitude^2, square, pow, conj, reciprocal, hypot, rem, mod, transpose, hermitian), so that round trip is lossless; "Sampling Time (s)" to SampleTime, as on every block.

Neither side carries the port count as a parameter: Simulink moves its own ports when Operator is set, and an imported model brings the port list the operator implies back with it. Two parameters are always written out because this block has no choice to offer behind them – OutputSignalType is real, since ICore signals are real doubles, and AlgorithmMethod is Exact, which pins the reciprocal to a true division rather than Simulink's Newton-Raphson approximation.

Notes

  • Algebraic, with no state: the output depends only on the current input.
  • Not linear in twelve of the fifteen functions, and the three that are either reshape the signal (Transpose, Hermitian) or do nothing to it (Complex Conjugate), so the block deliberately carries no state space and model reduction reports it as unmergeable.
  • Simulink's Square, Reciprocal and Transpose library entries are this same block pre-set to those functions, and import as such.
  • Changing Function to or from one of the two-input functions does not add or remove the port for you. The block reports the mismatch when the model is built rather than editing the diagram underneath you.

Code facts#

FactValue
registered typeControl_Systems/Base_Blocks/Math_Function
familyControl_Systems/Base_Blocks
solver environment classICoreBlock_0_Control_Systems_1_Base_Blocks_2_Math_Function
sourcesrc/ICoreSDK/ICoreBlockLibrary/Blocks/Control_Systems/Base_Blocks/Math_Function/ICoreBlock_0_Control_Systems_1_Base_Blocks_2_Math_Function.cpp
headersrc/ICoreSDK/ICoreBlockLibrary/Blocks/Control_Systems/Base_Blocks/Math_Function/ICoreBlock_0_Control_Systems_1_Base_Blocks_2_Math_Function.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
1inICoreDoubleu1
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
FunctionExponential (e^u)%~%Natural Logarithm (log(u))%~%Power of…Operator

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/Math Operations/Math Function
port-count rulePortsParam::MathFunctionOperator
SampleTime parameteryes
always setOutputSignalType = real, AlgorithmMethod = Exact
ICore configSimulink parameterValue translation
FunctionOperatorExponential (e^u)exp, Natural Logarithm (log(u))log, Power of Two (2^u)2^u, Power of Ten (10^u)10^u, Base 10 Logarithm (log10(u))log10, Magnitude Squared (|u|^2)magnitude^2, Square (u^2)square, Power (u1^u2)pow, Complex Conjugate (conj(u))conj, Reciprocal (1/u)reciprocal, Hypotenuse (sqrt(u1^2+u2^2))hypot, Remainder (rem(u1,u2))rem, Modulus (mod(u1,u2))mod, Transpose (u')transpose, Hermitian Transpose (u')hermitian

Caveat (shown to the user): the fifteen functions map 1:1 onto Simulink's Operator values, so the choice is lossless in both directions; the second input port that pow, hypot, rem and mod need is implied by the function rather than carried by a parameter

Catalog contract: src/ICoreSDK/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 Ports lists 3 entries for 2 ports (1 in, 1 out) — grouped, or one undocumented? a reader must say

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).

Math Function -- Simulink's fifteen-operator Math Function, entry by entry "Function" selects WHICH code runs, so every option is a mode rather than a tuning. Three of them change the block's SHAPE as well as its arithmetic, exactly as Simulink's does:

pow, hypot, rem, mod take a SECOND input port transpose, hermitian turn a [m,n] input into an [n,m] output

Four conventions are worth stating, because they are the only places the ten targets could have drifted from each other or from Simulink:

  • MOD IS NOT THE FLOOR FORM. MATLAB's mod() is fmod-with-sign-correction, not

a - b*floor(a/b). Measured against R2026a rather than assumed:

mod(0.3, 0.1) = 0 (MATLAB, and every backend here) 0.3 - 0.1*floor(0.3/0.1) = 0.099999999999999978

a - b*floor(a/b) is a WHOLE DIVISOR out whenever a/b lands just under an integer, so a backend written that way agrees on most samples and fails on exactly those. Every target here computes rem first and corrects its sign. mod(a,0) is a and rem(a,0) is NaN, both of which MATLAB and C's fmod already agree on.

  • OUT OF DOMAIN. log and log10 of a negative, pow of a negative base to a fractional

exponent, and reciprocal of zero have no real answer. The seven software targets all produce IEEE NaN / +/-Inf and agree exactly -- except MATLAB, whose log(), log10() and .^ return COMPLEX numbers there rather than NaN, so those bodies map the offending entries to NaN first and keep the result real, matching the other six.

  • HDL. Q16.16 fixed point carries neither NaN nor infinity, so the three HDL backends

answer 0 out of domain. They are also SIMULATION-ONLY for twelve of the fifteen operators: there is no fixed-point exp, log or power to call, so those convert at the port boundary and evaluate in real. The three that are pure data movement -- conj, transpose, hermitian -- stay in the fixed-point datapath and ARE synthesizable.

  • SCALAR BROADCAST. On a binary operator the second input may be a scalar, which is then

applied to every entry of the first, as in Simulink. Any other size mismatch is an error rather than a guess.

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

Sample results#

Math Function — Repeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sampleMath Function — Repeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample05101520-2-10123inputoutput
tin ICoreDouble-Out-0out ICoreDouble-Out-0
0-20.1353
0.40.51.649
0.8-20.1353
1.20.51.649
1.6-20.1353
20.51.649
2.4-20.1353
2.80.51.649
3.2-20.1353
3.60.51.649
4-20.1353
4.40.51.649
4.8-20.1353
5.20.51.649

Every 4th of 60 samples, from the table stimulus.

The same rig also ran:

StimulusWhat it isOutput range
impulseImpulse: one sample of 1 at k = 5, 0 elsewhere (Repeating Sequence Stair)1 … 2.718
rampRamp: slope 1 from t = 01 … 330.3
sineSine Wave: amplitude 1, 2 rad/s, no phase, no bias0.3679 … 2.717
stepStep: 0 -> 1 at t = 1 s1 … 2.718

Plotted: table — Repeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample

Category static · sample time 0.1 · 60 steps · commit ccf005c8 · produced by docsSample --out <folder> --steps 60 · data docs/generated/samples/Control_Systems__Base_Blocks__Math_Function.json · the SVG is generated from those numbers by tools/docs/plot_svg.py, so it is a run and not a drawing (R-D10).