summaryrefslogtreecommitdiff
path: root/ruby_1_8_5/x68/fconvert.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-15 19:08:43 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-15 19:08:43 +0000
commitd464704f111d211c1f1ff9ef23ef1d755054be00 (patch)
treeb58b17b645dc463322e5fca57fe282360db659c9 /ruby_1_8_5/x68/fconvert.c
parente4f06b3f2dec4b5d6334c5e9907e1cecbf649fc4 (diff)
add tag v1_8_5_54
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_5_54@12952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_1_8_5/x68/fconvert.c')
-rw-r--r--ruby_1_8_5/x68/fconvert.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/ruby_1_8_5/x68/fconvert.c b/ruby_1_8_5/x68/fconvert.c
new file mode 100644
index 0000000000..058876b564
--- /dev/null
+++ b/ruby_1_8_5/x68/fconvert.c
@@ -0,0 +1,81 @@
+/*
+ * 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: fconvert.c,v 1.1.1.2 1999/01/20 04:59:39 matz Exp $
+ */
+/* 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桁の文字列に変換 */
+ _dtos18 (x, decpt, sign, string);
+
+ /* コピー元アドレスを設定 */
+ src = string;
+
+ /* コピー先アドレスを設定 */
+ dst = buffer;
+
+ /* 小数点位置を得る */
+ pos = *decpt;
+
+ /* 小数点位置が負なら */
+ if (pos < 0) {
+
+ /* 埋める桁数を計算 */
+ n = min (-pos, ndigit);
+
+ /* 先頭を0で埋める */
+ while (n-- > 0)
+ *dst++ = '0';
+
+ /* 小数点位置は0になる */
+ *decpt = 0;
+
+ }
+
+ /* 残りのコピー桁数 */
+ n = ndigit + pos;
+
+ /* 格納先にコピー */
+ while (n-- > 0) {
+
+ /* 足りない部分は0で埋める */
+ if (*src == '\0') {
+ while (n-- >= 0)
+ *dst++ = '0';
+ break;
+ }
+
+ /* 変換文字列からコピー */
+ *dst++ = *src++;
+
+ }
+
+ /* 丸める */
+ *decpt += (figup = _round (buffer, dst, *src));
+
+ /* 繰り上がりがあれば末尾に0を追加する */
+ if (figup)
+ *dst++ = '0';
+
+ /* 終端に NUL を打つ */
+ *dst = '\0';
+
+ /* アドレスを返す */
+ return buffer;
+}