PDA

View Full Version : LF95 Linux: Incorrect results with C main.


Lahey Support
12-08-2003, 11:20 PM
LF95 Linux: Incorrect results with C main.

Lahey issue number: 1004-96239

<hr>

The information in this post applies to:

LF95 Linux PRO
LF95 Linux Express

Symptoms

Incorrect arithmetic results obtained if a project uses a C main calling Fortran routines.

Cause

This problem is caused by the difference of the mantissa bits between
LF95 and gcc. In floating point arithmetic, lf95 uses 53 bit mantissa, and gcc uses 64 bit mantissa (example in trig.c).

Workaround

Build project with Fortran main or insert the assembler command which
changes from 64bit to 53bit in a C main.


Status

Open.


Source, trig.c:

main ()
{

/* 80x87 control word
15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
+--+--+--+--+-----+-----+--+--+--+--+--+--+--+--+
| | | |IC| RC | PC |IE| |PM|UM|OM|ZM|DM|IM|
+--+--+--+--+-----+-----+--+--+--+--+--+--+--+--+
*/
short ctrlword;

asm("fstcw %0":"=g"(ctrlword));
ctrlword = (ctrlword & ~(0x0300)) | 0x0200;
asm("fldcw %0"::"g"(ctrlword));

printtrigs_ ();
}