summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-06 06:11:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-06 06:11:43 +0000
commit591503c0ab7a4d6bf9f90b8bdf317ee5cfa13d03 (patch)
tree0fc9701b470d9c1a4d68f011fc6204b5f43035cc
parent6aac0579d1920fe3be0a12cd2a0775036d576220 (diff)
* sprintf.c (rb_str_format): ignore 0 flag for NaN and Inf.
[ruby-dev:33994] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15711 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--sprintf.c21
-rw-r--r--test/ruby/test_sprintf.rb24
3 files changed, 18 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index f88a4f3..f277ed0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Mar 6 15:11:40 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * sprintf.c (rb_str_format): ignore 0 flag for NaN and Inf.
+ [ruby-dev:33994]
+
Thu Mar 6 15:05:25 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* {bcc32,win32}/Makefile.sub (RUNRUBY): use $(PROGRAM) instead of
diff --git a/sprintf.c b/sprintf.c
index c54e8e8..f5b3e84 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -766,7 +766,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if (isnan(fval) || isinf(fval)) {
const char *expr;
- if (isnan(fval)) {
+ if (isnan(fval)) {
expr = "NaN";
}
else {
@@ -789,25 +789,6 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
blen++;
strncpy(&buf[blen], expr, strlen(expr));
}
- else if (flags & FZERO) {
- if (!isnan(fval) && fval < 0.0) {
- buf[blen++] = '-';
- need--;
- }
- else if (flags & FPLUS) {
- buf[blen++] = '+';
- need--;
- }
- else if (flags & FSPACE) {
- blen++;
- need--;
- }
- if ((need -= strlen(expr)) > 0) {
- memset(buf+blen, '0', need);
- blen += need;
- }
- strncpy(&buf[blen], expr, strlen(expr));
- }
else {
if (!isnan(fval) && fval < 0.0)
buf[blen + need - strlen(expr) - 1] = '-';
diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb
index 711a59d..1746ae0 100644
--- a/test/ruby/test_sprintf.rb
+++ b/test/ruby/test_sprintf.rb
@@ -87,17 +87,17 @@ class TestSprintf < Test::Unit::TestCase
assert_equal("NaN ", sprintf("%-8f", nan))
assert_equal(" +NaN", sprintf("%+8f", nan))
- assert_equal("00000NaN", sprintf("%08f", nan))
+ assert_equal(" NaN", sprintf("%08f", nan))
assert_equal("NaN ", sprintf("%-08f", nan))
- assert_equal("+0000NaN", sprintf("%+08f", nan))
+ assert_equal(" +NaN", sprintf("%+08f", nan))
assert_equal(" NaN", sprintf("% 8f", nan))
assert_equal(" NaN ", sprintf("%- 8f", nan))
assert_equal(" +NaN", sprintf("%+ 8f", nan))
- assert_equal(" 0000NaN", sprintf("% 08f", nan))
+ assert_equal(" NaN", sprintf("% 08f", nan))
assert_equal(" NaN ", sprintf("%- 08f", nan))
- assert_equal("+0000NaN", sprintf("%+ 08f", nan))
+ assert_equal(" +NaN", sprintf("%+ 08f", nan))
end
def test_inf
@@ -110,17 +110,17 @@ class TestSprintf < Test::Unit::TestCase
assert_equal("Inf ", sprintf("%-8f", inf))
assert_equal(" +Inf", sprintf("%+8f", inf))
- assert_equal("00000Inf", sprintf("%08f", inf))
+ assert_equal(" Inf", sprintf("%08f", inf))
assert_equal("Inf ", sprintf("%-08f", inf))
- assert_equal("+0000Inf", sprintf("%+08f", inf))
+ assert_equal(" +Inf", sprintf("%+08f", inf))
assert_equal(" Inf", sprintf("% 8f", inf))
assert_equal(" Inf ", sprintf("%- 8f", inf))
assert_equal(" +Inf", sprintf("%+ 8f", inf))
- assert_equal(" 0000Inf", sprintf("% 08f", inf))
+ assert_equal(" Inf", sprintf("% 08f", inf))
assert_equal(" Inf ", sprintf("%- 08f", inf))
- assert_equal("+0000Inf", sprintf("%+ 08f", inf))
+ assert_equal(" +Inf", sprintf("%+ 08f", inf))
assert_equal("-Inf", sprintf("%f", -inf))
assert_equal("-Inf", sprintf("%-f", -inf))
@@ -130,17 +130,17 @@ class TestSprintf < Test::Unit::TestCase
assert_equal("-Inf ", sprintf("%-8f", -inf))
assert_equal(" -Inf", sprintf("%+8f", -inf))
- assert_equal("-0000Inf", sprintf("%08f", -inf))
+ assert_equal(" -Inf", sprintf("%08f", -inf))
assert_equal("-Inf ", sprintf("%-08f", -inf))
- assert_equal("-0000Inf", sprintf("%+08f", -inf))
+ assert_equal(" -Inf", sprintf("%+08f", -inf))
assert_equal(" -Inf", sprintf("% 8f", -inf))
assert_equal("-Inf ", sprintf("%- 8f", -inf))
assert_equal(" -Inf", sprintf("%+ 8f", -inf))
- assert_equal("-0000Inf", sprintf("% 08f", -inf))
+ assert_equal(" -Inf", sprintf("% 08f", -inf))
assert_equal("-Inf ", sprintf("%- 08f", -inf))
- assert_equal("-0000Inf", sprintf("%+ 08f", -inf))
+ assert_equal(" -Inf", sprintf("%+ 08f", -inf))
assert_equal('..f00000000',
sprintf("%x", -2**32), '[ruby-dev:32351]')
assert_equal("..101111111111111111111111111111111",