Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / mathieeedoubbas / ieeedpfix.c
blob40a8011606391c84c25038701cb0654b3bd50d73
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeedoubbas_intern.h"
8 /*
9 FUNCTION
10 Convert IEEE double precision floating point number to integer
12 RESULT
13 absolute value of y
15 Flags:
16 zero : result is zero
17 negative : result is negative
18 overflow : ieeedp out of integer-range
20 NOTES
22 EXAMPLE
24 BUGS
26 SEE ALSO
28 INTERNALS
30 HISTORY
33 AROS_LHQUAD1(LONG, IEEEDPFix,
34 AROS_LHAQUAD(double, y, D0, D1),
35 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 5, MathIeeeDoubBas
38 AROS_LIBFUNC_INIT
40 LONG Res, Shift, tmp;
41 QUAD y2;
42 QUAD * Qy = (QUAD *)&y;
44 tmp = Get_High32of64(*Qy) & IEEEDPExponent_Mask_Hi;
46 if ( tmp > 0x41d00000 )
48 if( is_lessSC(*Qy, 0x0, 0x0))
50 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
51 return 0x80000000;
53 else
55 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
56 return 0x7fffffff;
61 if(
62 is_eqC(*Qy, 0x0, 0x0)
63 || is_eqC(*Qy,IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo)
64 ) /* y=+-0; */
66 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
67 return 0;
70 Shift = (Get_High32of64(*Qy) & IEEEDPExponent_Mask_Hi) >> 20;
71 Shift = 0x433 - Shift;
72 tmp = Get_High32of64(*Qy);
73 AND64QC(*Qy, IEEEDPMantisse_Mask_Hi, IEEEDPMantisse_Mask_Lo);
74 OR64QC(*Qy, 0x00100000, 0x00000000);
75 SHRU64(y2, *Qy , Shift);
76 Res = Get_Low32of64(y2);
78 /* Test for a negative sign */
79 if (tmp < 0) /* y < 0 */
81 Res = -Res;
82 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
85 return Res;
87 AROS_LIBFUNC_EXIT