# Printf "\[%08f\]\\n", 0.0/0.0

**URL:** <https://www.ruby-forum.com/t/printf-08f-n-0-0-0-0/131061>\
**Category:** Development\
**Created:** [March 5, 2008, 5:58pm UTC](https://www.ruby-forum.com/t/printf-08f-n-0-0-0-0/131061 "2008-03-05T17:58:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [March 5, 2008, 5:58pm UTC](https://www.ruby-forum.com/t/printf-08f-n-0-0-0-0/131061/1 "2008-03-05T17:58:16Z")

</div>

e$B0J2\<$N$h$&$K!"e(Bprintf e$B$Ge(B NaN, Inf e$B$Ge(B 0 padding  
e$B$,5/$3$j$^$9!#e(B

% ./ruby -ve ‘printf “[%08f]\n”, 0.0/0.0’  
ruby 1.9.0 (2008-03-06 revision 15699) [i686-linux]  
[00000NaN]  
% ./ruby -e ‘printf “[%08f]\n”, 1.0/0.0’  
[00000Inf]  
% ./ruby -e ‘printf “[%08f]\n”, -1.0/0.0’  
[-0000Inf]

e$B$7$+$7!"e(BC e$B$N5,3J$G$Oe(B NaN e$B$He(B Inf e$B$K4X$7$F$Oe(B 0  
padding e$B$O5/$3e(B  
e$B$j$^$;$s!#\<B:]!"e(Bglibc e$B$G$O$=$&$J$j$^$9!#e(B

% uname -srv  
Linux 2.6.18-5-686 #1 SMP Mon Dec 24 16:41:07 UTC 2007  
% cat tst.c  
#include \<stdlib.h\>  
#include \<stdio.h\>

int main(int argc, char \*\*argv)  
{  
printf("[%08f]\n", 0.0/0.0);  
printf("[%08f]\n", 1.0/0.0);  
printf("[%08f]\n", -1.0/0.0);  
return 0;  
}  
% gcc tst.c  
% ./a.out  
[nan]  
[inf]  
[-inf]

---

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [March 6, 2008, 2:47am UTC](https://www.ruby-forum.com/t/printf-08f-n-0-0-0-0/131061/2 "2008-03-06T02:47:30Z")

</div>

e$B$J$+$@$G$9!#e(B

At Thu, 6 Mar 2008 01:57:27 +0900,  
Tanaka A. wrote in [ruby-dev:33994]:

> e$B0J2\<$N$h$&$K!"e(Bprintf e$B$Ge(B NaN, Inf e$B$Ge(B 0 padding e$B$,5/$3$j$^$9!#e(B
> 
> % ./ruby -ve ‘printf “[%08f]\n”, 0.0/0.0’  
> ruby 1.9.0 (2008-03-06 revision 15699) [i686-linux]  
> [00000NaN]  
> % ./ruby -e ‘printf “[%08f]\n”, 1.0/0.0’  
> [00000Inf]  
> % ./ruby -e ‘printf “[%08f]\n”, -1.0/0.0’  
> [-0000Inf]

e$B%F%9%H$b4V0c$C$F$$$k$H$$$&$3$H$G$7$g$&$+!#e(B

# Index: sprintf.c

— sprintf.c (revision 15701)  
+++ sprintf.c (working copy)  
@@ -767,4 +767,5 @@ rb\_str\_format(int argc, const VALUE \*arg  
const char \*expr;

- 

```
   flags &= ~FZERO;
   if (isnan(fval)) {
 expr = "NaN";

```

# Index: test/ruby/test\_sprintf.rb

— test/ruby/test\_sprintf.rb (revision 15701)  
+++ test/ruby/test\_sprintf.rb (working copy)  
@@ -88,7 +88,7 @@ class TestSprintf \< Test::Unit::TestCase  
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(" 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

@@ -111,7 +111,7 @@ class TestSprintf \< Test::Unit::TestCase  
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(" 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("-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("-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]’)

---

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [March 6, 2008, 5:01am UTC](https://www.ruby-forum.com/t/printf-08f-n-0-0-0-0/131061/3 "2008-03-06T05:01:09Z")

</div>

In article [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
Nobuyoshi N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> e$B%F%9%H$b4V0c$C$F$$$k$H$$$&$3$H$G$7$g$&$+!#e(B

e$B$?$V$s!#e(B

Inf e$B$de(B NaN e$B$Ke(B 0 e$B$,$D$/$HJQ$G$9$h$M!#e(B

e$B$^$?!";d$,D4$Y$?$N$Oe(B C99 e$B$Ne(B draft e$B$He(B JIS X 3010  
e$B$Ne(B fprintfe$B$Ne(B  
e$B9`$Ge(B

```
   0 For d, i, o, u, x, X, a, A, e, E, f, F, g, and G
         conversions, leading zeros (following any indication
         of sign or base) are used to pad to the field width |
         rather than performing space padding, except when |
         converting an infinity or NaN. If the 0 and - flags
         both appear, the 0 flag is ignored. For d, i, o, u,
         x, and X conversions, if a precision is specified, the
         0 flag is ignored. For other conversions, the
         behavior is undefined.

```

e$B$H$+e(B

```
   220When applied to infinite and NaN values, the -, +, and
      space flag characters have their usual meaning; the # and
      0 flag characters have no effect.

```

e$B$H!"e(B0 (e$B$He(B #) e$B$Oe(B infinity e$B$He(B NaN  
e$B$K$O8z$+$J$$$HL@3N$K=q$$$F$"e(B  
e$B$j$^$9!#e(B  
(e$B$=$l$KBP$7!"e(B-, +, space e$B$O8z$/$h$&$G$9!#e(BNaN  
e$B$NId9f$O$h$/$oe(B  
e$B$+$j$^$;$s$,!#e(B)
