开发者

What Is "\t%.10g\n"

I'm new at Bison, but in C/C++ no and at this time of development and regular expressions i never heard something like this, only the \n that's used for a new line, but i want to know what is the explanation of \t%.10g, that in the code is li开发者_如何转开发ke this:

line:     '\n'
        | exp '\n'  { printf ("\t%.10g\n", $1); }
;

Best Regards.


It means "print a tab character (\t) followed by a floating point number with 10 decimal places, either in scientific or fixed point notation depending on the order of magnitude (%.10g), followed by a newline (\n)".


Have a look at the printf reference to decode the pattern:

g Use the shorter of %e or %f

e Scientific notation (mantise/exponent) using e character

f Decimal floating point

Thus, %.10g prints a decimal number with ten significant digits.


It's not a regex but a printf format specification : Print a tab character followed by a floating point number with 10 digits behind the decimal point, either %f (floating point notation) way or %e (scientific notatation) way, whichever is shorter, and end with a newline.

man printf
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜