Latex plotting (jagged function)

Hey, I have a function which I would like to plot with latex/tikz. Since I'm just a beginner I really don't know how to do it. Don't get me wrong I don't have any problems with most functions but this one is a killer and the documentation is a little bit overwhelming.

It would be great if someone could help me to plot this one.

-

You can try the following.

part 1 : I think the difficult part is to get the fractional part of a number. The pgf/tikz function Mod does just that. Note that it is not the same as mod.

part 2 : one problem with the function f and tikz is the fact that tikz uses fixed point arithmetic and for this function you quickly exceed the limits. One way around this is to use the fpu library., but this is not what I will do. A pure tikz approach, noticing that u(100^n*x) is only there to get successive decimal digits of x, is shown below. Also, the sample rate of the plot changes the aspect of the plot dramatically.

\documentclass{minimal}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
[declare function={
u(\x) = Mod(\x,1);
j(\x) = 1- abs(u(\x)-0.5);
f(\x) = j(100*\x)/10 + j(100*u(100*\x))/100 + j(100*u(100*u(100*\x)))/1000;}]

\draw[domain=-1:1,samples=50] plot (\x,{f(\x)});

\end{tikzpicture}
\end{document}

-