与 gnuplot 格式说明符 %t 和 %T 不一致?
Inconsistency with gnuplot format specifiers %t and %T?
如果您使用 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
?
这背后的原因是什么?
实际上,除了gprintf("%t",95)
和gprintf("%T",95)
没有显示预期的尾数和幂之外,公式floor(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 源代码中修复。
如果您使用 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
?
这背后的原因是什么?
实际上,除了gprintf("%t",95)
和gprintf("%T",95)
没有显示预期的尾数和幂之外,公式floor(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 源代码中修复。