[#20392] [BigDecimal] proposal to change specification — "Tadashi Saito" <shiba@...2.accsnet.ne.jp>

斎藤と申します。

25 messages 2003/06/20
[#20407] Re: [BigDecimal] proposal to change specification — "Shigeo Kobayashi" <shigeo@...> 2003/06/22

小林です。

[#20447] [BigDecimal] renaming proposal — "Tadashi Saito" <shiba@...2.accsnet.ne.jp>

斎藤です。

47 messages 2003/06/24
[#20621] Re: [BigDecimal] renaming proposal — "Shigeo Kobayashi" <shigeo@...> 2003/07/11

小林@MAILチェック中です。

[#20628] Re: [BigDecimal] renaming proposal — "Shigeo Kobayashi" <shigeo@...> 2003/07/11

小林です。

[ruby-dev:20399] Re: locale and Marshal

From: Masao Mutoh <mutoh@...>
Date: 2003-06-21 01:11:03 UTC
List: ruby-dev #20399
むとうです。

On Sat, 21 Jun 2003 09:45:49 +0900
Masao Mutoh <mutoh@highway.ne.jp> wrote:

> むとうです。
> 
> On Fri, 20 Jun 2003 12:34:53 +0900
> Tanaka Akira <akr@m17n.org> wrote:
> 
> > In article <1056041498.240245.12121.nullmailer@picachu.netlab.jp>,
> >   matz@ruby-lang.org (Yukihiro Matsumoto) writes:
> > 
> > > known problemです。sprintf(3)を使わずに(localeに影響されずに)
> > > 浮動小数点数を文字列化する手段がなかなか手に入らないので。
> > > 逆は自前のstrtod(3)を用意することで対応したのですが。
> > 
> > ふと、思いついたのですが、(思いついただけですが)
> > localeconv(3) を使って decimal_point を得て、sprintf の結果を
> > decimal_point から "." に書き換えてしまうとか。
> 
> なるほど。せっかくですので上記を実装してみました。添付します。
> #2バイト以上のdecimal_pointには対応してませんが。

すみません。break入れた方が良いですね。

-- 
.:% Masao Mutoh<mutoh@highway.ne.jp>

Attachments (1)

marshal.patch (1.05 KB, text/x-diff)
Index: marshal.c
===================================================================
RCS file: /src/ruby/marshal.c,v
retrieving revision 1.91
diff -u -r1.91 marshal.c
--- marshal.c	6 Jun 2003 09:24:59 -0000	1.91
+++ marshal.c	21 Jun 2003 01:09:40 -0000
@@ -14,6 +14,7 @@
 #include "rubyio.h"
 #include "st.h"
 #include "util.h"
+#include <locale.h>
 
 #include <math.h>
 #ifdef HAVE_FLOAT_H
@@ -278,7 +279,7 @@
     struct dump_arg *arg;
 {
     char buf[100];
-
+    
     if (isinf(d)) {
 	if (d < 0) strcpy(buf, "-inf");
 	else       strcpy(buf, "inf");
@@ -292,10 +293,21 @@
     }
     else {
 	int len;
+        int i;
+        struct lconv *lc;
+        lc = localeconv();
 
 	/* xxx: should not use system's sprintf(3) */
 	sprintf(buf, "%.*g", FLOAT_DIG, d);
 	len = strlen(buf);
+        if (lc->decimal_point[0] != '.'){
+          for (i=0; i<len; i++) {
+            if (buf[i] == lc->decimal_point[0]){
+              buf[i] = '.';
+              break;
+            }
+          }
+        }
 	w_bytes(buf, len + save_mantissa(d, buf + len), arg);
 	return;
     }

In This Thread