|
From: Juhász P. <pet...@gm...> - 2010-12-29 17:14:42
|
On Tue, 2010-12-28 at 16:36 -0600, Daniel J Sebald wrote:
> Thanks Péter. The rand() function should probably be revisited with your comments in mind. More below.
>
> Juhász Péter wrote:
> > Dear gnuplot developers,
> >
> > a recent thread[1] in the newsgroup made me play with the rand()
> > function, and I've found some issues with it:
> >
> > 1) rand() silently accepts string arguments:
> > gnuplot> print rand("foo")
> > 0.222457440974512
> >
> > While this is not particularly bad in itself, but it's not consistent
> > with the behavior of other numerical functions (which reject string
> > arguments), and it's undocumented.
>
> Actually, my observation is that functions having real arguments will reject string inputs while functions with optional complex arguments will not reject string inputs. For example
>
> gnuplot> print gamma("test")
>
> gnuplot> print gamma("test")
> ^
> undefined value
>
> gnuplot> print erfc("test")
> 1.0
>
I think this is not true.
# optional complex argument
gnuplot> pr sin({2,3})
{9.15449914691143, -4.16890695996656}
# croaks on meaningless strings
gnuplot> pr sin("foo")
Non-numeric string found where a numeric expression was
expected
# works with meaningful strings
gnuplot> pr sin("3")
0.141120008059867
> Perhaps the gnuplot code needs to be altered to also reject strings if the argument is possibly complex, unless a string is a valid input argument. (But I don't know of any, off hand.)
>
Ethan's suggestion about pop_or_convert_from_string(x) adequately fixes
this problem.
>
> > Its effect is the same as that of
> > rand(0) - which have misled the user in the thread[1], because he
> > thought that rand("time") sets the random seed to the current time.
>
> Are you proposing there should be an input argument "time"?
No, but now that you mention it, I've found it frustrating that there is
no way within gnuplot to get the current time, one has to resort to an
external application. There is already an extensive framework in place
for formatting date&time strings, there is even a way to put the current
time as a time stamp on the plot, but there is no way to get it as a
variable (for example). There ought to be a time() function that returns
the current gnuplot time (seconds since 2000), the existing formatting
functions are adequate to transform that into any other format.
Apart from the very narrow use case of initializing rand(), this
proposed function would allow for relative time plots, e.g.
plot "logfile" u (timecol(1)-time()):2
>
> Dan
Péter Juhász
|