
Calling Sequence


option hfloat or options hfloat


Description


•

The hfloat option to a procedure forces all floatingpoint operations in a procedure to be performed using hardware floatingpoint values. Depending on the operations performed, this can significantly speed up execution of the procedure, at the cost of floatingpoint accuracy. Procedures that perform many floatingpoint operations or manipulate the contents of Arrays, Matrices, or Vectors of hardware floatingpoint values will benefit the most from this option.

•

Specifically, the hfloat option causes the following differences in the procedure's definition and execution:

–

Any floatingpoint constants appearing in the procedure body are converted into hardware floatingpoint values when the procedure is first created.

–

Numeric arguments passed to the procedure are converted into hardware floatingpoint values when the procedure is invoked.

–

Calls to evalhf made from within the procedure will return a hardware floatingpoint value, and thus will not incur a conversion to arbitrary precision floatingpoint form.

•

The differences, together with the rules for contagion of hardware floatingpoint values in expressions (see HFloat), will usually cause arithmetic operations in the procedure to be performed using hardware floatingpoint 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*(sample1)/rate) * amp);
end:

>

$\mathrm{time}\left(\mathrm{SineSignal}\left(\mathrm{duration}=5.0\right)\right)$

>

$\mathrm{SlowSineSignal}\u2254\mathrm{setattribute}\left(\mathrm{copy}\left(\mathrm{eval}\left(\mathrm{SineSignal}\right)\right)\,\mathrm{no\_options}\right)$

${\mathrm{SlowSineSignal}}{\u2254}{\mathbf{proc}}\left({\mathrm{freq}}{::}{\mathrm{numeric}}{\u2254}{261.6255652}{\,}{\mathrm{amp}}{::}{\mathrm{numeric}}{\u2254}{1.0}{\,}\left\{{\mathrm{duration}}{::}{\mathrm{numeric}}{\u2254}{1.0}{\,}{\mathrm{rate}}{::}{\mathrm{integer}}{\u2254}{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}}{\u2254}{\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)$



