[DGD] DGD 1.6.2 and Hydra 1.3.9

Felix A. Croes felix at dworkin.nl
Mon Jan 22 00:29:34 CET 2018


"nikoroleva ." <natasha.i.koroleva at gmail.com> wrote:

> I want to convert these vectors' units:
>
> R = { 0.857033096, -0.493251623, -0.213830204 } (astronomical units)
> V = { 0.00886739864, 0.0133184022, 0.0057727916 } (astronomical units per day)
>
> Basic code for conversion:
>
> float au_to_km(float au)
> {
>     return au * 1.49597870691e+8;
> }
>
> float aupd_to_kms(float au_per_day)
> {
>     return au_per_day * 1731.45684;
> }
>
> f1 = R_x = 0.857033096
> f2 = R_y = -0.493251623
> f3 = R_z = -0.213830204
>
> f4 = V_x = 0.00886739864
> f5 = V_y = 0.0133184022
> f6 = V_z = 0.0057727916
>
> The results are below. Using floats in DGD or a C program yield same results.
> But it seems that I would prefer to have doubles instead; gets closer
> to the Matlab/Octave results.

This is quite interesting, but it's not the whole story.  Take a look at
the generated file /include/float.h and you'll see that DGD floats have
more precision than ordinary floats:

    # define FLT_DIG        11
    # define FLT_MANT_DIG   37
    # define FLT_MAX_EXP    1024
    # define FLT_MAX_10_EXP 308

DGD floats have 37 bits of precision.  That is more than IEEE floats,
which only have 24 bits of precision.  IEEE doubles have 53 bits of
precision.

As a matter of fact, the DGD host float implementation is backed by C
doubles.  I just chose to display fewer digits of precision when a
floating point number is converted to a string than are actually
available.

DGD floats always have the same precision, no matter if they are backed
by simulated floats or host floats (actually doubles).  They also have
the same representation in snapshots.  And the host float backing doesn't
really require IEEE doubles, it just requires a floating point type
that is as least as precise as DGD's type.

Perhaps you are going to argue that anything less than double precision
is not enough.  But then, are doubles really precise enough?  I have a
working implementation of simulated floating point numbers with 81 bits
of precision for Hydra.  Much more precise than the 53 bits in doubles,
wouldn't you agree?  Better even than Intel's extended floating point
format, which only has 64 bits of precision.  If you really want to
perform astronomical computations, doubles are not good enough.

I do think that for serious mathematical computations, DGD's floats are
not precise enough, as well as not fast enough.  That is why I recommend
that such computations only be done in LPC in a first version, later to
be replaced by an extension module which performs the same operations in
optimized vectorized floating point code.

Regards,
Felix Croes



More information about the DGD mailing list