Menu

#2259 summation of strings

None
closed-not-a-bug
nobody
None
2022-02-13
2020-05-09
No

Maybe it is not a bug, but I don't see a reason why the following code should not output 2.0. Tested in gnuplot 5.2.8.

gnuplot> a="1"
gnuplot> print sum [i = 1:2] a
         warning: encountered a string when expecting a number
         Did you try to generate a file name using dummy variable x or y?

Discussion

  • Ethan Merritt

    Ethan Merritt - 2020-05-10

    The error message seems clear enough. "sum" wants numerical values to sum, not strings.
    Compare
    print sum [i=1:2] int(a)
    or
    print sum [i=1:2] real(a)

     
  • Daniel Molina García

    Yes, I understand the error. My concern is because the following two options work.

    gnuplot> a="1"
    gnuplot> print a+a
    2
    gnuplot> sum = 0.0
    gnuplot> do for [i=1:2] {
    more> sum = sum + a
    more> }
    gnuplot> print sum
    2.0
    

    I am not used to gnuplot developer ideas, but I would expect sum to support strings which contain numbers.

     
  • Ethan Merritt

    Ethan Merritt - 2022-02-13
    • status: open --> closed-not-a-bug
    • Group: -->
    • Priority: -->
     

Log in to post a comment.