%%
%% This is file `datatool-pgfmath.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% datatool.dtx  (with options: `datatool-pgfmath.def,package')
%% 
%%  datatool.dtx
%%  Copyright 2025 Nicola Talbot
%% 
%%  This work may be distributed and/or modified under the
%%  conditions of the LaTeX Project Public License, either version 1.3
%%  of this license or (at your option) any later version.
%%  The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%%  and version 1.3 or later is part of all distributions of LaTeX
%%  version 2005/12/01 or later.
%% 
%%  This work has the LPPL maintenance status `maintained'.
%% 
%%  The Current Maintainer of this work is Nicola Talbot.
%% 
%%  This work consists of the files datatool.dtx and datatool.ins and the derived files datatool-base.sty, datatool-undetermined.ldf, datatool-latin1.ldf, datatool-utf8.ldf, datatool-l3fp.def, datatool-lua.def, datatool-fp.def, datatool-fp.sty, datatool-pgfmath.def, datatool-pgfmath.sty, datatool.sty, datagidx.sty, databib.sty, databar.sty, datapie.sty, dataplot.sty, person.sty, databib.bst, databar-2019-09-27.sty, databib-2019-09-27.sty, datagidx-2019-09-27.sty, datapie-2019-09-27.sty, dataplot-2019-09-27.sty, datatool-2019-09-27.sty, datatool-base-2019-09-27.sty, datatool-fp-2019-09-27.sty, datatool-pgfmath-2019-09-27.sty, person-2019-09-27.sty.
%% 
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{datatool-pgfmath.def}[2025/12/04 v3.4.3 (NLCT)]
\RequirePackage{pgfrcs,pgfkeys,pgfmath}
\ExplSyntaxOn
\NewDocumentCommand \dtlifnumeq { m m m m }
{
  \def\@dtl@truepart{#3}%
  \def\@dtl@falsepart{#4}%
  \exp_args:Nx \pgfmathifthenelse {#1==#2}%
    {"\exp_not:N \@dtl@truepart"}{"\exp_not:N \@dtl@falsepart"}%
  \pgfmathresult
}
\NewDocumentCommand \dtlifnumlt { m m m m }
{
  \def\@dtl@truepart{#3}%
  \def\@dtl@falsepart{#4}%
  \exp_args:Nx \pgfmathifthenelse {#1 < #2}%
    {"\exp_not:N \@dtl@truepart"}{"\exp_not:N \@dtl@falsepart"}%
  \pgfmathresult
}
\NewDocumentCommand \dtlifnumgt { m m m m }
{
  \def\@dtl@truepart{#3}%
  \def\@dtl@falsepart{#4}%
  \exp_args:Nx \pgfmathifthenelse {#1 > #2}%
    {"\exp_not:N \@dtl@truepart"}{"\exp_not:N \@dtl@falsepart"}%
  \pgfmathresult
}
\NewDocumentCommand \dtlifnumopenbetween { m m m m m }
{
  \dtlifnumlt { #1 } { #3 }
  { \dtlifnumgt { #1 } { #2 } { #4 } { #5 } }
  { #5 }
}
\NewDocumentCommand \dtlifnumclosedbetween { m m m m m }
{
  \dtlifnumlt { #1 } { #2 }
  { #5 }
  { \dtlifnumgt { #1 } { #3 } { #5 } { #4 } }
}
\NewDocumentCommand \dtladd { m m m }
{
  \pgfmathadd{#2}{#3}%
  \let#1\pgfmathresult
}
\NewDocumentCommand \dtladdall { m m }
{
  \tl_set:Nn \pgfmathresult { 0 }
  \exp_args:No \clist_map_inline:nn { #2 }
  {
    \pgfmathadd { \pgfmathresult } { ##1 }
  }
  \tl_set_eq:NN #1 \pgfmathresult
}
\NewDocumentCommand \dtlsub { m m m }
{
  \pgfmathsubtract{#2}{#3}%
  \let#1\pgfmathresult
}
\NewDocumentCommand \dtlmul { m m m }
{%
  \pgfmathmultiply{#2}{#3}%
  \let#1\pgfmathresult
}
\NewDocumentCommand \dtldiv { m m m }
{%
  \pgfmathdivide{#2}{#3}%
  \let#1\pgfmathresult
}
\NewDocumentCommand \dtlsqrt { m m }
{%
  \pgfmathsqrt{#2}%
  \let#1\pgfmathresult
}
\NewDocumentCommand \dtlroot { m m m }
{
  \exp_args:Nx \tl_if_eq:nnTF { #3 } { 2 }
  {
    \exp_args:Nx \pgfmathsqrt { #2 }
    \let#1\pgfmathresult
  }
  {
    \exp_args:Nxx \pgfmathpow { #2 } { 1 / ( #3 ) }
    \let#1\pgfmathresult
  }
}
\NewDocumentCommand{\dtlround}{mmm}{%
  \ifnum#3=0\relax
    \exp_args:Nx \pgfmathparse { int( round ( #2 ) ) }
    \let#1\pgfmathresult
  \else
    \exp_args:Nx \pgfmathparse { int ( 10 \exp_not:N ^ #3 )}
    \let\dtl@tmpshift\pgfmathresult
    \exp_args:Nx \pgfmathparse { int ( floor ( #2 ) ) }%
    \let\dtl@int@round\pgfmathresult
    \exp_args:Nx \pgfmathparse
      { int ( round ( ( #2 - \dtl@int@round ) * \dtl@tmpshift ) ) }
    \@dtl@tmpcount=0\relax
    \expandafter\@dtl@countdigits\pgfmathresult.\relax
    \advance\@dtl@tmpcount by -#3\relax
    \def\@dtl@intpart{}%
    \def\@dtl@fracpart{}%
    \expandafter\@dtl@gatherintfrac\pgfmathresult\relax
    \tl_if_empty:NT \@dtl@intpart { \tl_set:Nn \@dtl@intpart { 0 } }
    \edef\@dtl@intpart{\number\numexpr\dtl@int@round + \@dtl@intpart}%
    \edef#1{\@dtl@intpart.\@dtl@fracpart}%
  \fi
}
\newcommand*{\@dtl@gatherintfrac}[1]{%
  \ifx\relax#1\relax
  \else
    \advance\@dtl@tmpcount by -1\relax
    \ifnum\@dtl@tmpcount<0\relax
      \edef\@dtl@fracpart{\@dtl@fracpart#1}%
    \else
      \edef\@dtl@intpart{\@dtl@intpart#1}%
    \fi
    \expandafter\@dtl@gatherintfrac
  \fi
}
\NewDocumentCommand \dtltrunc { m m m }
{
  \ifnum#3=0\relax
    \exp_args:Nx \pgfmathparse { int ( floor ( #2 ) ) }%
    \let#1\pgfmathresult
  \else
    \exp_args:Nx \pgfmathparse { int ( 10 \exp_not:N ^ #3 ) }
    \let\dtl@tmpshift\pgfmathresult
    \exp_args:Nx \pgfmathparse { int ( floor ( #2 ) ) }
    \let\dtl@int@trunc\pgfmathresult
    \exp_args:Nx \pgfmathparse
     { int ( floor ( ( #2 - \dtl@int@trunc ) * \dtl@tmpshift ) ) }
    \@dtl@tmpcount=0\relax
    \expandafter\@dtl@countdigits\pgfmathresult.\relax
    \advance\@dtl@tmpcount by -#3\relax
    \def\@dtl@intpart{}%
    \def\@dtl@fracpart{}%
    \expandafter\@dtl@gatherintfrac\pgfmathresult\relax
    \tl_if_empty:NT \@dtl@intpart { \tl_set:Nn \@dtl@intpart { 0 } }
    \edef\@dtl@intpart{\number\numexpr\dtl@int@trunc
      + \@dtl@intpart}%
    \edef#1{\@dtl@intpart.\@dtl@fracpart}%
  \fi
}
\NewDocumentCommand \dtlclip { m m }
{
  \fp_set:Nn { \l__datatool_tmpa_fp } { #2 }
  \tl_set:Nx #1 { \fp_use:N { \l__datatool_tmpa_fp } }
}
\NewDocumentCommand \dtlmin { m m m }
{
  \exp_args:Nxx \pgfmathmin { #2 } { #3 }
  \let#1\pgfmathresult
}
\NewDocumentCommand \dtlminall { m m }
{
  \exp_args:Nx \pgfmathmin { #2 } { }
  \let#1\pgfmathresult
}
\NewDocumentCommand \dtlmax { m m m }
{
  \exp_args:Nx \pgfmathmax { #2 } { #3 }
  \let#1\pgfmathresult
}
\NewDocumentCommand \dtlmaxall { m m }
{
  \exp_args:Nx \pgfmathmax { #2 } { }
  \let#1\pgfmathresult
}
\NewDocumentCommand \dtlabs { m m }
{
  \exp_args:Nx \pgfmathabs { #2 }
  \let#1\pgfmathresult
}
\NewDocumentCommand \dtlneg { m m }
{
  \exp_args:Nx \pgfmathneg { #2 }
  \let#1\pgfmathresult
}
\NewDocumentCommand \dtlmeanforall { m m }
{
  \tl_set:Nn \pgfmathresult { 0 }
  \int_zero:N \l__datatool_count_int
  \exp_args:No \clist_map_inline:nn { #2 }
  {
    \int_incr:N \l__datatool_count_int
    \exp_args:Nxx \pgfmathadd { \pgfmathresult } { ##1 }
  }
  \exp_args:Nxx \pgfmathdivide
    { \pgfmathresult }
    { \int_use:N \l__datatool_count_int }
  \tl_set_eq:NN #1 \pgfmathresult
}
\NewDocumentCommand {\dtlvarianceforall} { o m m }
{%
  \IfNoValueTF { #1 }
  {
    \tl_set:Nn \pgfmathresult { 0 }
    \int_zero:N \l__datatool_count_int
    \exp_args:No \clist_map_inline:nn { #3 }
    {
      \int_incr:N \l__datatool_count_int
      \exp_args:Nxx \pgfmathadd { \pgfmathresult } { ##1 }
    }
    \exp_args:Nxx \pgfmathdivide
      { \pgfmathresult }
      { \int_use:N \l__datatool_count_int }
    \tl_set_eq:NN \@dtl@mean \pgfmathresult
    \tl_set:Nn #2 { 0 }
    \exp_args:No \clist_map_inline:nn { #3 }
    {
      \exp_args:Nxx \pgfmathsubtract { ##1 } { \@dtl@mean }
      \exp_args:Nxx \pgfmathmultiply { \pgfmathresult } { \pgfmathresult }
      \exp_args:Nxx \pgfmathadd { #2 } { \pgfmathresult }
      \tl_set_eq:NN #2 \pgfmathresult
    }
  }
  {
    \tl_set:Nx \@dtl@mean { #1 }
    \int_zero:N \l__datatool_count_int
    \tl_set:Nn #2 { 0 }
    \exp_args:No \clist_map_inline:nn { #3 }
    {
      \int_incr:N \l__datatool_count_int
      \exp_args:Nxx \pgfmathsubtract { ##1 } { \@dtl@mean }
      \exp_args:Nxx \pgfmathmultiply
       { \pgfmathresult } { \pgfmathresult }
      \exp_args:Nxx \pgfmathadd { #2 } { \pgfmathresult }
      \tl_set_eq:NN #2 \pgfmathresult
    }
  }
  \exp_args:Nxx \pgfmathdivide
    { #2 }
    { \int_use:N \l__datatool_count_int }
  \tl_set_eq:NN #2 \pgfmathresult
}
\NewDocumentCommand{\dtlsdforall} { o m m }
{%
  \IfNoValueTF{#1}%
  {%
    \tl_set:Nn \pgfmathresult { 0 }
    \int_zero:N \l__datatool_count_int
    \exp_args:No \clist_map_inline:nn { #3 }
    {
      \int_incr:N \l__datatool_count_int
      \exp_args:Nxx \pgfmathadd { \pgfmathresult } { ##1 }
    }
    \exp_args:Nxx \pgfmathdivide
      { \pgfmathresult }
      { \int_use:N \l__datatool_count_int }
    \tl_set_eq:NN \@dtl@mean \pgfmathresult
    \tl_set:Nn #2 { 0 }
    \exp_args:No \clist_map_inline:nn { #3 }
    {
      \exp_args:Nxx \pgfmathsubtract { ##1 } { \@dtl@mean }
      \exp_args:Nxx \pgfmathmultiply { \pgfmathresult } { \pgfmathresult }
      \exp_args:Nxx \pgfmathadd { #2 } { \pgfmathresult }
      \tl_set_eq:NN #2 \pgfmathresult
    }
  }
  {
    \tl_set:Nn \@dtl@mean { #1 }
    \int_zero:N \l__datatool_count_int
    \tl_set:Nn #2 { 0 }
    \exp_args:No \clist_map_inline:nn { #3 }
    {
      \int_incr:N \l__datatool_count_int
      \exp_args:Nxx \pgfmathsubtract { ##1 } { \@dtl@mean }
      \exp_args:Nxx \pgfmathmultiply
        { \pgfmathresult } { \pgfmathresult }
      \exp_args:Nxx \pgfmathadd { #2 } { \pgfmathresult }
      \tl_set_eq:NN #2 \pgfmathresult
    }
  }
  \exp_args:Nxx \pgfmathdivide
     { #2 } { \int_use:N \l__datatool_count_int }
  \exp_args:Nx \pgfmathsqrt { \pgfmathresult }
  \tl_set_eq:NN #2 \pgfmathresult
}
\ExplSyntaxOff
\endinput
%%
%% End of file `datatool-pgfmath.def'.
