与gnuplot格式说明符%t和%T不一致?

时间:2019-03-12 20:37:00

标签: gnuplot number-formatting

如果使用gnuplot格式说明符%t%T,则会观察到一些不一致的行为。

### 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

结果:

 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

例如,为什么95显示为0.95 x 10^2而不是9.5 x 10^1? 这背后的原因是什么?

1 个答案:

答案 0 :(得分:0)

实际上,除了gprintf("%t",95)gprintf("%T",95)没有显示期望的尾数和幂之外,公式floor(log10(n))有时也没有显示n的正确幂。 (请参见此处:gnuplot: how to get correct order of magnitude?

解决方法的建议:以下公式通过字符串格式绕道而行,但至少它们应始终给出正确的尾数和幂。

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:])

从长远来看,应该在gnuplot源代码中固定功能gprintf("%t",...)gprintf("%T",...)

相关问题