Macrosfunctional blocks
P.
315 of 349
You can define as many local
varoables as you like, but the
memory usage will be increased
Compact design
Compact design
empty line before :end means no
return value (if :return is not defined)
Use it as built-in
If we want to define a function
cosh
x
=
e
x
−
e
−
x
2
we can define the following macro
:begin cosh(x)
:info Calculates the cosh-function
:var sum@
:var p_ex@
:var m_ex@
p_ex@=exp(x)
m_ex@=-exp(-x)
sum@=p_ex@+m_ex@
:return sum@ / 2.f32
:end
Of course, in this case the local variables
sum@, p_ex@
and
m_ex@
are not really necessary and
we could code instead:
:begin cosh(x)
:info Calculates the cosh-function
:return (exp(x)-exp(-x))/2f32
:end
Additionally the return command could be left (due to compatibility reasons to older macros), so the
code
:begin cosh(x)
:info Calculates the cosh-function
(exp(x)-exp(-x))/2f32
:end
is still equivalent to the code above. If the last line before
:end
is empty or only spaces, no return
value is defined. So it is a good coding style always to use
:return
.
:return
can be placed anywhere in
the code of the macro.
:begin cosh(x)
:info Calculates the cosh-function
(exp(x)-exp(-x))/2f32
:end
Once defined in a macro-lib and added to the [
MacroLibs
] section, the macro can be used as a built-
in function:
[EibPC]
MyVar=cosh(2.3f32)
MyVar2=cosh(cosh('1/3/2'f32)) +cosh('1/3/3'f32) + 32f32
HandbuchEibPC_USA-30.odt, 2017-05-11
Enertex
®
Bayern GmbH - Erlachstraße 13 - 91301 Forchheim - [email protected]