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

是否与gnuplot格式说明符%t和%t不一致?,gnuplot,number-formatting,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) =

如果使用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.95x10^2
而不是
9.5x10^1

这背后的原因是什么?

事实上,除了
gprintf(“%t”,95)
gprintf(“%t”,95)
没有显示预期的尾数和幂,还有
下限公式(log10(n))
有时也没有显示
n的正确幂。(见此处:)

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

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:])
从长远来看,函数
gprintf(“%t”,…)
gprintf(“%t”,…)
应该固定在gnuplot源代码中