revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / mathieeedoubbas / ieeedpfloor.c
blobb9de83925936833c8c316da799794acea78d4f09
1 /*
2 Copyright © 1995-2017, 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 an IEEE double precision number.
23 INPUTS
24 y - IEEE double precision floating point number.
26 RESULT
27 x - floor of y.
29 Flags:
30 zero : result is zero
31 negative : result is negative
32 overflow : 0
34 NOTES
36 EXAMPLE
38 BUGS
40 SEE ALSO
41 IEEEDPCeil(), IEEEDPFix()
43 INTERNALS
45 *****************************************************************************/
47 AROS_LIBFUNC_INIT
49 QUAD Mask;
50 QUAD y_tmp,y2;
51 int shift;
52 QUAD * Qy = (QUAD *)&y;
54 if (is_eqC(*Qy,0,0)) return *Qy;
56 Set_Value64(y_tmp, *Qy);
57 AND64QC(y_tmp, IEEEDPExponent_Mask_Hi, IEEEDPExponent_Mask_Lo );
59 if (is_lessC(y_tmp, one_Hi, one_Lo ))
61 if (is_lessSC(*Qy,0,0))
63 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
64 Set_Value64C
66 *Qy,
67 one_Hi | IEEEDPSign_Mask_Hi,
68 one_Lo | IEEEDPSign_Mask_Lo
70 return y;
72 else
74 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
75 Set_Value64C(*Qy, 0,0);
76 return y;
80 /* |fnum| >= 1 */
81 Set_Value64C(Mask, 0x80000000, 0x00000000);
82 SHRU32(shift, y_tmp, 52);
83 SHRS64(Mask, Mask, (shift-0x3ff+11)); /* leave the () there! StormC 1.1 needs 'em! */
85 /* y is negative */
86 if (is_leqSC(*Qy, 0x0, 0x0))
88 QUAD Mask2;
89 NOT64(Mask2, Mask);
90 Set_Value64(y2,*Qy);
91 AND64Q(y2, Mask2);
92 if (is_neqC(y2,0x0,0x0))
94 QUAD minusone;
95 double * Dminusone = (double *)&minusone;
96 Set_Value64C
98 minusone,
99 one_Hi | IEEEDPSign_Mask_Hi,
100 one_Lo | IEEEDPSign_Mask_Lo
102 *Qy = IEEEDPAdd(*Qy, *Dminusone);
103 Set_Value64C(Mask, 0x80000000, 0x00000000);
104 SHRU32(shift, y_tmp, 52);
105 SHRS64(Mask, Mask, (shift-0x3ff+11)); /* leave the () there! StormC 1.1 needs 'em! */
109 if (is_lessSC(*Qy,0x0,0x0))
111 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
114 AND64Q(*Qy, Mask);
116 return y;
118 AROS_LIBFUNC_EXIT