[petsc-users] format specifiers

Jed Brown jed at 59A2.org
Wed Apr 13 12:59:13 CDT 2011


On Wed, Apr 13, 2011 at 19:24, Gaurish Telang <gaurish108 at gmail.com> wrote:

> Hmm, %f seems to be working fine for these data types. Is there any harm in
> using it though?


If you are referring to just using plain "%f" (or any single % specifier) to
show a PetscScalar, that's a matter of whether you have configured so that
PetscScalar is real or compex valued. It will not work when you use complex.

If you meant using %f instead of %G in my example above, that is a matter of
precision:

PetscPrintf converts %G (but not currently variants like %12.5G) to a
representation that works for any choice of precision. For example, '%g' for
double and float [1], %Lg for long double, %Qe for __float128. Similarly,
%[1-9]D is converted to %d or %lld depending the use of 64-bit indices. If
you only ever use double and native ints (usually 32-bit), then you don't
have to worry about these conversions and you can use whatever you want.


[1] The standard specifies that float is promoted to double when calling a
function with no prototype or a variadic function. The same rule promotes
char and short int to int.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110413/be3d70c5/attachment.htm>


More information about the petsc-users mailing list