Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / device / lib / _ulonglong2fs.c
blob4753b10cfb6343111fe06a60963e3f66885c64d1
1 /*-------------------------------------------------------------------------
2 _ulonglong2fs.c - Floating point library in optimized assembly for 8051
4 Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com
5 2022, Benedikt Freisen
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20 MA 02110-1301, USA.
22 As a special exception, if you link this library with other files,
23 some of which are compiled with SDCC, to produce an executable,
24 this library does not by itself cause the resulting executable to
25 be covered by the GNU General Public License. This exception does
26 not however invalidate any other reasons why the executable file
27 might be covered by the GNU General Public License.
28 -------------------------------------------------------------------------*/
31 #define __SDCC_FLOAT_LIB
32 #include <float.h>
36 ** libgcc support for software floating point.
37 ** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved.
38 ** Permission is granted to do *anything* you want with this file,
39 ** commercial or otherwise, provided this message remains intact. So there!
40 ** I would appreciate receiving any updates/patches/changes that anyone
41 ** makes, and am willing to be the repository for said changes (am I
42 ** making a big mistake?).
44 ** Pat Wood
45 ** Pipeline Associates, Inc.
46 ** pipeline!phw@motown.com or
47 ** sun!pipeline!phw or
48 ** uunet!motown!pipeline!phw
51 /* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */
52 /* (c)2022: fix sdcc bug #3276 -- Benedikt Freisen */
53 /* ported from ulong to ulonglong -- Benedikt Freisen */
55 union float_long
57 float f;
58 long l;
61 float __ulonglong2fs (unsigned long long a ) __SDCC_FLOAT_NONBANKED
63 unsigned char exp = (unsigned char)24 + (unsigned char)EXCESS;
64 volatile union float_long fl;
66 if (!a)
68 return 0.0;
71 if (a == 0xffffffffffffffffull)
73 return 18446744073709551616.0f;
76 while (a < HIDDEN)
78 a <<= 1;
79 exp--;
82 while (a & NORM)
84 // we lose accuracy here
85 if (a & 1)
86 a += 2;
87 a >>= 1;
88 exp++;
91 a &= ~HIDDEN ;
92 /* pack up and go home */
93 fl.l = PACK(0,(unsigned long)exp, a);
95 return (fl.f);