|
From: Ethan M. <merritt@u.washington.edu> - 2004-10-14 20:01:08
|
On Thursday 14 October 2004 12:29 pm, Juergen Wieferink wrote:
> Am Mittwoch, 13. Oktober 2004 19:39 schrieb Ethan Merritt:
> > Issues that have been raised regarding the core code (#1043784)
> >
> > - The pre-defined function sprintf() requires some familiarity
> > with C language formats. Harald doesn't like this. I see it as a
> > feature, since the documentation is basically "see man page for
> > sprintf"
>
> I tried
>
> gnuplot> print sprintf("%i", 5)
> 5
> gnuplot> print sprintf("%i", 5.)
> 0
> gnuplot> print sprintf("%f", 5.)
> 5.000000
> gnuplot> print sprintf("%f", 5)
> 0.000000
>
> Are the second and the fourth example meant not to work?
The 2nd example doesn't work in C either.
"see man page for sprintf" :-) :-)
> But is there a way to find out if a variable is an int or
> a double/complex (apart from "show var")? I'd prefer not to have to
> trigger what type my variable is -- at least as long as I know it is
> numerical.
gnuplot already has the standard functions floor(x) and ceil(x),
which will force an integer value. If you are not sure whether FOO
is currently an int, you can do
FOO = floor(FOO)
> How difficult would it be to get gnuplot to do casts implicitly?
The existing code in internal.c maps all arithmetic operations onto
C language statements, so the normal C rules for promoting
ints to doubles apply.
Are you asking if it would be possible to catch mis-matched
format statements at runtime? I suppose so, although this goes
beyond what most languages do.
The string variable code already does a little of that, since
otherwise an attempt to print a number with %s would segfault
immediately.
--
Ethan A Merritt merritt@u.washington.edu
Biomolecular Structure Center
Mailstop 357742
University of Washington, Seattle, WA 98195
|