Metatarget for copying of testfile fixed.
[AROS.git] / workbench / libs / mathffp / spcmp.c
blob83ebc7f72ca7fa667a8036db0c845f7a136f81d2
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathffp_intern.h"
8 /*
9 FUNCTION
10 Compares two ffp numbers
12 RESULT
13 <code>
14 +1 : fnum1 > fnum2
15 0 : fnum1 = fnum2
16 -1 : fnum1 < fnum2
19 Flags:
20 zero : fnum2 = fnum1
21 negative : fnum2 < fnum1
22 overflow : 0
23 </code>
25 NOTES
27 EXAMPLE
29 BUGS
31 SEE ALSO
34 INTERNALS
35 ALGORITHM:
36 <code>
37 1st case:
38 fnum1 is negative and fnum2 is positive
40 ( exponent(fnum1) < exponent(fnum2) and signs are equal )
41 -> fnum1 < fnum2
43 2nd case:
44 fnum1 is positive and fnum2 is negative
46 ( exponent(fnum1) > exponent(fnum2) and signs are equal )
47 -> fnum2 > fnum1
49 now the signs and exponents must be equal
51 3rd case:
52 fnum1 == fnum2
54 4th case:
55 mantisse(fnum1) < mantisse(fnum2)
56 -> fnum1 < fnum2
58 final case:
59 fnum1 > fnum2
60 </code>
61 HISTORY
64 AROS_LH2(LONG, SPCmp,
65 AROS_LHA(float, fnum1, D1),
66 AROS_LHA(float, fnum2, D0),
67 struct LibHeader *, MathBase, 7, Mathffp
70 AROS_LIBFUNC_INIT
72 D(kprintf("SPCmp(%08x,%08x)=", fnum1, fnum2));
74 /* fnum1 is negative and fnum2 is positive
75 ** or
76 ** exponent of fnum1 is less than the exponent of fnum2
77 ** => fnum1 < fnum2
79 if ( (char)fnum1 < (char)fnum2 )
81 D(kprintf("-1\n"));
82 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
83 return -1;
86 /* fnum1 is positive and fnum2 is negative
87 ** or
88 ** exponent of fnum1 is greater tban the exponent if fnum2
89 ** => fnum1 > fnum2
91 if ((char) fnum1 > (char) fnum2 )
93 D(kprintf("1\n"));
94 SetSR(0, Zero_Bit | Overflow_Bit | Negative_Bit );
95 return 1;
98 /*the signs and exponents of fnum1 and fnum2 must now be equal
99 **fnum1 == fnum2
101 if (fnum1 == fnum2)
103 D(kprintf("0\n"));
104 SetSR(Zero_Bit, Zero_Bit | Overflow_Bit | Negative_Bit);
105 return 0;
108 /* mantisse(fnum1) < mantisse(fnum2) */
109 if (fnum1 < fnum2)
111 D(kprintf("-1\n"));
112 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
113 return -1;
116 /* Mantisse(fnum1) > mantisse(fnum2) */
117 D(kprintf("1\n"));
118 SetSR(0, Zero_Bit | Negative_Bit | Overflow_Bit);
119 return 1;
121 AROS_LIBFUNC_EXIT