b9f453fb3a1d38ea7b8277929965ff232fa44201
[fw/sdcc] / device / lib / _fssub.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/2001: hacked a little by johan.knol@iduna.nl for sdcc */
18
19 #include <float.h>
20
21 union float_long
22   {
23     float f;
24     long l;
25   };
26
27 /* subtract two floats */
28 float __fssub (float a1, float a2)
29 {
30   volatile union float_long fl1, fl2;
31
32   fl1.f = a1;
33   fl2.f = a2;
34
35   /* check for zero args */
36   if (!fl2.l)
37     return (fl1.f);
38   if (!fl1.l)
39     return (-fl2.f);
40
41   /* twiddle sign bit and add */
42   fl2.l ^= SIGNBIT;
43   return fl1.f + fl2.f; 
44 }