зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
6aac0579d1
Коммит
591503c0ab
|
@ -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
|
||||
|
|
21
sprintf.c
21
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] = '-';
|
||||
|
|
|
@ -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",
|
||||
|
|
Загрузка…
Ссылка в новой задаче