[#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:20397] Re: locale and Marshal

From: Masao Mutoh <mutoh@...>
Date: 2003-06-21 00:45:49 UTC
List: ruby-dev #20397
むとうです。

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には対応してませんが。

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

Attachments (1)

marshal.patch (909 Bytes, text/x-diff)
--- marshal.c	2003-06-06 18:24:59.000000000 +0900
+++ marshal.c.new	2003-06-21 09:36:52.000000000 +0900
@@ -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,20 @@
     }
     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] = '.';
+            }
+          }
+        }
 	w_bytes(buf, len + save_mantissa(d, buf + len), arg);
 	return;
     }

In This Thread