[前][次][番号順一覧][スレッド一覧]

ruby-changes:23037

From: nobu <ko1@a...>
Date: Mon, 19 Mar 2012 00:21:17 +0900 (JST)
Subject: [ruby-changes:23037] nobu:r35086 (trunk): num2ll and num2ull

nobu	2012-03-19 00:21:04 +0900 (Mon, 19 Mar 2012)

  New Revision: 35086

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35086

  Log:
    num2ll and num2ull
    
    * ext/-test-/num2int/num2int.c (print_num2ll, print_num2ull): define
      only if long long is available, and use long long printf modifier
      checked by configure.

  Modified files:
    trunk/ext/-test-/num2int/num2int.c
    trunk/test/-ext-/num2int/test_num2int.rb

Index: ext/-test-/num2int/num2int.c
===================================================================
--- ext/-test-/num2int/num2int.c	(revision 35085)
+++ ext/-test-/num2int/num2int.c	(revision 35086)
@@ -72,13 +72,14 @@
     return Qnil;
 }
 
+#ifdef HAVE_LONG_LONG
 static VALUE
 print_num2ll(VALUE obj, VALUE num)
 {
     char buf[128];
     VALUE str;
 
-    sprintf(buf, "%lld", NUM2LL(num));
+    sprintf(buf, "%"PRI_LL_PREFIX"d", NUM2LL(num));
     str = rb_str_new_cstr(buf);
     rb_io_write(rb_stdout, str);
     return Qnil;
@@ -90,13 +91,13 @@
     char buf[128];
     VALUE str;
 
-    sprintf(buf, "%llu", NUM2ULL(num));
+    sprintf(buf, "%"PRI_LL_PREFIX"u", NUM2ULL(num));
     str = rb_str_new_cstr(buf);
     rb_io_write(rb_stdout, str);
     return Qnil;
 }
+#endif
 
-
 void
 Init_num2int(void)
 {
@@ -111,7 +112,9 @@
     rb_define_singleton_method(cNum2int, "print_num2long", print_num2long, 1);
     rb_define_singleton_method(cNum2int, "print_num2ulong", print_num2ulong, 1);
 
+#ifdef HAVE_LONG_LONG
     rb_define_singleton_method(cNum2int, "print_num2ll", print_num2ll, 1);
     rb_define_singleton_method(cNum2int, "print_num2ull", print_num2ull, 1);
+#endif
 }
 
Index: test/-ext-/num2int/test_num2int.rb
===================================================================
--- test/-ext-/num2int/test_num2int.rb	(revision 35085)
+++ test/-ext-/num2int/test_num2int.rb	(revision 35086)
@@ -188,7 +188,7 @@
     assert_output((FIXNUM_MAX+1).to_s) do
       Num2int.print_num2ll(FIXNUM_MAX+1)
     end
-  end
+  end if defined?(Num2int.print_num2ll)
 
   def test_num2ull
     assert_output("0") do
@@ -221,7 +221,7 @@
     assert_output((FIXNUM_MAX+1).to_s) do
       Num2int.print_num2ull(FIXNUM_MAX+1)
     end
-  end
+  end if defined?(Num2int.print_num2ull)
 end
 
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]