grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / mathieeedoubbas / ieeedpflt.c
blob644ed6b99f32746d4fe2dece0bfd9eb6770e3a91
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_LH1(double, IEEEDPFlt,
14 /* SYNOPSIS */
15 AROS_LHA(LONG, y, D0),
17 /* LOCATION */
18 struct MathIeeeDoubBasBase *, MathIeeeDoubBasBase, 6, MathIeeeDoubBas)
20 /* FUNCTION
22 INPUTS
24 RESULT
25 IEEE double precision number
27 Flags:
28 zero : result is zero
29 negative : result is negative
30 overflow : 0
32 BUGS
34 INTERNALS
36 *****************************************************************************/
38 AROS_LIBFUNC_INIT
40 LONG Exponent = 0;
41 LONG TestMask = 0xFFFFFFFF;
42 QUAD Res, yQuad, ExponentQuad;
43 double * DRes = (double *)&Res;
45 Set_Value64C(Res,0,0);
47 if (0 == y)
49 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
50 return *DRes; /* return 0 */
53 if (y < 0 )
55 Set_Value64C(Res, IEEEDPSign_Mask_Hi, IEEEDPSign_Mask_Lo);
56 y = -y;
58 /* find out which is the number of the highest set bit */
59 while (TestMask & y)
61 Exponent ++;
62 TestMask <<= 1;
65 SHL32(yQuad , y , (53 - Exponent) );
67 AND64QC(yQuad, IEEEDPMantisse_Mask_Hi, IEEEDPMantisse_Mask_Lo);
69 Exponent += 0x3fe;
71 /* adapt Exponent to IEEEDP-Format */
72 SHL32(ExponentQuad, Exponent, 52);
73 OR64Q(Res, yQuad);
74 OR64Q(Res, ExponentQuad);
75 if ( is_lessSC(Res,0,0) ) /* Res < 0 */
77 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
80 return *DRes;
82 AROS_LIBFUNC_EXIT