Removed _float.h and all references to it
[fw/sdcc] / device / lib / _fs2ulong.c
1 /*
2 ** libgcc support for software floating point.
3 ** Copyright (C) 1991 by Pipeline Associates, Inc.  All rights reserved.
4 ** Permission is granted to do *anything* you want with this file,
5 ** commercial or otherwise, provided this message remains intact.  So there!
6 ** I would appreciate receiving any updates/patches/changes that anyone
7 ** makes, and am willing to be the repository for said changes (am I
8 ** making a big mistake?).
9 **
10 ** Pat Wood
11 ** Pipeline Associates, Inc.
12 ** pipeline!phw@motown.com or
13 ** sun!pipeline!phw or
14 ** uunet!motown!pipeline!phw
15 */
16
17 /* (c)2000: hacked a little by johan.knol@iduna.nl for sdcc */
18
19 #include <limits.h>
20
21 /* the following deal with IEEE single-precision numbers */
22 #define EXCESS          126
23 #define SIGNBIT         ((unsigned long)0x80000000)
24 #define HIDDEN          (unsigned long)(1 << 23)
25 #define SIGN(fp)        ((fp >> (8*sizeof(fp)-1)) & 1)
26 #define EXP(fp)         (((fp) >> 23) & (unsigned int) 0x00FF)
27 #define MANT(fp)        (((fp) & (unsigned long) 0x007FFFFF) | HIDDEN)
28 #define PACK(s,e,m)     ((s) | ((e) << 23) | (m))
29
30 union float_long
31 {
32   float f;
33   long l;
34 };
35
36 /* convert float to unsigned long */
37 unsigned long 
38 __fs2ulong (float a1)
39 {
40   volatile union float_long fl1;
41   volatile int exp;
42   volatile long l;
43   
44   fl1.f = a1;
45   
46   if (!fl1.l || SIGN(fl1.l))
47     return (0);
48
49   if (a1>=ULONG_MAX)
50     return ULONG_MAX;
51
52   exp = EXP (fl1.l) - EXCESS - 24;
53   l = MANT (fl1.l);
54   
55   l >>= -exp;
56
57   return l;
58 }
59
60
61
62