зеркало из https://github.com/github/ruby.git
82 строки
1.6 KiB
C
82 строки
1.6 KiB
C
|
/*
|
|||
|
* PROJECT C Library, X68000 PROGRAMMING INTERFACE DEFINITION
|
|||
|
* --------------------------------------------------------------------
|
|||
|
* This file is written by the Project C Library Group, and completely
|
|||
|
* in public domain. You can freely use, copy, modify, and redistribute
|
|||
|
* the whole contents, without this notice.
|
|||
|
* --------------------------------------------------------------------
|
|||
|
* $Id$
|
|||
|
*/
|
|||
|
/* changed 1997.2.3 by K.Okabe */
|
|||
|
|
|||
|
/* System headers */
|
|||
|
#include <stdlib.h>
|
|||
|
#include <sys/xstdlib.h>
|
|||
|
|
|||
|
/* Functions */
|
|||
|
char *fconvert (double x, int ndigit, int *decpt, int *sign, char *buffer)
|
|||
|
{
|
|||
|
int pos, n;
|
|||
|
char *src, *dst;
|
|||
|
char string[24];
|
|||
|
int figup;
|
|||
|
|
|||
|
/* 18<31><38><EFBFBD><EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD> */
|
|||
|
_dtos18 (x, decpt, sign, string);
|
|||
|
|
|||
|
/* <20><><EFBFBD>ԡ<EFBFBD><D4A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɥ쥹<C9A5><ECA5B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
src = string;
|
|||
|
|
|||
|
/* <20><><EFBFBD>ԡ<EFBFBD><D4A1>襢<EFBFBD>ɥ쥹<C9A5><ECA5B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
dst = buffer;
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
pos = *decpt;
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>ʤ<EFBFBD> */
|
|||
|
if (pos < 0) {
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
n = min (-pos, ndigit);
|
|||
|
|
|||
|
/* <20><>Ƭ<EFBFBD><C6AC>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
while (n-- > 0)
|
|||
|
*dst++ = '0';
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD>0<EFBFBD>ˤʤ<CBA4> */
|
|||
|
*decpt = 0;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/* <20>Ĥ<EFBFBD><C4A4>Υ<EFBFBD><CEA5>ԡ<EFBFBD><D4A1><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
n = ndigit + pos;
|
|||
|
|
|||
|
/* <20><>Ǽ<EFBFBD><C7BC><EFBFBD>˥<EFBFBD><CBA5>ԡ<EFBFBD> */
|
|||
|
while (n-- > 0) {
|
|||
|
|
|||
|
/* <><C2AD><EFBFBD>ʤ<EFBFBD><CAA4><EFBFBD>ʬ<EFBFBD><CAAC>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
if (*src == '\0') {
|
|||
|
while (n-- >= 0)
|
|||
|
*dst++ = '0';
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
/* <20>Ѵ<EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD>饳<F3A4ABA4>ԡ<EFBFBD> */
|
|||
|
*dst++ = *src++;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/* <20>ݤ<EFBFBD><DDA4><EFBFBD> */
|
|||
|
*decpt += (figup = _round (buffer, dst, *src));
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>夬<EFBFBD>꤬<EFBFBD><EAA4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD>ɲä<C9B2><C3A4><EFBFBD> */
|
|||
|
if (figup)
|
|||
|
*dst++ = '0';
|
|||
|
|
|||
|
/* <20><>ü<EFBFBD><C3BC> NUL <20><><EFBFBD>Ǥ<EFBFBD> */
|
|||
|
*dst = '\0';
|
|||
|
|
|||
|
/* <20><><EFBFBD>ɥ쥹<C9A5><ECA5B9><EFBFBD>֤<EFBFBD> */
|
|||
|
return buffer;
|
|||
|
}
|