← Back to team overview

ffc team mailing list archive

Re: -fprecision!=15

 

On Wed, Aug 20, 2008 at 10:08:48AM -0600, Ostien, Jakob T wrote:
> Hi,
> 
> Just for fun I tried to compile a form with -fprecision=32, to see if that would impact a problem I was seeing.  The generated code was not what I expected.
> 
> For example, using the default, the factor 1/3 is represented as:
>   0.333333333333333
> 
> But for -fprecision=32 (for the same form) 1/3 becomes
>   0.33333333333333331482961625624739
> 
> Obviously that latter isn't really that much better than the former.
> 
> Is this known?  I can only guess what's happening, anyone have a solid idea?  Possibly (hopefully) its an environment issue that I can fix locally.
> 
> Jake

It's very simple. FFC (and Python) computes with double precision so
you only have 16 digits. If you ask for more digits, you will get more
digits but they can be anything.

Just try the following in Python:

>>> print "%.32f" % 1.0
1.00000000000000000000000000000000
>>> print "%.32f" % 1.1
1.10000000000000008881784197001252
>>> print "%.32f" % 1.5
1.50000000000000000000000000000000
>>> print "%.32f" % 1.6
1.60000000000000008881784197001252

-- 
Anders

Attachment: signature.asc
Description: Digital signature


References