evalhf - Maple Programming Help

evalhf

evaluate an expression using hardware floating-point

 Calling Sequence evalhf(expr)

Parameters

 expr - expression to be evaluated numerically

Description

 • A call to evalhf evaluates an expression to a numerical value using the floating-point hardware of the underlying system. The evaluation is done in double precision.
 • In some cases evalhf may call evalf for evaluation of some special functions with complex arguments, or with real arguments leading to complex results.
 • The argument of evalhf must be an expression that evaluates to a single value; an hfarray or rtable with $\mathrm{datatype}={\mathrm{float}}_{8}$, $\mathrm{double}$, or ${\mathrm{complex}}_{8}$; or a procedure. As opposed to evalf, no other symbolic answers are permitted.
 • The argument evaluated by evalhf can include function calls, either to standard functions (such as sin and arctan; see evalhf/fcnlist) or to user-defined functions in Maple.  There are restrictions on user-defined functions to be properly evaluated within the evalhf environment. For details, see evalhf/procedure.
 • The evalhf function converts all its arguments to hardware floats, computes the answer and converts the answer to a Maple float result. Hence the user never deals with hardware floating-point numbers; these are confined to evalhf.
 • It is advantageous to do as much computation as possible within a single call to evalhf, to avoid the conversion overhead.
 • When evalhf returns an hfarray or rtable with $\mathrm{datatype}={\mathrm{float}}_{8}$, $\mathrm{datatype}=\mathrm{double}$, or $\mathrm{datatype}={\mathrm{complex}}_{8}$, no conversion to Maple floats takes place until the time that elements of the array are accessed. Even then, only the accessed elements are converted. Using hfarrays or rtables with $\mathrm{datatype}={\mathrm{float}}_{8}$, $\mathrm{double}$, or ${\mathrm{complex}}_{8}$, it is possible to pass data between invocations of evalhf at almost no cost.
 • Maple includes evalhf for the purpose of gaining speed in numerical computations or for users who wish to use the hardware floating-point system.
 • If Digits is set equal to (the integer part of) the special value evalhf(Digits) (approximately 15 on many 32-bit architectures) then evalf and evalhf (when both succeed) should produce similar results.
 • In the evalhf environment, non-default numeric event handling settings are not guaranteed to be respected.

 • The evalhf command is thread safe as of Maple 15, provided that evaluating the given expression is itself thread safe.

Examples

 > $\mathrm{evalhf}\left(\mathrm{sin}\left({ⅇ}^{\mathrm{gamma}+2}+\mathrm{ln}\left(\mathrm{cos}\left(\mathrm{Catalan}\right)\right)\right)\right)$
 ${0.0980197901238379354}$ (1)
 > $A≔\mathrm{Matrix}\left(3,2,\left(i,j\right)→i+jI,\mathrm{datatype}={\mathrm{complex}}_{8}\right)$
 ${A}{≔}\left[\begin{array}{cc}{1.}{+}{I}& {1.}{+}{2.}{}{I}\\ {2.}{+}{I}& {2.}{+}{2.}{}{I}\\ {3.}{+}{I}& {3.}{+}{2.}{}{I}\end{array}\right]$ (2)
 > $\mathrm{evalhf}\left(\mathrm{map}\left(\mathrm{sin},A\right)\right)$
 $\left[\begin{array}{cc}{1.29845758141598}{+}{0.634963914784736}{}{I}& {3.16577851321617}{+}{1.95960104142161}{}{I}\\ {1.40311925062204}{-}{0.489056259041294}{}{I}& {3.42095486111701}{-}{1.50930648532362}{}{I}\\ {0.217759551622152}{-}{1.16344036370325}{}{I}& {0.530921086248520}{-}{3.59056458998578}{}{I}\end{array}\right]$ (3)
 > f := proc(n) if n<2 then n else (n+1)*f(n-1)/n end if end proc:
 > $\mathrm{evalhf}\left(f\left(100\right)+f\left(10\right)+f\left(1\right)\right)$
 ${57.}$ (4)
 > g := proc(x) x^5*ln(x)/(1+x^2) end proc:
 > $\mathrm{evalhf}\left(g\left(2\right)\right)$
 ${4.43614195558364965}$ (5)
 > $\mathrm{solutions}≔\mathrm{solve}\left({x}^{3}=-3\right)$
 ${\mathrm{solutions}}{≔}{-}{{3}}^{{1}}{{3}}}{,}\frac{{{3}}^{{1}}{{3}}}}{{2}}{-}\frac{{I}{}{{3}}^{{5}}{{6}}}}{{2}}{,}\frac{{{3}}^{{1}}{{3}}}}{{2}}{+}\frac{{I}{}{{3}}^{{5}}{{6}}}}{{2}}$ (6)
 > $\mathrm{map}\left(\mathrm{evalhf},\left[\mathrm{solutions}\right]\right)$
 $\left[{-1.44224957030740830}{,}{0.721124785153704151}{-}{1.24902476648340643}{}{I}{,}{0.721124785153704151}{+}{1.24902476648340643}{}{I}\right]$ (7)
 > $\mathrm{Digits}≔\mathrm{trunc}\left(\mathrm{evalhf}\left(\mathrm{Digits}\right)\right)$
 ${\mathrm{Digits}}{≔}{15}$ (8)
 > $\mathrm{evalf}\left(g\left(2\right)\right)$
 ${4.43614195558365}$ (9)