.FUNC -- User Defined Functions

 

Syntax: .func <name>([args]) {<expression>}

 

Example: .func Pythag(x,y) {sqrt(x*x+y*y)}

 

The .func directive allows the creation of user-defined functions for use with user parameterized circuits and behavioral sources. This is useful for associating a name with a function for the sake of clarity and parameterizing subcircuits so that abstract circuits can be saved in libraries.

 

The .func statement can be included inside a subcircuit definition to limit the scope the function to that subcircuit and the subcircuits invoked by that subcircuit.

 

To invoke parameter substitution and expression evaluation with these user-defined functions, enclose the expression in curly braces. The enclosed expression will be replaced with the floating-point value.

 

Below is a example using both a .func and .param statements.

 

* Example deck using a .func statement

.func myfunc(x,y) {sqrt(x*x+y*y)}

.param u=100 v=600

V1 a 0 pulse(0 1 0 1n 1n .5µ 1µ)

R1 a b {myfunc(u,v/3)}

C1 b 0 100p

.tran 3µ

.end

 

All parameter substitution evaluation is done before the simulation begins.