Inconsistency with gnuplot format specifiers %t and %T?

◇◆丶佛笑我妖孽 提交于 2019-11-28 06:21:35

问题


If you use the gnuplot format specifiers %t and %T, you will observe some inconsistent behaviour.

### gnuplot format specifiers

Numbers = "94 95 99 100 101"

do for [n in Numbers] {
    print gprintf("%3g",n)." = ".gprintf("%t",n)." x 10^".gprintf("%T",n)
}

Mantissa(n) = real(n)/10**floor(log10(n))
Power(n) = floor(log10(n))
do for [n in Numbers] {
    print gprintf("%3g",n)." = ",Mantissa(n)," x 10^",Power(n)
}
### end of code

Result:

 94 = 9.400000 x 10^1
 95 = 0.950000 x 10^2
 99 = 0.990000 x 10^2
100 = 1.000000 x 10^2
101 = 1.010000 x 10^2
 94 = 9.4 x 10^1
 95 = 9.5 x 10^1
 99 = 9.9 x 10^1
100 = 1.0 x 10^2
101 = 1.01 x 10^2

Why, for example, is 95 shown as 0.95 x 10^2 instead of 9.5 x 10^1? What is the reasoning behind this?


回答1:


Actually, besides gprintf("%t",95) and gprintf("%T",95) not showing the expected mantissa and power, also the formula floor(log10(n)) sometimes does not show the correct power of n. (see here: gnuplot: how to get correct order of magnitude?)

Suggestion for workaround: the following formulas make a detour via string formatting, but at least they should always give the correct mantissa and power.

Mantissa(n) = real(sprintf("%.15e",n)[1:strstrt(sprintf("%.15e",n),"e")-1])

Power(n) = int(sprintf("%.15e",n)[strstrt(sprintf("%.15e",n),"e")+1:])

In the longterm, the functions gprintf("%t",...), gprintf("%T",...) should be fixed in the gnuplot source code.



来源:https://stackoverflow.com/questions/55130265/inconsistency-with-gnuplot-format-specifiers-t-and-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!