 option hfloat - Maple Help

Option hfloat in Procedures Calling Sequence option hfloat   or   options hfloat Description

 • The hfloat option to a procedure forces all floating-point operations in a procedure to be performed using hardware floating-point values. Depending on the operations performed, this can significantly speed up execution of the procedure, at the cost of floating-point accuracy. Procedures that perform many floating-point operations or manipulate the contents of Arrays, Matrices, or Vectors of hardware floating-point values will benefit the most from this option.
 • Specifically, the hfloat option causes the following differences in the procedure's definition and execution:
 – Any floating-point constants appearing in the procedure body are converted into hardware floating-point values when the procedure is first created.
 – Numeric arguments passed to the procedure are converted into hardware floating-point values when the procedure is invoked.
 – Calls to evalhf made from within the procedure will return a hardware floating-point value, and thus will not incur a conversion to arbitrary precision floating-point form.
 • The differences, together with the rules for contagion of hardware floating-point values in expressions (see HFloat), will usually cause arithmetic operations in the procedure to be performed using hardware floating-point arithmetic.
 • The use of the hfloat option differs from using evalhf in a few ways:
 – When a procedure is executed within the evalhf environment, everything is performed using hardware floats, and the operations available are restricted to those that can be done using hardware floats. No other basic data types, such as integers or strings, are available.
 – The only data structures available within the evalhf environment are Arrays.
 • Performance of a procedure having option hfloat will generally be better than one operating with arbitrary precision floats, but usually not as good as a procedure operating within evalhf. But, a procedure with option hfloat has the full power of Maple available to it. All Maple operations, data types (except arbitrary precision software floating point), and data structures can be used in such a procedure.
 • The hfloat option cannot be used in conjunction with any of these other options: autocompile, builtin, call_external, and inline. Examples

 > SineSignal := proc( freq :: numeric := 261.6255652,                    amp :: numeric := 1.0,                  { duration :: numeric := 1.0,                    rate :: integer := 44100 } )    option hfloat;    local freq2pi := evalhf(freq * 2.0 * Pi);    AudioTools:-Create(':-duration'=duration,':-rate'=rate,                          sample->sin(freq2pi*(sample-1)/rate) * amp); end:
 > $\mathrm{time}\left(\mathrm{SineSignal}\left(\mathrm{duration}=5.0\right)\right)$
 ${0.558}$ (1)
 > $\mathrm{SlowSineSignal}≔\mathrm{setattribute}\left(\mathrm{copy}\left(\mathrm{eval}\left(\mathrm{SineSignal}\right)\right),\mathrm{no_options}\right)$
 ${\mathrm{SlowSineSignal}}{≔}{\mathbf{proc}}\left({\mathrm{freq}}{::}{\mathrm{numeric}}{≔}{261.6255652}{,}{\mathrm{amp}}{::}{\mathrm{numeric}}{≔}{1.0}{,}\left\{{\mathrm{duration}}{::}{\mathrm{numeric}}{≔}{1.0}{,}{\mathrm{rate}}{::}{\mathrm{integer}}{≔}{44100}\right\}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{option}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{no_options}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{freq2pi}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{freq2pi}}{≔}{\mathrm{evalhf}}{}\left({6.283185308}{*}{\mathrm{freq}}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{AudioTools}}{:-}{\mathrm{Create}}{}\left({'}{}{:-}{\mathrm{duration}}{'}{=}{\mathrm{duration}}{,}{'}{}{:-}{\mathrm{rate}}{'}{=}{\mathrm{rate}}{,}{\mathrm{sample}}{→}{\mathrm{sin}}{}\left({\mathrm{freq2pi}}{*}\left({\mathrm{sample}}{-}{1}\right){/}{\mathrm{rate}}\right){*}{\mathrm{amp}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (2)
 > $\mathrm{time}\left(\mathrm{SlowSineSignal}\left(\mathrm{duration}=5.0\right)\right)$
 ${7.784}$ (3)