Command Line and Plot2d: different resutls



Probably I this is due to some pilot error, but I am confused why I get 
different results when I evaluate a function at the command line 
compared to using Plot2D.

Functions of interest are:

    fmod(x,y):=(1.0*x/(1.0*y) - floor(1.0*x/(1.0*y)))*(1.0*y);

    triangleWv(t,tp):=if fmod(floor(t*1.0/(1.0*tp)),2.0) = 0.0 then 
fmod(t,tp) else tp - fmod(t,tp);

My function triangleWv(t,tP) was intended to plot a "triangle wave" with 
period 2*tP; i.e., for triangleWv(t,10.0), 0<= t <= 20, the intention is 
to get a straight line with positive slope from 0 to 10, and then a 
straight line with negative slope from 10 to 20.

Following gives results from command line:

> (%i7) triangleWv(3.0,10.0);
> (%o7) 3.0
and
> (%i8) triangleWv(13.0,10.0);
> (%o8) 7.0
These are the intended results.

Yet, when I try

> (%i9) plot2d([triangleWv(t,10.0)], [t,0,20], [gnuplot_preamble, "set 
> xrange [0:20];"])$
I get two periods of a straight line with negative slope.

Is this a "bug", or more likely my confusion.

Thanks,

John