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

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

On Sat, 21 Jun 2003 10:07:48 +0900
nobu.nakada@nifty.ne.jp wrote:

> なかだです。
> 
> At Sat, 21 Jun 2003 09:45:49 +0900,
> Masao Mutoh wrote:
> > > > known problemです。sprintf(3)を使わずに(localeに影響されずに)
> > > > 浮動小数点数を文字列化する手段がなかなか手に入らないので。
> > > > 逆は自前のstrtod(3)を用意することで対応したのですが。
> > > 
> > > ふと、思いついたのですが、(思いついただけですが)
> > > localeconv(3) を使って decimal_point を得て、sprintf の結果を
> > > decimal_point から "." に書き換えてしまうとか。
> > 
> > なるほど。せっかくですので上記を実装してみました。添付します。
> 
> locale.hとlocaleconv()はconfigureでチェックすべきでしょうね。

すみません...。改めまして。

でも、私、configure.inの書き方がよくわかっていないので
これで良いのかはちょっと自信ないです。

それでは。
-- 
.:% Masao Mutoh<mutoh@highway.ne.jp>



Attachments (1)

marshal.patch2 (2.11 KB, text/x-diff)
Index: configure.in
===================================================================
RCS file: /src/ruby/configure.in,v
retrieving revision 1.175
diff -u -r1.175 configure.in
--- configure.in	9 Jun 2003 10:02:36 -0000	1.175
+++ configure.in	21 Jun 2003 01:42:57 -0000
@@ -353,7 +353,7 @@
 AC_CHECK_HEADERS(stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h\
 		 fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h\
 		 syscall.h pwd.h grp.h a.out.h utime.h memory.h direct.h sys/resource.h \
-		 sys/mkdev.h sys/utime.h float.h)
+		 sys/mkdev.h sys/utime.h float.h locale.h)
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_TYPE_UID_T
@@ -378,7 +378,7 @@
 	      setrgid setegid setregid setresgid pause lchown lchmod\
 	      getpgrp setpgrp getpgid setpgid getgroups setgroups getpriority getrlimit\
 	      dlopen sigprocmask sigaction _setjmp setsid telldir seekdir fchmod\
-	      mktime timegm cosh sinh tanh)
+	      mktime timegm cosh sinh tanh localeconv)
 AC_STRUCT_TIMEZONE
 AC_CACHE_CHECK(for struct tm.tm_gmtoff, rb_cv_member_struct_tm_tm_gmtoff,
   [AC_TRY_COMPILE([#include <time.h>],
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:42:57 -0000
@@ -15,6 +15,10 @@
 #include "st.h"
 #include "util.h"
 
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
 #include <math.h>
 #ifdef HAVE_FLOAT_H
 #include <float.h>
@@ -292,10 +296,24 @@
     }
     else {
 	int len;
-
+#ifdef HAVE_LOCALECONV 
+        int i;
+        struct lconv *lc;
+#endif
 	/* xxx: should not use system's sprintf(3) */
 	sprintf(buf, "%.*g", FLOAT_DIG, d);
 	len = strlen(buf);
+#ifdef HAVE_LOCALECONV 
+        lc = localeconv();
+        if (lc->decimal_point[0] != '.'){
+          for (i=0; i<len; i++) {
+            if (buf[i] == lc->decimal_point[0]){
+              buf[i] = '.';
+              break;
+            }
+          }
+        }
+#endif
 	w_bytes(buf, len + save_mantissa(d, buf + len), arg);
 	return;
     }

In This Thread