Pristine Ack-5.5
[Ack-5.5.git] / mach / proto / fp / cmf8.c
1 /*
2   (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
3   See the copyright notice in the ACK home directory, in the file "Copyright".
4 */
5
6 /* $Id: cmf8.c,v 1.10 1994/06/24 13:31:35 ceriel Exp $ */
7
8 /*
9         COMPARE DOUBLES (CMF 8)
10 */
11
12 #include        "FP_types.h"
13 #include        "get_put.h"
14
15 int
16 cmf8(d1,d2)
17 DOUBLE  d1,d2;
18 {
19 #define SIGN(x) (((x) < 0) ? -1 : 1)
20                 /*
21                  * return ((d1 < d2) ? 1 : (d1 > d2) ? -1 : 0))
22                  */
23         long    l1,l2;
24         int     sign1,sign2;
25         int     rv;
26
27 #if FL_MSL_AT_LOW_ADDRESS
28         l1 = get4((char *)&d1);
29         l2 = get4((char *)&d2);
30 #else
31         l1 = get4(((char *)&d1+4));
32         l2 = get4(((char *)&d2+4));
33 #endif
34         sign1 = SIGN(l1);
35         sign2 = SIGN(l2);
36         if (sign1 != sign2) {
37                 l1 &= 0x7fffffff;
38                 l2 &= 0x7fffffff;
39                 if (l1 != 0 || l2 != 0) {
40                         return ((sign1 > 0) ? -1 : 1);
41                 }
42         }
43         if (l1 != l2)   {       /* we can decide here */
44                 rv = l1 < l2 ? 1 : -1;
45         }
46         else    {               /* decide in 2nd half */
47                 unsigned long u1, u2;
48 #if FL_MSL_AT_LOW_ADDRESS
49                 u1 = get4(((char *)&d1 + 4));
50                 u2 = get4(((char *)&d2 + 4));
51 #else
52                 u1 = get4((char *)&d1);
53                 u2 = get4((char *)&d2);
54 #endif
55                 if (u1 == u2)
56                         return(0);
57                 if (u1 < u2) rv = 1;
58                 else rv = -1;
59         }
60         return sign1 * rv;
61 }