Unexplained differences in iteration between gnuplot 4.6 and gnuplot 5.0

梦想与她 提交于 2019-12-13 02:16:09

问题


In trying to answer a gnuplot question that involved the need to iterate over dates, I was told that my solution didn't work with gnuplot 4.6. In investigating why, I noticed a strange difference in how gnuplot 4.6 and gnuplot 5.0 are handling the same iteration construct.

Consider these two iteration expressions

do for [i=396835200:397094400:86400] {print i}
do for [i=396835200:397008000:86400] {print i}

In gnuplot 5.0, the first produces

396835200
396921600
397008000
397094400

and the second produces

396835200
396921600
397008000

but in gnuplot 4.6, the first produces only the first two numbers and the second produces one extra number (397094400).

Why is this happening? The gnuplot 5.0 behavior is correct according to the definition of iteration in gnuplot. Was there a bug that was fixed in gnuplot 5.0?

I had suspected that it may be related to an integer overflow, but I don't think these numbers are quite large enough to trigger that (they all easily fit in a 32 bit signed integer).

I had also suspected that there may have been a change in iteration so that the upper bound was checked using < in version 4.6 and <= in version 5.0, but that still wouldn't explain this (it almost would if the 4.6 outputs of those expressions were switched).

Why are these do versions behaving differently here? Any reference to changes in the release notes, or source code changes would be appreciated.


回答1:


It looks like I managed to find an answer myself. This is apparently a bug that appeared in gnuplot and was fixed in version 5.0.

The actual bug is reported at the gnuplot bug reports as bug number 1429 with a description roughly equivalent to mine, as well as a more detailed explanation of the fix in 1358.

This was fixed in version 5.0rc1 and version 4.6 patchlevel 6.

I won't repeat the source code here, as I don't know about the license restrictions, but there is a change in the file parse.c in the next_iteration function, where a patch was added to prevent an overflow caused by multiplying two large numbers together (and apparently a similar patch was needed in at least one other place).



来源:https://stackoverflow.com/questions/35003735/unexplained-differences-in-iteration-between-gnuplot-4-6-and-gnuplot-5-0

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