printfの変換仕様について。
printf() の変換仕様「%+f」 「%g」について軽く教えてください。
printfの変換仕様
Re: printfの変換仕様
%+fは浮動小数点数を符号付きで出力します。
%gは浮動小数点数を短く出力します。
%gは浮動小数点数を短く出力します。
(http://www.open-std.org/jtc1/sc22/wg14/ ... /n1256.pdf)N1256 7.19.6.1 The fprintf function さんが書きました: + The result of a signed conversion always begins with a plus or minus sign.(It begins with a sign only when a negative value is converted if this flag is not specified.)
(中略)
f, F A double argument representing a floating-point number is converted to decimal notation in the style[−]ddd.ddd, where the number of digits after the decimal-point character is equal to the precision specification.If the precision is missing, it is taken as 6; if the precision is zero and the # flag is not specified, no decimal-point character appears. If a decimal-point character appears, at least one digit appears before it. The value is rounded to the appropriate number of digits.
A double argument representing an infinity is converted in one of the styles [-]inf or [-]infinity—which style is implementation-defined. A double argument representing a NaN is converted in one of the styles [-]nan or [-]nan(n-char-sequence)—which style, and the meaning of any n-char-sequence, is implementation-defined. The F conversion specifier produces INF,INFINITY, or NAN instead of inf, infinity, or nan, respectively.
(中略)
g, G A double argument representing a floating-point number is converted in style for e(or in style For E in the case of a G conversion specifier), depending on the value converted and the precision. Let P equal the precision if nonzero, 6 if the precision is omitted, or 1 if the precision is zero. Then, if a conversion with style E would have an exponent of X :
—if P>X≥−4, the conversion is with style f (or F) and precision P−(X+1).
—otherwise, the conversion is with style e (or E)and precision P−1.
Finally, unless the # flag is used, any trailing zeros are removed from the fractional portion of the result and the decimal-point character is removed if there is no fractional portion remaining.
A double argument representing an infinity or NaN is converted in the style of an f or F conversion specifier.
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)