Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Taking the modulo of column data

2,191 views
Skip to first unread message

Gert

unread,
Nov 8, 2002, 6:04:19 AM11/8/02
to
When trying to take the modulo of a column variable, I get:

"script_name", line 5: can only mod ints

Line 5 refers to:

plot "<data_file_name>" using
<column_number_1>:($<column_number_2>%<mod_base>) title '<title>' with
lines

The data of <column_number_2> does indeed solely consist of integers.

So, is this is a bug? Or do I have to provide some sort of casting to tell
gnuplot the data are integers.

Thank you,

Gert

Hans-Bernhard Broeker

unread,
Nov 8, 2002, 7:33:38 AM11/8/02
to
Gert <Eagerb...@hotmail.com> wrote:

> The data of <column_number_2> does indeed solely consist of integers.

You may know that, but gnuplot doesn't. You have to tell it, by
casting, like this:

plot 'datafile' using 1:(int($2) % 2)

--
Hans-Bernhard Broeker (bro...@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Gert

unread,
Nov 12, 2002, 5:00:31 AM11/12/02
to
> > The data of <column_number_2> does indeed solely consist of integers.
>
> You may know that, but gnuplot doesn't. You have to tell it, by
> casting, like this:
>
> plot 'datafile' using 1:(int($2) % 2)

Thank you very much. I had looked into many online tutorials, but still
hadn't find any information about this casting.

Did I overlook the existence of a decent tutorial which does incorporate
these kind of manipulations (...and much more)?

Gert

Hans-Bernhard Broeker

unread,
Nov 12, 2002, 6:39:19 AM11/12/02
to
Gert <Eagerb...@hotmail.com> wrote:

> Did I overlook the existence of a decent tutorial which does incorporate
> these kind of manipulations (...and much more)?

I don't think so. You did overlook the actual gnuplot documentation,
though. To be more precise: "help expression", which says:

Note that gnuplot uses both "real" and "integer" arithmetic, like FORTRAN and
C. Integers are entered as "1", "-10", etc; reals as "1.0", "-10.0", "1e1",
3.5e-1, etc. The most important difference between the two forms is in
division: division of integers truncates: 5/2 = 2; division of reals does
not: 5.0/2.0 = 2.5. In mixed expressions, integers are "promoted" to reals
before evaluation: 5/2e0 = 2.5. The result of division of a negative integer
by a positive one may vary among compilers. Try a test like "print -5/2" to
determine if your system chooses -2 or -3 as the answer.

This explains why the problem occurs in the first place.

Gert

unread,
Nov 12, 2002, 12:55:38 PM11/12/02
to
> I don't think so. You did overlook the actual gnuplot documentation,
> though. To be more precise: "help expression", which says:
>
> Note that gnuplot uses both "real" and "integer" arithmetic, like FORTRAN and
> C. Integers are entered as "1", "-10", etc; reals as "1.0", "-10.0", "1e1",
> 3.5e-1, etc. The most important difference between the two forms is in
> division: division of integers truncates: 5/2 = 2; division of reals does
> not: 5.0/2.0 = 2.5. In mixed expressions, integers are "promoted" to reals
> before evaluation: 5/2e0 = 2.5. The result of division of a negative integer
> by a positive one may vary among compilers. Try a test like "print -5/2" to
> determine if your system chooses -2 or -3 as the answer.
>
> This explains why the problem occurs in the first place.

Well, actually, I did read this part of the documentation. So I understood
the nature of the problem. But the documentation didn't mention anything
about the possibility to perform casting.

Thanks anyway for pointing me out.

Greetings,

Gert

galax...@gmail.com

unread,
Mar 11, 2019, 12:56:21 PM3/11/19
to
This does not work in you use:

set datafile separator ","

for comma separated data (CSV)

This must be a bug right?

galax...@gmail.com

unread,
Mar 11, 2019, 12:57:27 PM3/11/19
to
"if" you use:
0 new messages