ReactOS 0.4.15-dev-7788-g1ad9096
fconv.c File Reference
#include <schily/mconfig.h>
#include <schily/stdlib.h>
#include <schily/standard.h>
#include <schily/string.h>
#include <schily/schily.h>
#include <schily/math.h>
#include <schily/nlsdefs.h>
#include <schily/float.h>
#include "cvt.c"
Include dependency graph for fconv.c:

Go to the source code of this file.

Macros

#define isnan(val)   (0)
 
#define NO_ISNAN
 
#define isinf(val)   (0)
 
#define NO_ISINF
 
#define MDOUBLE   double
 
#define abs(i)   ((i) < 0 ? -(i) : (i))
 

Functions

char *ecvt __PR ((double, int, int *, int *))
 
static int _ferr __PR ((char *, double))
 
EXPORT int ftoes (register char *s, MDOUBLE val, register int fieldwidth, register int ndigits)
 
EXPORT int ftofs (register char *s, MDOUBLE val, register int fieldwidth, register int ndigits)
 
LOCAL int _ferr (char *s, double val)
 

Variables

static char _js_nan [] = "(NaN)"
 
static char _js_inf [] = "(Infinity)"
 

Macro Definition Documentation

◆ abs

#define abs (   i)    ((i) < 0 ? -(i) : (i))

Definition at line 206 of file fconv.c.

◆ isinf

#define isinf (   val)    (0)

Definition at line 129 of file fconv.c.

◆ isnan

#define isnan (   val)    (0)

Definition at line 124 of file fconv.c.

◆ MDOUBLE

#define MDOUBLE   double

Definition at line 200 of file fconv.c.

◆ NO_ISINF

#define NO_ISINF

Definition at line 130 of file fconv.c.

◆ NO_ISNAN

#define NO_ISNAN

Definition at line 125 of file fconv.c.

Function Documentation

◆ __PR() [1/2]

static int _ferr __PR ( (char *, double )
static

◆ __PR() [2/2]

char *ecvt __PR ( (double, int, int *, int *)  )

◆ _ferr()

LOCAL int _ferr ( char s,
double  val 
)

Definition at line 397 of file fconv.c.

400{
401 if (isnan(val)) {
402 strcpy(s, _js_nan);
403 return (sizeof (_js_nan) - 1);
404 }
405
406 /*
407 * Check first for NaN because finite() will return 1 on Nan too.
408 */
409 if (isinf(val)) {
410 strcpy(s, _js_inf);
411 return (sizeof (_js_inf) - 1);
412 }
413 return (0);
414}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
static char _js_inf[]
Definition: fconv.c:190
#define isnan(val)
Definition: fconv.c:124
#define isinf(val)
Definition: fconv.c:129
static char _js_nan[]
Definition: fconv.c:189
GLdouble s
Definition: gl.h:2039
GLuint GLfloat * val
Definition: glext.h:7180

Referenced by ftoes(), and ftofs().

◆ ftoes()

EXPORT int ftoes ( register char s,
MDOUBLE  val,
register int  fieldwidth,
register int  ndigits 
)

Definition at line 209 of file fconv.c.

214{
215 register char *b;
216 register char *rs;
217 register int len;
218 register int rdecpt;
219 int decpt;
220 int sign;
221
222#ifndef __DO_LONG_DOUBLE__
223 if ((len = _ferr(s, val)) > 0)
224 return (len);
225#endif
226 rs = s;
227#ifdef V7_FLOATSTYLE
228 b = ecvt(val, ndigits, &decpt, &sign);
229 rdecpt = decpt;
230#else
231 b = ecvt(val, ndigits+1, &decpt, &sign);
232 rdecpt = decpt-1;
233#endif
234#ifdef __DO_LONG_DOUBLE__
235 len = *b;
236 if (len < '0' || len > '9') { /* Inf/NaN */
237 strcpy(s, b);
238 return (strlen(b));
239 }
240#endif
241 len = ndigits + 6; /* Punkt e +/- nnn */
242 if (sign)
243 len++;
244 if (fieldwidth > len)
245 while (fieldwidth-- > len)
246 *rs++ = ' ';
247 if (sign)
248 *rs++ = '-';
249#ifndef V7_FLOATSTYLE
250 if (*b)
251 *rs++ = *b++;
252#endif
253#if defined(HAVE_LOCALECONV) && defined(USE_LOCALE)
254 *rs++ = *(localeconv()->decimal_point);
255#else
256 *rs++ = '.';
257#endif
258 while (*b && ndigits-- > 0)
259 *rs++ = *b++;
260 *rs++ = 'e';
261 *rs++ = rdecpt >= 0 ? '+' : '-';
262 rdecpt = abs(rdecpt);
263#ifdef __DO_LONG_DOUBLE__
264 if (rdecpt >= 1000) { /* Max-Exp is > 4000 */
265 *rs++ = rdecpt / 1000 + '0';
266 rdecpt %= 1000;
267 }
268#endif
269#ifndef V7_FLOATSTYLE
270 if (rdecpt >= 100)
271#endif
272 {
273 *rs++ = rdecpt / 100 + '0';
274 rdecpt %= 100;
275 }
276 *rs++ = rdecpt / 10 + '0';
277 *rs++ = rdecpt % 10 + '0';
278 *rs = '\0';
279 return (rs - s);
280}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
LOCAL int _ferr(char *s, double val)
Definition: fconv.c:397
#define abs(i)
Definition: fconv.c:206
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum GLsizei len
Definition: glext.h:6722
_Check_return_opt_ _CRTIMP struct lconv *__cdecl localeconv(void)
Definition: locale.c:601
_Check_return_ _CRTIMP char *__cdecl ecvt(_In_ double _Val, _In_ int _NumOfDigits, _Out_ int *_PtDec, _Out_ int *_PtSign)
#define b
Definition: ke_i.h:79
#define sign(x)
Definition: mapdesc.cc:613
static size_t double int ndigits
Definition: printf.c:72
static size_t double int int * decpt
Definition: printf.c:72

Referenced by for().

◆ ftofs()

EXPORT int ftofs ( register char s,
MDOUBLE  val,
register int  fieldwidth,
register int  ndigits 
)

Definition at line 290 of file fconv.c.

295{
296 register char *b;
297 register char *rs;
298 register int len;
299 register int rdecpt;
300 int decpt;
301 int sign;
302
303#ifndef __DO_LONG_DOUBLE__
304 if ((len = _ferr(s, val)) > 0)
305 return (len);
306#endif
307 rs = s;
308#ifdef USE_ECVT
309 /*
310 * Needed on systems with broken fcvt() implementation
311 * (e.g. Cygwin32)
312 */
313 b = ecvt(val, ndigits, &decpt, &sign);
314 /*
315 * The next call is needed to force higher precision.
316 */
317 if (decpt > 0)
318 b = ecvt(val, ndigits+decpt, &decpt, &sign);
319#else
320 b = fcvt(val, ndigits, &decpt, &sign);
321#endif
322#ifdef __DO_LONG_DOUBLE__
323 len = *b;
324 if (len < '0' || len > '9') { /* Inf/NaN */
325 strcpy(s, b);
326 return (strlen(b));
327 }
328#endif
329 rdecpt = decpt;
330 len = rdecpt + ndigits + 1;
331 if (rdecpt < 0)
332 len -= rdecpt;
333 if (sign)
334 len++;
335 if (fieldwidth > len)
336 while (fieldwidth-- > len)
337 *rs++ = ' ';
338 if (sign)
339 *rs++ = '-';
340 if (rdecpt > 0) {
341 len = rdecpt;
342 while (*b && len-- > 0)
343 *rs++ = *b++;
344#ifdef USE_ECVT
345 while (len-- > 0)
346 *rs++ = '0';
347#endif
348 }
349#ifndef V7_FLOATSTYLE
350 else {
351 *rs++ = '0';
352 }
353#endif
354#if defined(HAVE_LOCALECONV) && defined(USE_LOCALE)
355 *rs++ = *(localeconv()->decimal_point);
356#else
357 *rs++ = '.';
358#endif
359 if (rdecpt < 0) {
360 len = rdecpt;
361 while (len++ < 0 && ndigits-- > 0)
362 *rs++ = '0';
363 }
364 while (*b && ndigits-- > 0)
365 *rs++ = *b++;
366#ifdef USE_ECVT
367 while (ndigits-- > 0)
368 *rs++ = '0';
369#endif
370 *rs = '\0';
371 return (rs - s);
372}
_Check_return_ _CRTIMP char *__cdecl fcvt(_In_ double _Val, _In_ int _NumOfDec, _Out_ int *_PtDec, _Out_ int *_PtSign)

Referenced by for().

Variable Documentation

◆ _js_inf

char _js_inf[] = "(Infinity)"
static

Definition at line 190 of file fconv.c.

Referenced by _ferr().

◆ _js_nan

char _js_nan[] = "(NaN)"
static

Definition at line 189 of file fconv.c.

Referenced by _ferr().