change printf_fast to LGPL
[fw/sdcc] / device / lib / _ulong2fs.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 /* the following deal with IEEE single-precision numbers */
20 #define EXCESS          126
21 #define SIGNBIT         ((unsigned long)0x80000000)
22 #define HIDDEN          (unsigned long)(1 << 23)
23 #define SIGN(fp)        ((fp) & SIGNBIT)
24 #define EXP(fp)         (((fp) >> 23) & (unsigned int) 0x00FF)
25 #define MANT(fp)        (((fp) & (unsigned long)0x007FFFFF) | HIDDEN)
26 #define PACK(s,e,m)     ((s) | ((e) << 23) | (m))
27
28 union float_long
29   {
30     float f;
31     long l;
32   };
33
34 float 
35 __ulong2fs (unsigned long a )
36 {
37   int exp = 24 + EXCESS;
38   volatile union float_long fl;
39
40   if (!a)
41     {
42       return 0.0;
43     }
44
45   while (a < HIDDEN)
46     {
47       a <<= 1;
48       exp--;
49     }
50
51    a &= ~HIDDEN ;
52   /* pack up and go home */
53   fl.l = PACK(0,(unsigned long)exp, a);
54
55   return (fl.f);
56 }