generate::Macrofort::setPrecisionOption
-- sets precision
IntroductionMac::setPrecisionOption (where
Mac:=generate::Macrofort) sets the precision (single,
double or quadruple) for the FORTRAN code generated by
Mac::genFor.
Call(s)generate::Macrofort::setPrecisionOption(s)
Parameterss |
- | one of the strings "single",
"double" or "quadruple". |
Returnsthe void object of domain type DOM_NULL
Side
EffectsResets the global macrofort precision variable for the FORTRAN code
generated by generate::Macrofort::genFor.
Related
FunctionsDIGITS, generate::Macrofort::init,
generate::Macrofort::genFor
Details"single"), 16 digits ("double") or
32 digits ("quadruple"). Intrinsic FORTRAN functions are
often written with a prefix "d" for double precision or a
prefix "q" for quadruple precision. E.g. the functions
sin or cos as used in single precision become
respectively dsin dcos in double precision or
qsin and qcos in quadruple precision
(although some compilers adhere to a standard which does not need these
prefixes). The advantage is that MuPAD readily allows the user to
generate constants like PI to any accuracy without
mistakes.Mac::setPrecisionOption (where
Mac:=generate::Macrofort) is used with
Mac::genFor and Mac::init (see these programs
for more details) and adjusts the Macrofort (internal) global variable
for precision. The default setting for this variable made by an initial
call to Mac::init is "single" for the
resulting FORTRAN code.DIGITS and making a call
to float). Mac::genFor resets the value of
DIGITS to 8,16 or 32 depending on the choice of
precision.
Example
1Initialize Macrofort and open file
"test.f"
>> Mac := generate::Macrofort:
Mac::init():
Mac::openOutputFile("test.f"):
This example generates the same FORTRAN assignment in respectively single, double and quadruple precisions.
>> Mac::setPrecisionOption("single"):
Mac::genFor(["equal", a, 1.0 + PI*sinh(E)]):
Mac::setPrecisionOption("double"):
Mac::genFor(["equal", a, 1.0 + PI*sinh(E)]):
Mac::setPrecisionOption("quadruple"):
Mac::genFor(["equal", a, 1.0 + PI*sinh(E)]):
Mac::closeOutputFile():
delete a:
The output file test.f is:
a = 0.3141593E1*sinh(0.2718282E1)+0.1E1
a = 0.3141592653589793D1*dsinh(0.2718281828459045D1)+0.1D1
a = 0.31415926535897932384626433832795Q1*qsinh(0.27182818284590452
#353602874713527Q1)+0.1Q1
See the help-file for Mac::genFor for a more
comprehensive list of examples.