Subject: Re: accuracy of "long double"
To: None <10.50@free.fr>
From: Matthias Drochner <M.Drochner@fz-juelich.de>
List: tech-kern
Date: 09/03/2007 20:23:56
10.50@free.fr said:
> I failed to located where exactly the FP control word is set for
> <double> operation

It is initialized in machdep.c:setregs().

> There is a test in npx.c where this register is compared
> with 0x03XX

That's just an initial check to tell whether there is an FPU at all.
(could probably be skipped if it is reported by cpuid)

> Odd enough, there are also some libm functions that purposely alter the CW bit
> to enter full precision mode.

Afais in almost all cases the rounding mode is changed, to
implement floor()/ceil().
(btw, gcc will issue similar code to implement typecasts from
floating-point to int which requires clipping rather than rounding.
That's why lrint() should be used if the algorithm allows.)

As I see there is just one case where 64-bit mode is used: for exp()
which is implemented by a scaled 2^x. Obviously to avoid intermediate
rounding errors.

> All in all, all that seems a bit messy ! :)

It is complex matter, and there are some tradeoffs. Imho, one is better
off using just "double" -- the code is portable, and even on i386 it
can benefit from SSE2 and successors.

best regards
Matthias




-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
Forschungszentrum Juelich GmbH
52425 Juelich

Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDirig'in Baerbel Brumme-Bothe
Vorstand: Prof. Dr. Achim Bachem (Vorsitzender), Dr. Ulrich Krafft (stellv. 
Vorsitzender)
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------