History

doc/utils/eval: review and extend, clarify ld/st index meaning

Prefer idx in place of id for functions accessing the internal variables, and add a short introduction to mention them.

Stefano Sabatini committed 2 years ago

Commit b2bc4ac1 parent 8ceb37d1 file · +33 −27Browse files

Unified · Split

doc/utils.texi+33−27
@@ -801,6 +801,11 @@ The following binary operators are available: @code{+}, @code{-}, · 800 unmodified lines
801 801
802The following unary operators are available: @code{+}, @code{-}.802The following unary operators are available: @code{+}, @code{-}.
803 803
804Some internal variables can be used to store and load intermediary
805results. They can be accessed using the @code{ld} and @code{st}
806functions with an index argument varying from 0 to 9 to specify which
807internal variable to access.
808
804The following functions are available:809The following functions are available:
805@table @option810@table @option
806@item abs(x)811@item abs(x)
@@ -898,9 +903,9 @@ Return 1.0 if @var{x} is +/-INFINITY, 0.0 otherwise. · 91 unmodified lines
898@item isnan(x)903@item isnan(x)
899Return 1.0 if @var{x} is NAN, 0.0 otherwise.904Return 1.0 if @var{x} is NAN, 0.0 otherwise.
900 905
901@item ld(var)906@item ld(idx)
902Load the value of the internal variable with number907Load the value of the internal variable with index @var{idx}, which was
903@var{var}, which was previously stored with st(@var{var}, @var{expr}).908previously stored with st(@var{idx}, @var{expr}).
904The function returns the loaded value.909The function returns the loaded value.
905 910
906@item lerp(x, y, z)911@item lerp(x, y, z)
@@ -933,16 +938,14 @@ Compute the power of @var{x} elevated @var{y}, it is equivalent to · 26 unmodified lines
933 938
934@item print(t)939@item print(t)
935@item print(t, l)940@item print(t, l)
936Print the value of expression @var{t} with loglevel @var{l}. If941Print the value of expression @var{t} with loglevel @var{l}. If @var{l} is not
937@var{l} is not specified then a default log level is used.942specified then a default log level is used.
938Returns the value of the expression printed.943Return the value of the expression printed.
939
940Prints t with loglevel l
941 944
942@item random(idx)945@item random(idx)
943Return a pseudo random value between 0.0 and 1.0. @var{idx} is the946Return a pseudo random value between 0.0 and 1.0. @var{idx} is the
944index of the internal variable which will be used to save the947index of the internal variable used to save the seed/state, which can be
945seed/state.948previously stored with @code{st(idx)}.
946 949
947To initialize the seed, you need to store the seed value as a 64-bit950To initialize the seed, you need to store the seed value as a 64-bit
948unsigned integer in the internal variable with index @var{idx}.951unsigned integer in the internal variable with index @var{idx}.
@@ -955,8 +958,8 @@ st(0,42); print(random(0)); print(random(0)); print(random(0)) · 6 unmodified lines
955 958
956@item randomi(idx, min, max)959@item randomi(idx, min, max)
957Return a pseudo random value in the interval between @var{min} and960Return a pseudo random value in the interval between @var{min} and
958@var{max}. @var{idx} is the index of the internal variable which will961@var{max}. @var{idx} is the index of the internal variable which will be used to
959be used to save the seed/state.962save the seed/state, which can be previously stored with @code{st(idx)}.
960 963
961To initialize the seed, you need to store the seed value as a 64-bit964To initialize the seed, you need to store the seed value as a 64-bit
962unsigned integer in the internal variable with index @var{idx}.965unsigned integer in the internal variable with index @var{idx}.
@@ -968,14 +971,14 @@ with argument @var{ld(0)} is 0 in the interval 0..@var{max}. · 5 unmodified lines
968The expression in @var{expr} must denote a continuous function or the971The expression in @var{expr} must denote a continuous function or the
969result is undefined.972result is undefined.
970 973
971@var{ld(0)} is used to represent the function input value, which means974@var{ld(0)} is used to represent the function input value, which means that the
972that the given expression will be evaluated multiple times with975given expression will be evaluated multiple times with various input values that
973various input values that the expression can access through976the expression can access through @code{ld(0)}. When the expression evaluates to
974@code{ld(0)}. When the expression evaluates to 0 then the9770 then the corresponding input value will be returned.
975corresponding input value will be returned.
976 978
977@item round(expr)979@item round(expr)
978Round the value of expression @var{expr} to the nearest integer. For example, "round(1.5)" is "2.0".980Round the value of expression @var{expr} to the nearest integer. For example,
981"round(1.5)" is "2.0".
979 982
980@item sgn(x)983@item sgn(x)
981Compute sign of @var{x}.984Compute sign of @var{x}.
@@ -993,12 +996,15 @@ Compute the square root of @var{expr}. This is equivalent to · 11 unmodified lines
993@item squish(x)996@item squish(x)
994Compute expression @code{1/(1 + exp(4*x))}.997Compute expression @code{1/(1 + exp(4*x))}.
995 998
996@item st(var, expr)999@item st(idx, expr)
997Store the value of the expression @var{expr} in an internal1000Store the value of the expression @var{expr} in an internal
998variable. @var{var} specifies the number of the variable where to1001variable. @var{idx} specifies the index of the variable where to store
999store the value, and it is a value ranging from 0 to 9. The function1002the value, and it is a value ranging from 0 to 9. The function returns
1000returns the value stored in the internal variable.1003the value stored in the internal variable.
1001Note, Variables are currently not shared between expressions.1004
1005The stored value can be retrieved with @code{ld(var)}.
1006
1007Note: variables are currently not shared between expressions.
1002 1008
1003@item tan(x)1009@item tan(x)
1004Compute tangent of @var{x}.1010Compute tangent of @var{x}.
@@ -1007,16 +1013,16 @@ Compute tangent of @var{x}. · 2 unmodified lines
1007Compute hyperbolic tangent of @var{x}.1013Compute hyperbolic tangent of @var{x}.
1008 1014
1009@item taylor(expr, x)1015@item taylor(expr, x)
1010@item taylor(expr, x, id)1016@item taylor(expr, x, idx)
1011Evaluate a Taylor series at @var{x}, given an expression representing1017Evaluate a Taylor series at @var{x}, given an expression representing
1012the @code{ld(id)}-th derivative of a function at 0.1018the @code{ld(idx)}-th derivative of a function at 0.
1013 1019
1014When the series does not converge the result is undefined.1020When the series does not converge the result is undefined.
1015 1021
1016@var{ld(id)} is used to represent the derivative order in @var{expr},1022@var{ld(idx)} is used to represent the derivative order in @var{expr},
1017which means that the given expression will be evaluated multiple times1023which means that the given expression will be evaluated multiple times
1018with various input values that the expression can access through1024with various input values that the expression can access through
1019@code{ld(id)}. If @var{id} is not specified then 0 is assumed.1025@code{ld(idx)}. If @var{idx} is not specified then 0 is assumed.
1020 1026
1021Note, when you have the derivatives at y instead of 0,1027Note, when you have the derivatives at y instead of 0,
1022@code{taylor(expr, x-y)} can be used.1028@code{taylor(expr, x-y)} can be used.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t