* string.c (rb_str_each_line): return original string.
[ruby-svn.git] / x68 / fconvert.c
blob9a0bc0e0887fd4d01ece1cf286bad93a045eb2c7
1 /*
2 * PROJECT C Library, X68000 PROGRAMMING INTERFACE DEFINITION
3 * --------------------------------------------------------------------
4 * This file is written by the Project C Library Group, and completely
5 * in public domain. You can freely use, copy, modify, and redistribute
6 * the whole contents, without this notice.
7 * --------------------------------------------------------------------
8 * $Id$
9 */
10 /* changed 1997.2.3 by K.Okabe */
12 /* System headers */
13 #include <stdlib.h>
14 #include <sys/xstdlib.h>
16 /* Functions */
17 char *fconvert (double x, int ndigit, int *decpt, int *sign, char *buffer)
19 int pos, n;
20 char *src, *dst;
21 char string[24];
22 int figup;
24 /* 18·å¤Îʸ»úÎó¤ËÊÑ´¹ */
25 _dtos18 (x, decpt, sign, string);
27 /* ¥³¥Ô¡¼¸µ¥¢¥É¥ì¥¹¤òÀßÄê */
28 src = string;
30 /* ¥³¥Ô¡¼À襢¥É¥ì¥¹¤òÀßÄê */
31 dst = buffer;
33 /* ¾®¿ôÅÀ°ÌÃÖ¤òÆÀ¤ë */
34 pos = *decpt;
36 /* ¾®¿ôÅÀ°ÌÃÖ¤¬Éé¤Ê¤é */
37 if (pos < 0) {
39 /* Ëä¤á¤ë·å¿ô¤ò·×»» */
40 n = min (-pos, ndigit);
42 /* ÀèƬ¤ò0¤ÇËä¤á¤ë */
43 while (n-- > 0)
44 *dst++ = '0';
46 /* ¾®¿ôÅÀ°ÌÃÖ¤Ï0¤Ë¤Ê¤ë */
47 *decpt = 0;
51 /* »Ä¤ê¤Î¥³¥Ô¡¼·å¿ô */
52 n = ndigit + pos;
54 /* ³ÊǼÀè¤Ë¥³¥Ô¡¼ */
55 while (n-- > 0) {
57 /* ­¤ê¤Ê¤¤Éôʬ¤Ï0¤ÇËä¤á¤ë */
58 if (*src == '\0') {
59 while (n-- >= 0)
60 *dst++ = '0';
61 break;
64 /* ÊÑ´¹Ê¸»úÎ󤫤饳¥Ô¡¼ */
65 *dst++ = *src++;
69 /* ´Ý¤á¤ë */
70 *decpt += (figup = _round (buffer, dst, *src));
72 /* ·«¤ê¾å¤¬¤ê¤¬¤¢¤ì¤ÐËöÈø¤Ë0¤òÄɲ乤ë */
73 if (figup)
74 *dst++ = '0';
76 /* ½ªÃ¼¤Ë NUL ¤òÂÇ¤Ä */
77 *dst = '\0';
79 /* ¥¢¥É¥ì¥¹¤òÊÖ¤¹ */
80 return buffer;