Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / mathieeedoubbas / ieeedpfix.c
blob0042959c848aa4a54a43aff1dc90fb7b0a63d1f7
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(LONG, IEEEDPFix,
14 /* SYNOPSIS */
15 AROS_LHAQUAD(double, y, D0, D1),
17 /* LOCATION */
18 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 5, MathIeeeDoubBas)
20 /* FUNCTION
21 Convert IEEE double precision floating point number to integer
23 INPUTS
25 RESULT
26 absolute value of y
28 Flags:
29 zero : result is zero
30 negative : result is negative
31 overflow : ieeedp out of integer-range
33 BUGS
35 INTERNALS
37 *****************************************************************************/
39 AROS_LIBFUNC_INIT
41 LONG Res, Shift, tmp;
42 QUAD y2;
43 QUAD * Qy = (QUAD *)&y;
45 tmp = Get_High32of64(*Qy) & IEEEDPExponent_Mask_Hi;
47 if ( tmp > 0x41d00000 )
49 if( is_lessSC(*Qy, 0x0, 0x0))
51 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
52 return 0x80000000;
54 else
56 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
57 return 0x7fffffff;
62 if(
63 is_eqC(*Qy, 0x0, 0x0)
64 || is_eqC(*Qy,IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo)
65 ) /* y=+-0; */
67 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
68 return 0;
71 Shift = (Get_High32of64(*Qy) & IEEEDPExponent_Mask_Hi) >> 20;
72 Shift = 0x433 - Shift;
73 tmp = Get_High32of64(*Qy);
74 AND64QC(*Qy, IEEEDPMantisse_Mask_Hi, IEEEDPMantisse_Mask_Lo);
75 OR64QC(*Qy, 0x00100000, 0x00000000);
76 SHRU64(y2, *Qy , Shift);
77 Res = Get_Low32of64(y2);
79 /* Test for a negative sign */
80 if (tmp < 0) /* y < 0 */
82 Res = -Res;
83 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
86 return Res;
88 AROS_LIBFUNC_EXIT