Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / mathieeedoubbas / ieeedpfloor.c
blob6c0771362932f8b3323a181648bdd0396927a7c5
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeedoubbas_intern.h"
8 /*****************************************************************************
10 NAME */
12 AROS_LHQUAD1(double, IEEEDPFloor,
14 /* SYNOPSIS */
15 AROS_LHAQUAD(double, y, D0, D1),
17 /* LOCATION */
18 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 15, MathIeeeDoubBas)
20 /* FUNCTION
21 Calculates the floor-value of a IEEE double precision number
23 INPUTS
25 RESULT
26 +1 : y > z
27 0 : y = z
28 -1 : y < z
30 Flags:
31 zero : y = z
32 negative : y < z
33 overflow : 0
35 BUGS
37 INTERNALS
39 *****************************************************************************/
41 AROS_LIBFUNC_INIT
43 QUAD Mask;
44 QUAD y_tmp,y2;
45 int shift;
46 QUAD * Qy = (QUAD *)&y;
48 if (is_eqC(*Qy,0,0)) return *Qy;
50 Set_Value64(y_tmp, *Qy);
51 AND64QC(y_tmp, IEEEDPExponent_Mask_Hi, IEEEDPExponent_Mask_Lo );
53 if (is_lessC(y_tmp, one_Hi, one_Lo ))
55 if (is_lessSC(*Qy,0,0))
57 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
58 Set_Value64C
60 *Qy,
61 one_Hi | IEEEDPSign_Mask_Hi,
62 one_Lo | IEEEDPSign_Mask_Lo
64 return y;
66 else
68 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
69 Set_Value64C(*Qy, 0,0);
70 return y;
74 /* |fnum| >= 1 */
75 Set_Value64C(Mask, 0x80000000, 0x00000000);
76 SHRU32(shift, y_tmp, 52);
77 SHRS64(Mask, Mask, (shift-0x3ff+11)); /* leave the () there! StormC 1.1 needs 'em! */
79 /* y is negative */
80 if (is_leqSC(*Qy, 0x0, 0x0))
82 QUAD Mask2;
83 NOT64(Mask2, Mask);
84 Set_Value64(y2,*Qy);
85 AND64Q(y2, Mask2);
86 if (is_neqC(y2,0x0,0x0))
88 QUAD minusone;
89 double * Dminusone = (double *)&minusone;
90 Set_Value64C
92 minusone,
93 one_Hi | IEEEDPSign_Mask_Hi,
94 one_Lo | IEEEDPSign_Mask_Lo
96 *Qy = IEEEDPAdd(*Qy, *Dminusone);
97 Set_Value64C(Mask, 0x80000000, 0x00000000);
98 SHRU32(shift, y_tmp, 52);
99 SHRS64(Mask, Mask, (shift-0x3ff+11)); /* leave the () there! StormC 1.1 needs 'em! */
103 if (is_lessSC(*Qy,0x0,0x0))
105 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
108 AND64Q(*Qy, Mask);
110 return y;
112 AROS_LIBFUNC_EXIT