Technical article 100867

3.2v4.2-based application using floating point code runs incorrectly on OpenServer 5.0.4.

OpenServer 5.0.4OpenServer 5.0.5

Written · Last revised

Problem

The following program, when compiled on SCO UNIX System V/386
Release 3.2 Version 4.2 (3.2v4.2), runs correctly on SCO UNIX
Version 4.2 and SCO OpenServer 5.0.0 and 5.0.2.  However, when
run on SCO OpenServer 5.0.4, the floating point value comparison
in this program fails.

If the code is *compiled* and executed on OpenServer 5.0.4, then it will work correctly.

Using SCO XENIX/DOS Cross Development compiler 'xcc' on OpenServer 5.0.0, 5.0.2, 5.0.4 will also generate a failing binary.

<---------------------------CUT HERE---------------------------------------->
/*
        cc scotest.c -lm -o scotest
This program will fail if:

(a) compiled on 3.2v4.2 and run on v5.0.4 (b) compiled with the XENIX/DOS Cross compiler 'xcc' on v5.0.[024] and run on v5.0.4

This program will succeed if:

(a) compiled on 3.2v4.2 and run on v5.0.[02] (b) re-compiled on any release of SCO OpenServer 5.0.[024]

*/
#include <stdio.h>
#include <math.h>
double mspower(x,y)
double x,y;
{
        double d,ip;
double floor(),ceil();
d=(pow(x,y)+0.00000001)*1000000.0;
#if defined (DEBUG)
        printf(" pt1: (%lf)\n",d);
#endif
        ip=(d>0.0)?floor(d):ceil(d);
#if defined (DEBUG)
        printf(" pt2: (%lf)\n",ip);
#endif
return(ip/1000000.0);
}
main()
{
        double test_val;

test_val=10.0; if ( test_val != mspower((double) 10, (double) 1)) printf(" Values are not equal!\n"); else printf(" Values are equal!\n");

#if defined (DEBUG)
        printf(" Value returned by POW is (%.15f)\n",
                mspower((double) 10, (double) 1));
#endif
}
<---------------------------CUT HERE---------------------------------------->
NOTES:    This problem is fixed in SCO OpenServer Release 5.0.6.

Solution

This behavior was introduced by the changes made to the floating-point driver in SCO OpenServer 5.0.4. Replacing the /etc/conf/pack.d/fp/Driver.o on 5.0.4 with the previous driver from 5.0.2 will result in both the version 4.2 and 5.0.4 binaries working successfully.

Another possible workaround is to patch the floating-point driver in SCO OpenServer 5.0.4 so that it's initialized in the same way that it was in previous releases of SCO OpenServer 5. In order to patch the driver in this way, do the following:

1. First, make a backup of the /etc/conf/pack.d/fp/Driver.o file.

2. Then patch the fp/Driver.o as follows:

# /etc/_fst -w /etc/conf/pack.d/fp/Driver.o
* finitstate/X
finitstate:        0x137f
* finitstate/W 0x1272
finitstate:        0x137f= 0x1272  (this confirms that the current
                                    value of 0x137f has now been
                                    changed to 0x1272)
* $q

NOTE: On certain pre-release versions of OpenServer 5.0.4, finitstate/X may return the value 0x1372 instead of 0x137f, but this technical article will still work correctly.

3. Relink the UNIX kernel and reboot the system.

From the Xinuos technical article database, record 100867. Reproduced with permission. The original is at www.sco.com/ta/100867, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.