Option hfloat in Procedures
Calling Sequence
Description
Examples
option hfloat or options hfloat
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.
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:
time⁡SineSignal⁡duration=5.0
0.472
SlowSineSignal≔setattribute⁡copy⁡eval⁡SineSignal,no_options
SlowSineSignal ≔ procfreq::numeric ≔ 261.6255652,amp::numeric ≔ 1.0,duration::numeric ≔ 1.0,rate::integer ≔ 44100optionno_options;localfreq2pi;freq2pi ≔ evalhf⁡6.283185308*freq;AudioTools:-Create⁡':-duration'=duration,':-rate'=rate,sample→sin⁡freq2pi*sample − 1/rate*ampend proc
time⁡SlowSineSignal⁡duration=5.0
0.914
See Also
evalhf
HFloat
Procedure options
Procedures
Download Help Document