是否与gnuplot格式说明符%t和%T不一致? [英] Inconsistency with gnuplot format specifiers %t and %T?

查看:157
本文介绍了是否与gnuplot格式说明符%t和%T不一致?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

结果:

 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? 背后的原因是什么?

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?

推荐答案

实际上,除了gprintf("%t",95)gprintf("%T",95)没有显示期望的尾数和幂,公式floor(log10(n))有时也没有显示n. (请参见此处: gnuplot:如何获取正确的数量级?)

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

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

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

这篇关于是否与gnuplot格式说明符%t和%T不一致?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆