Bug in gmt math when reading from STDIN?

I ran the following commands, and in both cases the result is 5.
In the second command, I switched the order of the operands (expecting to get -5), but I still get 5.

Is this a bug, or am I misunderstanding how gmt math handles the -C0 option?

echo 10 | gmt math STDIN -C0 5 SUB  =
echo 10 | gmt math STDIN 5 -C0 SUB  =

You didn’t change the order of the operand, just the column on which the operation is made.

-C0 STDIN 5 SUB : restrict to first column then operate
STDIN 5 SUB -C0 : operate then restrict to first column … But the operation default to whatever column it finds (because no restriction beforehand).

Does it make sense ?

$ echo "1 2" | gmt math STDIN 5 SUB = % applies to last column
1       -3
$ echo "1 2" | gmt math -C0 STDIN 5 SUB = % restrict to first column from the get go
-4      0
$ echo "1 2" | gmt math STDIN -C0 5 SUB = % reads all, then operation on first column
-4      2
$ echo "1 2" | gmt math STDIN 5 -C0 SUB = % same
-4      2
$ echo "1 2" | gmt math STDIN 5 SUB -C0 = % too late, has no effect
1      -3
$ echo "1 2" | gmt math STDIN -C0 5 SUB -C1 3 ADD = % reads all, restrict SUB on first and restrict ADD on second
-4      5
$ echo "1 2" | gmt math -C0 STDIN 5 SUB -C1 3 ADD =% reads first column only, SUB first ADD second 
-4      3

1 Like

Thanks for the explanation!