Author: greatlrd
Date: Fri May 26 23:23:34 2006
New Revision: 22062
URL:
http://svn.reactos.ru/svn/reactos?rev=22062&view=rev
Log:
replace djgpp hell bugs fcvtbuf with project
http://www.jbox.dk/sanos/source/lib/fcvt.c.html with small modification's to match
ReactOS arch. Floating point to string conversion routines Copyright (C) 2002 Michael
Ringgaard. All rights reserved.
Make wine test for fcvt shut up we are failing 64 of wine test in msvrt printf, but we
pass all fcvt test. before we did fail 75 test in wine test of msvrt printf test. Before
we did fail almost all test case for fcvt in wine test
Modified:
trunk/reactos/lib/crt/stdlib/fcvtbuf.c
Modified: trunk/reactos/lib/crt/stdlib/fcvtbuf.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/crt/stdlib/fcvtbuf.c?re…
==============================================================================
--- trunk/reactos/lib/crt/stdlib/fcvtbuf.c (original)
+++ trunk/reactos/lib/crt/stdlib/fcvtbuf.c Fri May 26 23:23:34 2006
@@ -1,61 +1,127 @@
-/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <float.h>
+#include <math.h>
#include <malloc.h>
// #include <msvcrt/locale.h>
-void __ecvround (char *, char *, const char *, int *);
-char *ecvtbuf (double, int, int *, int *, char *);
+// replace fjgpp fcvtbuf from project
http://www.jbox.dk/sanos/source/lib/fcvt.c.html
+// with small modification's to match ReactOS arch
-char *
-fcvtbuf (double value, int ndigits, int *decpt, int *sign, char *buf)
+// Floating point to string conversion routines
+//
+// Copyright (C) 2002 Michael Ringgaard. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// 3. Neither the name of the project nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE.
+//
+
+
+//#include <math.h>
+#define CVTBUFSIZE 2 * DBL_MAX_10_EXP + 10
+static char *cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, int eflag)
{
- static char INFINITY[] = "Infinity";
- char decimal = '.' /* localeconv()->decimal_point[0] */;
- int digits = ndigits >= 0 ? ndigits : 0;
- char *cvtbuf = (char *)_alloca (2*DBL_MAX_10_EXP + 16);
- char *s = cvtbuf;
- char *dot;
+ int r2;
+ double fi, fj;
+ char *p, *p1;
- sprintf (cvtbuf, "%-+#.*f", DBL_MAX_10_EXP + digits + 1, value);
+ if (ndigits < 0) ndigits = 0;
+ if (ndigits >= CVTBUFSIZE - 1) ndigits = CVTBUFSIZE - 2;
+ r2 = 0;
+ *sign = 0;
+ p = &buf[0];
+ if (arg < 0)
+ {
+ *sign = 1;
+ arg = -arg;
+ }
+ arg = modf(arg, &fi);
+ p1 = &buf[CVTBUFSIZE];
- /* The sign. */
- if (*s++ == '-')
- *sign = 1;
- else
- *sign = 0;
+ if (fi != 0)
+ {
+ p1 = &buf[CVTBUFSIZE];
+ while (fi != 0)
+ {
+ fj = modf(fi / 10, &fi);
+ *--p1 = (int)((fj + .03) * 10) + '0';
+ r2++;
+ }
+ while (p1 < &buf[CVTBUFSIZE]) *p++ = *p1++;
+ }
+ else if (arg > 0)
+ {
+ while ((fj = arg * 10) < 1)
+ {
+ arg = fj;
+ r2--;
+ }
+ }
+ p1 = &buf[ndigits];
+ if (eflag == 0) p1 += r2;
+ *decpt = r2;
+ if (p1 < &buf[0])
+ {
+ buf[0] = '\0';
+ return buf;
+ }
+ while (p <= p1 && p < &buf[CVTBUFSIZE])
+ {
+ arg *= 10;
+ arg = modf(arg, &fj);
+ *p++ = (int) fj + '0';
+ }
+ if (p1 >= &buf[CVTBUFSIZE])
+ {
+ buf[CVTBUFSIZE - 1] = '\0';
+ return buf;
+ }
+ p = p1;
+ *p1 += 5;
+ while (*p1 > '9')
+ {
+ *p1 = '0';
+ if (p1 > buf)
+ ++*--p1;
+ else
+ {
+ *p1 = '1';
+ (*decpt)++;
+ if (eflag == 0)
+ {
+ if (p > buf) *p = '0';
+ p++;
+ }
+ }
+ }
+ *p = '\0';
+ return buf;
+}
- /* Where's the decimal point? */
- dot = strchr (s, decimal);
- *decpt = dot ? dot - s : (int)strlen (s);
-
- /* SunOS docs says if NDIGITS is 8 or more, produce "Infinity"
- instead of "Inf". */
- if (strncmp (s, "Inf", 3) == 0)
- {
- memcpy (buf, INFINITY, ndigits >= 8 ? 9 : 3);
- if (ndigits < 8)
- buf[3] = '\0';
- return buf;
- }
- else if (ndigits < 0)
- return ecvtbuf (value, *decpt + ndigits, decpt, sign, buf);
- else if (*s == '0' && value != 0.0)
- return ecvtbuf (value, ndigits, decpt, sign, buf);
- else
- {
- memcpy (buf, s, *decpt);
- if (s[*decpt] == decimal)
- {
- memcpy (buf + *decpt, s + *decpt + 1, ndigits);
- buf[*decpt + ndigits] = '\0';
- }
- else
- buf[*decpt] = '\0';
- __ecvround (buf, buf + *decpt + ndigits - 1,
- s + *decpt + ndigits + 1, decpt);
- return buf;
- }
+char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf)
+{
+ return cvt(arg, ndigits, decpt, sign, buf, 0);
}