Flexscript standard library has built-in functions to draw random samples from many probability distributions, but is surprisingly lacks some common math functions:
- tgamma, lgamma, beta (gamma function and beta function respectively)
- erf, erfc (Gauss error function)
- all hyperbolic function and their inverses (tanh, atanh, etc)
- log1p, expm1
The lack of the hyperbolic functions is a minor annoyance: there are exp and log functions after all.
The lack of the gamma function is more difficult to accept. It is necessary to calculate the parameters of the Weibull distribution with a given mean, which, I suppose, is a pretty common thing in the discrete event simulation.
Fortunately, most of these functions are already implemented in the standard C++ library. Even more are supported in C++17.
My current workaround to run std::tgamma() or similar is to create a module with a DLL library, export a wrapper for each of the standard functions like
_declspec(dllexport) Variant tgamma_wrapper(FLEXSIMINTERFACE) { return std::tgamma(param(1)); }
then create a corresponding usercommand in FlexSim, change its code node to DLL type, and point it to tgammer_wrapper. That's a lot of work, and a lot of unnecessary overhead. I suppose the built-in Flexscript functions can do it more efficiently.
It would be nice if tgamma and other special functions were available in Flexscript.
Another group of standard math functions that Flexscript needs are functions like
- isinf and INFINITY literal
- isnan and NAN literal
- isnormal
They're already in the C++ standard library.