11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.2 Hardware Floating-Point Numbers • 1991.40300383684168617> evalhf(Digits);15.> Digits := 10;Digits := 10You can use the evalhf(Digits) construct to determine whetherhardware floating-point arithmetic provides sufficient precision in a particularapplication. If Digits is less than evalhf(Digits), then you cantake advantage of the faster hardware floating-point calculations. Otherwise,you should use software floating-point arithmetic to perform thecalculation, with sufficient digits. The following evaluate procedure takesan unevaluated parameter, expr. Without the uneval declaration, Maplewould evaluate expr symbolically before invoking evaluate.> evaluate := proc(expr::uneval)> if Digits < evalhf(Digits) then> evalf(evalhf(expr));> else> evalf(expr);> end if;> end proc:The evalhf command evaluates many Maple functions, but not all.For example, you cannot evaluate an integral using hardware floatingpointarithmetic.> evaluate( Int(exp(x^3), x=0..1) );Error, (in evaluate) unable to evaluate function ‘Int‘in evalhfYou can improve the evaluate procedure so that it traps sucherrors and tries to evaluate the expression using software floating-pointnumbers instead.> evaluate := proc(expr::uneval)> local result;> if Digits < evalhf(Digits) then> try> return evalf(evalhf(expr));> catch:> end try;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!