document short-circuiting for ternary() variable function
This commit is contained in:
@ -759,10 +759,23 @@ is the nearest integer to its argument.
|
||||
|
||||
.. versionadded:: 7Feb2024
|
||||
|
||||
.. versionchanged:: TBD
|
||||
|
||||
Evaluate only selected argument
|
||||
|
||||
The ternary(x,y,z) function is the equivalent of the ternary operator
|
||||
(? and :) in C or C++. It takes 3 arguments. The first argument is a
|
||||
conditional. The result of the function is y if x evaluates to true
|
||||
(non-zero). The result is z if x evaluates to false (zero).
|
||||
(non-zero). The result is z if x evaluates to false (zero). Same as
|
||||
in C or C++ only the selected argument y or z is evaluated, so this
|
||||
function can be used to protect against crashes from evaluating invalid
|
||||
arguments, e.g. in the following example where qval is a variable with
|
||||
an expression that may become slightly negative due to floating-point
|
||||
math limitations.:
|
||||
|
||||
.. code-block:: LAMMPS
|
||||
|
||||
variable sqrtofqval equal "ternary(v_qval >= 0, sqrt(v_qval), 0.0)"
|
||||
|
||||
The ramp(x,y) function uses the current timestep to generate a value
|
||||
linearly interpolated between the specified x,y values over the course
|
||||
|
||||
Reference in New Issue
Block a user