tcl::mathfunc::trunc
tcl::mathfunc::NAME arg ?arg ...?
The math functions of Tcl 9.1: the functions of C99 acosh, asinh, atanh, cbrt, copysign, dim (fdim of C), erf, erfc, exp2, expm1, fma, gamma (tgamma of C), ldexp, lgamma, log1p, log2, logb, nextafter, remainder, and trunc, and the tests isfinite, isinf, isnan, isnormal, issubnormal, isunordered, and signbit. Each function except a test gives a double. A test gives 0 or 1, and it takes NaN, an integer of any size, or a double.
This page also has tcl::mathfunc::acosh, tcl::mathfunc::asinh, tcl::mathfunc::atanh, tcl::mathfunc::cbrt, tcl::mathfunc::copysign, tcl::mathfunc::dim, tcl::mathfunc::erf, tcl::mathfunc::erfc, tcl::mathfunc::exp2, tcl::mathfunc::expm1, tcl::mathfunc::fma, tcl::mathfunc::gamma, tcl::mathfunc::isfinite, tcl::mathfunc::isinf, tcl::mathfunc::isnan, tcl::mathfunc::isnormal, tcl::mathfunc::issubnormal, tcl::mathfunc::isunordered, tcl::mathfunc::ldexp, tcl::mathfunc::lgamma, tcl::mathfunc::log1p, tcl::mathfunc::log2, tcl::mathfunc::logb, tcl::mathfunc::nextafter, tcl::mathfunc::remainder, tcl::mathfunc::signbit.
Examples
expr {trunc(-2.5)}gives-2.0expr {log2(8)}gives3.0expr {remainder(7, 2)}gives-1.0expr {isnan(NaN)}gives1expr {signbit(-0.0)}gives1
Errors
expr {log2(-1)}gives the errordomain error: argument not in valid rangeexpr {trunc("a")}gives the errorexpected floating-point number but got "a"
Facts
- Capability: none.
- Compute cost: one compute unit for the call, and more for the commands that it runs.
- Release: Tcl 9.1 only. A script has the command when ztcl follows Tcl 9.1, with
--tcl 9.1. See Tcl 9.1.
Differences from Tcl 8.6
- The functions come from
std.mathof Zig. The last digit of a result can differ from tclsh 9.1.0, which gives 3.0000000000000004 forcbrt(27). tclsh gives the error "floating-point value too large to represent" for some results below 2**-1022, such asasinh(1e-310), and ztcl gives the result.