revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / mathieeedoubbas / ieeedpflt.c
blob81b95bd6b8ceee071e663bec119ba4c00b5e6551
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_LH1(double, IEEEDPFlt,
14 /* SYNOPSIS */
15 AROS_LHA(LONG, y, D0),
17 /* LOCATION */
18 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 6, MathIeeeDoubBas)
20 /* FUNCTION
21 Convert an integer into an IEEE double precision floating point
22 number.
24 INPUTS
25 y - a 32-bit integer.
27 RESULT
28 x - IEEE double precision floating point number.
30 Flags:
31 zero : result is zero
32 negative : result is negative
33 overflow : 0
35 NOTES
37 EXAMPLE
39 BUGS
41 SEE ALSO
42 IEEEDPFix()
44 INTERNALS
46 *****************************************************************************/
48 AROS_LIBFUNC_INIT
50 LONG Exponent = 0;
51 LONG TestMask = 0xFFFFFFFF;
52 QUAD Res, yQuad, ExponentQuad;
53 double * DRes = (double *)&Res;
55 Set_Value64C(Res,0,0);
57 if (0 == y)
59 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
60 return *DRes; /* return 0 */
63 if (y < 0 )
65 Set_Value64C(Res, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo);
66 y = -y;
68 /* find out which is the number of the highest set bit */
69 while (TestMask & y)
71 Exponent ++;
72 TestMask <<= 1;
75 SHL32(yQuad , y , (53 - Exponent) );
77 AND64QC(yQuad, IEEEDPMantisse_Mask_Hi, IEEEDPMantisse_Mask_Lo);
79 Exponent += 0x3fe;
81 /* adapt Exponent to IEEEDP-Format */
82 SHL32(ExponentQuad, Exponent, 52);
83 OR64Q(Res, yQuad);
84 OR64Q(Res, ExponentQuad);
85 if ( is_lessSC(Res,0,0) ) /* Res < 0 */
87 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
90 return *DRes;
92 AROS_LIBFUNC_EXIT