〔前の画面〕
〔クリックポイント〕 〔最新の一覧〕
〔全て読んだことにする〕〔全て読んだことにして終了〕 〔終了〕
1539 re(14):logscale での 固定/浮動小数点の表示の切替え |
2007/3/8(木)21:44 - 竹の - nolm01.iee.niit.ac.jp - 1576 hit(s)
松田七美男> gcc3.3.2に付属のman 3 printf の結果を引用しますと,
正確に言うと、gcc ではなくて、多分 glibc に付属のものだと思います。
松田七美男> 精度がゼロである場合には、1桁として取り扱われる。形
松田七美男> 式 e は、変換される値の指数が -4 より小さい場合、ま
なるほど、「変換される値」ってのが曲者ですね。つまり、変換する前の値だと
Linux は見ているんでしょうか。
Solaris 9 の man printf は以下の通りです:
g,G The double argument is printed in style f or e (or in
style E in the case of a G conversion character), with
the precision specifying the number of significant
digits. If an explicit precision is 0, it is taken as
1. The style used depends on the value converted:
style e (or E) will be used only if the exponent
resulting from the conversion is less than -4 or
greater than or equal to the precision. Trailing zeros
are removed from the fractional part of the result. A
radix character appears only if it is followed by a
digit.
「resulting from the conversion」ですから、明らかに変換結果の方を
見ています。FreeBSD (4.11) も同様で、
gG The double argument is converted in style f or e (or E for G con-
versions). The precision specifies the number of significant
digits. If the precision is missing, 6 digits are given; if the
precision is zero, it is treated as 1. Style e is used if the
exponent from its conversion is less than -4 or greater than or
equal to the precision. Trailing zeros are removed from the
fractional part of the result; a decimal point appears only if it
is followed by at least one digit.
「its conversion」ですから、変換したものが、と見ていると思います。
松田七美男> となっています.「変換される値の指数が-4より小さい場合にはe」ですから
松田七美男> 0.00009999 = 9.999e-5
松田七美男> は,e表示だと思うのです.何か大きな勘違いがありますでしょうか.
Linux のマニュアルがそうなっているなら、Linux ではそう見て、そう実装し
ている、ということでバグではない、ということになるような気もします。
K&R (第 2 版) は日本語訳しか持ってないですが、指数を見るのが変換前の値か、
変換後の値かは明示されてはいません。
g, G: 指数が -4 よりも小さいか、あるいは精度より大きいか等しいときに
は %e または %E が使われる。そうでないときは %f が使われる。後
に続くゼロおよび小数点は印字されない
そもそも、これがあまり明確でないから混乱が起きているのかな。
けど、glibc 2.2 (?) の Linux の man printf
http://www.die.net/doc/linux/man/man3/printf.3.html
の g の説明は、上の FreeBSD のと全く同じ文です (多分マニュアルの出どころ
が同じなんでしょう)。
うーん。
個人的には、元々の %g の意味からして、変換したものの指数を評価すべき (つ
まり FreeBSD, Solaris 側) じゃないかと思います。もちろん、それなら . を
とった場合も面倒みろよ、という気もしますが、そこまでは指定されてなかった
んで仕方ないと。
こういう議論って、既にどこかでやってないんでしょうかね。
〔ツリー構成〕
┣【1539】 re(14):logscale での 固定/浮動小数点の表示の切替え 2007/3/8(木)21:44 竹の (3062) |
〔前の画面〕
〔クリックポイント〕 〔最新の一覧〕
〔全て読んだことにする〕〔全て読んだことにして終了〕 〔終了〕
※ 『クリックポイント』とは一覧上から読み始めた地点を指し、ツリー上の記事を巡回しても、その位置に戻ることができます.