add place-holder directory for the a3000 wd533c93 scsi controller implementation.
[AROS.git] / workbench / libs / mathieeedoubbas / ieeedpfix.c
blob8814047f633f9129a4afa9f9f3f9459fd77d8a7a
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(LONG, IEEEDPFix,
14 /* SYNOPSIS */
15 AROS_LHAQUAD(double, y, D0, D1),
17 /* LOCATION */
18 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 5, MathIeeeDoubBas)
20 /* FUNCTION
21 Converts an IEEE double precision floating point number to an integer.
23 INPUTS
24 y - IEEE double precision floating point number.
26 RESULT
27 x - the closest signed 32-bit integer to y.
29 Flags:
30 zero : result is zero
31 negative : result is negative
32 overflow : ieeedp out of integer-range
34 NOTES
36 EXAMPLE
38 BUGS
40 SEE ALSO
41 IEEEDPFlt(), IEEEDPFloor(), IEEEDPCeil()
43 INTERNALS
45 *****************************************************************************/
47 AROS_LIBFUNC_INIT
49 LONG Res, Shift, tmp;
50 QUAD y2;
51 QUAD * Qy = (QUAD *)&y;
53 tmp = Get_High32of64(*Qy) & IEEEDPExponent_Mask_Hi;
55 if ( tmp > 0x41d00000 )
57 if( is_lessSC(*Qy, 0x0, 0x0))
59 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
60 return 0x80000000;
62 else
64 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
65 return 0x7fffffff;
70 if(
71 is_eqC(*Qy, 0x0, 0x0)
72 || is_eqC(*Qy,IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo)
73 ) /* y=+-0; */
75 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
76 return 0;
79 Shift = (Get_High32of64(*Qy) & IEEEDPExponent_Mask_Hi) >> 20;
80 Shift = 0x433 - Shift;
81 tmp = Get_High32of64(*Qy);
82 AND64QC(*Qy, IEEEDPMantisse_Mask_Hi, IEEEDPMantisse_Mask_Lo);
83 OR64QC(*Qy, 0x00100000, 0x00000000);
84 SHRU64(y2, *Qy , Shift);
85 Res = Get_Low32of64(y2);
87 /* Test for a negative sign */
88 if (tmp < 0) /* y < 0 */
90 Res = -Res;
91 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
94 return Res;
96 AROS_LIBFUNC_EXIT