www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - 8087 precision and _beginthread

Hi All

Here's a nasty little bug in the runtime library:

In the DM C++ startup code, the 80x87 control word is intialized to 0x137F such
that arithmetic is performed with 80 bit precision.

But when a new thread is started, it is initialized to 0x027F which specifies
only 64 bit precision. This is probably a default set by Windows. 

So the results of floating opertions can differ according to whether they are
performed in the main application thread, or in a worker thread!!!

The code in thread.c seems to initialize a t->f_env structure, but this isn't
the same as actually loading the value in the 80x87 control word; I'm a little
loath to modify this code as I don't know exactly the purpose of t->fenv i.e.
when it is loaded into the FCPU.

Meanwhile you can do

WORD newcw 0x137F
asm fldcw newcw;

at the start of worker threads to correctly initialize them for 80 bit
precision.

Best Regards 
John
Apr 04 2006