revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / mathffp / spflt.c
blobf136b1a8100b7dc37cc2b590ef6acfa74b944f09
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathffp_intern.h"
8 /*****************************************************************************
10 NAME */
12 AROS_LH1(float, SPFlt,
14 /* SYNOPSIS */
15 AROS_LHA(LONG, inum, D0),
17 /* LOCATION */
18 struct LibHeader *, MathBase, 6, Mathffp)
20 /* FUNCTION
22 INPUTS
24 RESULT
25 FFP number
27 Flags:
28 zero : result is zero
29 negative : result is negative
30 overflow : ffp is not exactly the integer
32 BUGS
34 INTERNALS
35 Return zero for x == 0.
36 If x < 0 set the sign-bit and calculate the absolute value
37 of x.
38 Find out which bit is the highest-set bit. If the number
39 of that bit <code>> 24</code> then the result has the highest bit
40 of the mantisse set to one and the exponent equals the
41 number of the bit + 2. This is due to the fact that we only
42 have 24 bits for the mantisse.
43 Otherwise rotate the given integer by
44 (32 - (number of highes set bit + 1)) bits to the left and
45 calculate the result from that.
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 BYTE Exponent = 0;
52 LONG TestMask = 0xFFFFFFFF;
53 LONG Res = 0;
55 D(kprintf("SPFlt(%d) = ",inum));
57 if (inum == 0)
59 SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
60 D(kprintf("0\n"));
61 return 0;
64 if (inum < 0)
66 Res = FFPSign_Mask;
67 inum = -inum;
69 /* find out which is the number of the highes set bit */
70 while (TestMask & inum)
72 Exponent ++;
73 TestMask <<= 1;
76 /* Exponent = number of highest set bit + 1 */
78 if (Exponent > 0) /* > 32 bit LONG shift = undefined */
79 inum <<= (32 - Exponent);
80 else
81 inum = 0;
82 if ((char) inum < 0) inum +=0x100;
83 inum &= FFPMantisse_Mask;
85 /* adapt the exponent to the ffp format */
86 Exponent += 0x40;
87 Res |= inum | Exponent;
88 if ((char) Res < 0)
90 SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
93 if (Exponent > (25 + 0x40))
95 Res |= 0x80000000;
96 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
99 D(kprintf("%x\n",Res));
101 return Res;
103 AROS_LIBFUNC_EXIT