summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCDecDeci.tex
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/profcollege/latex/PfCDecDeci.tex')
-rw-r--r--macros/latex/contrib/profcollege/latex/PfCDecDeci.tex177
1 files changed, 177 insertions, 0 deletions
diff --git a/macros/latex/contrib/profcollege/latex/PfCDecDeci.tex b/macros/latex/contrib/profcollege/latex/PfCDecDeci.tex
new file mode 100644
index 0000000000..3e9cc7d1c8
--- /dev/null
+++ b/macros/latex/contrib/profcollege/latex/PfCDecDeci.tex
@@ -0,0 +1,177 @@
+%%%
+% Décomposition décimale
+%%
+\setKVdefault[DecompDeci]{Parentheses,Colore=false,CouleurU=Blue,CouleurD=Red,CouleurC=Green,Fleches=false,Details=false}
+
+\newcounter{PfCNbDecDeci}
+\setcounter{PfCNbDecDeci}{0}
+
+\NewDocumentCommand\DecompositionDecimale{o m}{%
+ \stepcounter{PfCNbDecDeci}%
+ \useKVdefault[DecompDeci]%
+ \setKV[DecompDeci]{#1}%
+ % On cherche si le nombre est décimal ou entier
+ \StrCount{#2}{.}[\PfCNombrePoint]%
+ \xintifboolexpr{\PfCNombrePoint==0}{%
+ % on compte la longueur.
+ \StrLen{#2}[\PfCNombrePuisMax]%
+ \xdef\PfCRetiensPuis{0}%
+ % On cherche le nombre de 0 terminaux.
+ \xintFor* ##1 in{\xintSeq{1}{\PfCNombrePuisMax}}\do{%
+ \xintifboolexpr{\fpeval{#2/(10^##1)}==\fpeval{round(#2/(10^##1))}}{%
+ \xdef\PfCRetiensPuis{\fpeval{\PfCRetiensPuis+1}}%
+ }{}%
+ }%
+ % On cherche un affichage du style \num de \siunitx
+ \modulo{\fpeval{\PfCNombrePuisMax}}{3}%
+ \xintifboolexpr{\remainder==0}{%
+ \xdef\PfCDecDeciEcart{0}
+ }{\xintifboolexpr{\remainder==1}{\xdef\PfCDecDeciEcart{1}}{\xdef\PfCDecDeciEcart{2}}}
+ \ifboolKV[DecompDeci]{Fleches}{%
+ \colorlet{oldcolor}{black}%
+ % On affiche
+ \begin{center}
+ \xintFor* ##1 in {\xintSeq{1}{\fpeval{\PfCNombrePuisMax}}}\do{%
+ \StrChar{#2}{##1}[\PfCNombreChiffre]%
+ \modulo{\fpeval{\PfCNombrePuisMax+\PfCDecDeciEcart--##1}}{3}%
+ \xintifboolexpr{\remainder==0}{%
+ \color{\useKV[DecompDeci]{CouleurU}}\tikzmarknode[anchor=south,inner ysep=2pt]{DDA-\thePfCNbDecDeci-##1}{\PfCNombreChiffre}{}\xintifForLast{}{\,\color{oldcolor}}}{%
+ \xintifboolexpr{\remainder==1}{%
+ \color{\useKV[DecompDeci]{CouleurC}}\tikzmarknode[anchor=south,inner ysep=2pt]{DDA-\thePfCNbDecDeci-##1}{\PfCNombreChiffre}{}}{%
+ \color{\useKV[DecompDeci]{CouleurD}}\tikzmarknode[anchor=south,inner ysep=2pt]{DDA-\thePfCNbDecDeci-##1}{\PfCNombreChiffre}{}%
+ }%
+ }%
+ }\color{oldcolor}%
+
+ \vspace*{3em}
+
+ \ifboolKV[DecompDeci]{Details}{%
+ \ensuremath{%
+ \xintFor* ##1 in {\xintSeq{1}{\fpeval{\PfCNombrePuisMax-\PfCRetiensPuis}}}\do{%
+ \StrChar{#2}{##1}[\PfCNombreChiffre]
+ \modulo{\fpeval{\PfCNombrePuisMax+\PfCDecDeciEcart--##1}}{3}%
+ \colorlet{oldcolor}{.}
+ \xintifboolexpr{\remainder==0}{\color{\useKV[DecompDeci]{CouleurU}}}{%
+ \xintifboolexpr{\remainder==1}{\color{\useKV[DecompDeci]{CouleurC}}}{%
+ \color{\useKV[DecompDeci]{CouleurD}}%
+ }%
+ }%
+ \xintifboolexpr{\PfCNombreChiffre==0}{}{%
+ \tikzmarknode[anchor=north,inner ysep=2pt]{DDC-\thePfCNbDecDeci-##1}{\boxed{\num{\fpeval{\PfCNombreChiffre*10^(\PfCNombrePuisMax-##1)}}}}\color{oldcolor}%
+ \xintifForLast{}{+}%
+ }%
+ }%
+ }%
+
+ \vspace*{3em}
+
+ }{}%
+
+ \ensuremath{%
+ \xintFor* ##1 in {\xintSeq{1}{\fpeval{\PfCNombrePuisMax-\PfCRetiensPuis}}}\do{%
+ \StrChar{#2}{##1}[\PfCNombreChiffre]
+ \xintifboolexpr{\PfCNombreChiffre==0}{}{%
+ \modulo{\fpeval{\PfCNombrePuisMax+\PfCDecDeciEcart--##1}}{3}%
+ \colorlet{oldcolor}{.}
+ \xintifboolexpr{\remainder==0}{\color{\useKV[DecompDeci]{CouleurU}}}{%
+ \xintifboolexpr{\remainder==1}{\color{\useKV[DecompDeci]{CouleurC}}}{%
+ \color{\useKV[DecompDeci]{CouleurD}}%
+ }%
+ }%
+ \tikzmarknode[anchor=north,inner ysep=2pt]{DDB-\thePfCNbDecDeci-##1}{\boxed{\PfCNombreChiffre\times\num{\fpeval{10^(\PfCNombrePuisMax-##1)}}}}{}\color{oldcolor}%
+ \xintifForLast{}{+}%
+ }%
+ }%
+ }%
+ \end{center}
+ \begin{tikzpicture}[remember picture,overlay]
+ \xintFor* ##1 in {\xintSeq{1}{\fpeval{\PfCNombrePuisMax-\PfCRetiensPuis}}}\do{%
+ \StrChar{#2}{##1}[\PfCNombreChiffre]%
+ \modulo{\fpeval{\PfCNombrePuisMax+\PfCDecDeciEcart--##1}}{3}%
+ \xintifboolexpr{\remainder==0}{%
+ \colorlet{PfCDecDeciColor}{\useKV[DecompDeci]{CouleurU}}}{%
+ \xintifboolexpr{\remainder==1}{%
+ \colorlet{PfCDecDeciColor}{\useKV[DecompDeci]{CouleurC}}}{%
+ \colorlet{PfCDecDeciColor}{\useKV[DecompDeci]{CouleurD}}%
+ }%
+ }%
+ \ifboolKV[DecompDeci]{Details}{%
+ \xintifboolexpr{\PfCNombreChiffre>0}{%
+ \draw[-stealth,PfCDecDeciColor] (pic cs:DDA-\thePfCNbDecDeci-##1) to (pic cs:DDC-\thePfCNbDecDeci-##1);
+ \node (DDD-\thePfCNbDecDeci-##1) at ($(pic cs:DDC-\thePfCNbDecDeci-##1)!0.35!(pic cs:DDB-\thePfCNbDecDeci-##1)$) {};
+ \draw[-stealth,PfCDecDeciColor] (DDD-\thePfCNbDecDeci-##1) to (pic cs:DDB-\thePfCNbDecDeci-##1);
+ }{}%
+ }{%
+ \xintifboolexpr{\PfCNombreChiffre>0}{%
+ \draw[-stealth,PfCDecDeciColor] (pic cs:DDA-\thePfCNbDecDeci-##1) to (pic cs:DDB-\thePfCNbDecDeci-##1);
+ }{}%
+ }%
+ }%
+ \end{tikzpicture}
+ }{%
+ \ifboolKV[DecompDeci]{Colore}{%
+ \colorlet{oldcolor}{black}%
+ \ensuremath{%
+ \xintFor* ##1 in {\xintSeq{1}{\fpeval{\PfCNombrePuisMax}}}\do{%
+ \StrChar{#2}{##1}[\PfCNombreChiffre]%
+ \modulo{\fpeval{\PfCNombrePuisMax+\PfCDecDeciEcart--##1}}{3}%
+ \xintifboolexpr{\remainder==0}{\color{\useKV[DecompDeci]{CouleurU}}\PfCNombreChiffre\xintifForLast{}{\,\color{oldcolor}}}{%
+ \xintifboolexpr{\remainder==1}{\color{\useKV[DecompDeci]{CouleurC}}\PfCNombreChiffre}{%
+ \color{\useKV[DecompDeci]{CouleurD}}\PfCNombreChiffre%
+ }%
+ }%
+ }\color{oldcolor}%
+ =
+ \xintFor* ##1 in {\xintSeq{1}{\fpeval{\PfCNombrePuisMax-\PfCRetiensPuis}}}\do{%
+ \StrChar{#2}{##1}[\PfCNombreChiffre]
+ \xintifboolexpr{\PfCNombreChiffre==0}{}{%
+ \modulo{\fpeval{\PfCNombrePuisMax-\PfCRetiensPuis-##1}}{3}
+ \colorlet{oldcolor}{.}
+ \xintifboolexpr{\remainder==0}{\color{\useKV[DecompDeci]{CouleurU}}}{%
+ \xintifboolexpr{\remainder==1}{\color{\useKV[DecompDeci]{CouleurD}}}{%
+ \color{\useKV[DecompDeci]{CouleurC}}%
+ }%
+ }%
+ \boxed{\PfCNombreChiffre\times\num{\fpeval{10^(\PfCNombrePuisMax-##1)}}}\color{oldcolor}%
+ \xintifForLast{}{+}%
+ }%
+ }%
+ }
+ }{%
+ \ensuremath{%
+ \num{#2}=
+ \xintFor* ##1 in {\xintSeq{1}{\fpeval{\PfCNombrePuisMax-\PfCRetiensPuis}}}\do{%
+ \StrChar{#2}{##1}[\PfCNombreChiffre]
+ \xintifboolexpr{\PfCNombreChiffre==0}{}{%
+ \ifboolKV[DecompDeci]{Parentheses}{\left(}{}\PfCNombreChiffre\times\num{\fpeval{10^(\PfCNombrePuisMax-##1)}}\ifboolKV[DecompDeci]{Parentheses}{\right)}{}%
+ \xintifForLast{}{+}%
+ }%
+ }%
+ }%
+ }%
+ }%
+ }{%partie avec les nombres décimaux
+ \StrDel{#2}{.}[\PfCRetiensNombreEntier]%
+ \StrLen{#2}[\PfCNombrePuisMax]%
+ \xdef\PfCNombrePuisMax{\fpeval{\PfCNombrePuisMax-1}}%
+ \StrPosition{#2}{.}[\PfCPositionPoint]%
+ \xdef\PfCPuisDeci{\fpeval{\PfCNombrePuisMax-\PfCPositionPoint}}%
+ \xdef\PfCRetiensPuis{0}%
+ % On cherche le nombre de 0 terminaux.
+ \xintFor* ##1 in{\xintSeq{1}{\PfCNombrePuisMax}}\do{%
+ \xintifboolexpr{\fpeval{(#2*10^(\PfCPuisDeci+1))/(10^##1)}==\fpeval{round((#2*10^(\PfCPuisDeci+1))/(10^##1))}}{%
+ \xdef\PfCRetiensPuis{\fpeval{\PfCRetiensPuis+1}}%
+ }{}%
+ }%
+ \ensuremath{%
+ \num{#2}=
+ \xintFor* ##1 in {\xintSeq{1}{\PfCNombrePuisMax-\PfCRetiensPuis}}\do{%
+ \StrChar{\PfCRetiensNombreEntier}{##1}[\PfCNombreChiffre]
+ \xintifboolexpr{\PfCNombreChiffre==0}{}{%
+ \ifboolKV[DecompDeci]{Parentheses}{\left(}{}\PfCNombreChiffre\times\num{\fpeval{10^(\PfCNombrePuisMax-##1-\PfCPuisDeci-1)}}\ifboolKV[DecompDeci]{Parentheses}{\right)}{}%
+ \xintifForLast{}{+}%
+ }%
+ }%
+ }%
+ }%
+}% \ No newline at end of file