[CLN-list] Operations with different precisions
bruno at clisp.org
Mon Oct 12 23:54:21 CEST 2009
Sebastian Macke wrote:
[Please keep cln-list in CC. If you write to me privately, the probability that
you get a response is less than 0.3.]
> I used your library with a template class.
> template <class T>
> Here I define one and zero as
Please read again the essential, central chapter "Ordinary number types"
of the CLN documentation.
From it, it follows that
- Numbers such as 1.0 or 0.0 are floating-points and thus are approximate.
- If you want a "one" and "zero" in a ring, you should take exact numbers,
(cl_I)1 or (cl_I)0.
- You don't need templates, because the cl_F, cl_R, cl_N types already
comprise 'float' and 'double' (and longer) precisions.
> This works without problem with float, double and long double
> But with your implementation I can lose precision.
In the previous mail I explained to you that when you combine two floating-
point numbers with different precision, the result will have an accuracy
that approximately equals the minimum of the two precisions. This is a
mathematical property of the definition of accuracy. (You can verify it
with interval arithmetic or with statistics, if you like.)
You then have the choice:
- Return a result with a precision approximately equal to its accuracy.
This is what CLN does. Or
- Return a result whose precision is the *maximum* of the two precisions.
If you do this, you are betraying the user of your program.
More information about the CLN-list