    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %                                                               %
    %              tkz-arith.sty      encodage : utf8               %
    %                                                               %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %                                                               %
    %           Créé par Alain Matthes le 10-10-2007.               %
    %                                                               %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
%% Objet :  tools for arithmetic 
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{tkz-arith}[2008/04/15 v2.7b integers numbers]
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
\RequirePackage{ifthen}

%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
%                            arithmetic tools 
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
%                          modI
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
% \pgfmath@parsefunction@mod 
%
\def\pgfmath@parsefunction@modI{%
  \expandafter\pgfmath@parsefunction@modI@}
\def\pgfmath@parsefunction@modI@(#1,{%
  \pgfmathparse@{#1}\edef\pgfmath@firstoperand{\pgfmathresult}%
  \let\pgfmath@parsepostgroup\pgfmath@parsefunction@modI@@
  \pgfmath@startparsegroup}
\def\pgfmath@parsefunction@modI@@{%
  \edef\pgfmath@secondoperand{\pgfmathresult}%
  \pgfmathmodI@{\pgfmath@firstoperand}{\pgfmath@secondoperand}%
  \pgfmath@postfunction}
  
% \pgfmathmod
%
% Calculate #1 modI #2.
%
\def\pgfmathmodI#1#2{%
  \edef\pgfmath@marshal{%
    \noexpand\pgfmathparse{#2}
    \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult%
    \noexpand\pgfmathparse{#1}%
  }%
  \pgfmath@marshal%
  \pgfmathmodI@{\pgfmathresult}{\pgfmath@arg}%
}
\def\pgfmathmodI@#1#2{%
  \begingroup%
    \pgfmath@xa#1pt%
    \pgfmath@xb#2pt%
    \pgfmath@x\pgfmath@xa%
    \c@pgfmath@counta\pgfmath@xa%
    \c@pgfmath@countb\pgfmath@xb%
    \divide\c@pgfmath@counta\c@pgfmath@countb%
    \multiply\pgfmath@xb\c@pgfmath@counta%
    \advance\pgfmath@x-\pgfmath@xb%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        \pgfmath@xb#2pt%
        \ifdim\pgfmath@x<0pt\relax%
       \advance\pgfmath@x\pgfmath@xb\relax%
     \fi%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \pgfmath@returnone\pgfmath@x%
  \endgroup%
}


%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>

\def\nameedef#1{\expandafter\edef\csname #1\endcsname}
\def\nameuse#1{\csname #1\endcsname}
\newcounter{prim@r}
\newcounter{prim@q}
\newcounter{prim@a}
\newcounter{tprim@a}
\newcounter{tprim@b}
\newcounter{prim@n}
\newcounter{prim@d}
\newcounter{prim@b}
\newcounter{tkza@int}
\newcounter{tkza@tmp}
\newcounter{NbOfPrimFactor}\setcounter{NbOfPrimFactor}{0} 
\newboolean{tkzaIsAPrim}
\newboolean{goodtest}
\newboolean{tkzaIsAFactor}
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
% #2 divide #1 ?
\newcommand*{\tkzFindFactor}[2]{% 
\pgfmathsetcounter{prim@r}{modI(#1,#2)}
\ifthenelse{\equal{\theprim@r}{0}}{\setboolean{tkzaIsAFactor}{true}}{%
                                   \setboolean{tkzaIsAFactor}{false}}%
}
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
\newcommand*{\factors}[1]{%
\setcounter{tkza@int}{#1}%
\setboolean{tkzaIsAPrim}{false}%
\setcounter{NbOfPrimFactor}{0}%
\primality{\thetkza@int}%
\setcounter{prim@d}{2}%
\ifthenelse{\boolean{tkzaIsAPrim}}{%
   \thetkza@int\ }{%
   \whiledo{\not\equal{\thetkza@int}{1}}{%
        \ifthenelse{\isodd{\value{tkza@int}}}{%
            \setcounter{prim@d}{1}%
            \setcounter{prim@r}{1}%
            \whiledo{\not\equal{\theprim@r}{0}}{%
                \pgfmathaddtocounter{prim@d}{2}%
                \pgfmathsetcounter{prim@r}{modI(\thetkza@int,\theprim@d)}%
                }}{}%
         \pgfmathsetcounter{tkza@int}{\thetkza@int/\theprim@d}$\theprim@d\ $%
         \stepcounter{NbOfPrimFactor}%
         \nameedef{PrimFactor\alph{NbOfPrimFactor}}{\theprim@d}}%
}
}%
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
\newcommand*{\printdiv}[2]{%
  \setcounter{prim@a}{#1}\setcounter{prim@b}{#2}%
  \pgfmathsetcounter{prim@q}{\value{prim@a} / \value{prim@b}}%
  \theprim@q%
}%
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
% test if #1 is a prim number result set boolean :tkzaIsAPrim
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
\newcommand*\primality[1]{%
   \setboolean{tkzaIsAPrim}{true}%
\setcounter{prim@a}{#1}%
   \ifthenelse{#1 = 0}{%
     \setboolean{tkzaIsAPrim}{false}}{%
     \ifthenelse{#1 = 1}{%
       \setboolean{tkzaIsAPrim}{false}}{%
       \ifthenelse{#1 = 2}{}{%
          \ifthenelse{#1 = 3}{}{%
             \ifthenelse{\isodd{#1}}{%
               \setcounter{prim@d}{3}%
               \whiledo{\value{prim@a} > \value{prim@d}}{%
                  \pgfmathsetcounter{prim@r}{modI(\theprim@a,\theprim@d)}%
                  \ifthenelse{\value{prim@r} = 0}{%
                    \setboolean{tkzaIsAPrim}{false}%
                    \setcounter{prim@d}{\theprim@a}}{%
                    \pgfmathaddtocounter{prim@d}{2}
                   }%
               }% fin du whiledo
               }{%
               \setboolean{tkzaIsAPrim}{false}%
             }%
            }%
          }%
        }%
     }%
}%
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
% find pgcd of #1 and #2 result in \tkzmathresult and \theprim@a
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
\newcommand*\tkzPgcd[2]{%
\setcounter{prim@a}{#1}
 \setcounter{prim@b}{#2}
 \setcounter{prim@r}{\value{prim@a}} 
 \whiledo{\not\value{prim@r}=0} {% 
     \pgfmathsetcounter{prim@r}{modI(\value{prim@a},\value{prim@b})}
     \setcounter{prim@a}{\value{prim@b}}
     \setcounter{prim@b}{\value{prim@r}}%
     }%
\edef\tkzmathresult{\theprim@a}%
}

%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
%                   Simplification d'une fraction
% #2 if #2<>1 then frac with pi
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––>
\newcommand*{\tkz@reducfrac}[2]{%
\ifnum#1<0\relax%
    \pgfmathsetcounter{tprim@a}{-#1}%
    \def\tkzsgnnum{-}%
 \else%
   \setcounter{tprim@a}{#1}%
\fi%
\setcounter{tprim@b}{#2}%
 \tkzPgcd{\value{tprim@a}}{\value{tprim@b}}% 
\ifnum\value{tprim@a}=0%
  \setcounter{tprim@a}{(#1)}%
  \setcounter{tprim@b}{(#2)}%
\else%
  \pgfmathsetcounter{tprim@a}{(#1)/\tkzmathresult}%
  \pgfmathsetcounter{tprim@b}{(#2)/\tkzmathresult}%
\fi% 
%\def\tkz@rfrac{$\frac{\thetprim@a\pi}{\thetprim@b}$}
% modif for pi
\ifnum\value{tprim@a}=0%
   \global\def\tkz@rfrac{}%
\else%
\ifnum\value{tprim@b}=1%
   \ifnum\value{tprim@a}=1%
      \global\def\tkz@rfrac{$\scriptstyle{\pi}$}%
     \else%
      \ifnum\value{tprim@a}=-1%
         \global\def\tkz@rfrac{$\scriptstyle{-\pi}$}%
       \else%
         \global\def\tkz@rfrac{$\scriptstyle{\thetprim@a\pi}$}%
      \fi\fi%
\else% 
  \ifnum\value{tprim@a}=1%
      \global\def\tkz@rfrac{$\frac{\pi}{\thetprim@b}$}%
    \else%
      \ifnum\value{tprim@a}=-1%
         \global\def\tkz@rfrac{$\frac{-\pi}{\thetprim@b}$}%
       \else% 
          \global\def\tkz@rfrac{$\frac{\thetprim@a\pi}{\thetprim@b}$}%
\fi\fi\fi\fi%
}%

\endinput
%  pgfmath
%  pgffor