Last edit
\documentclass[twoside,12pt]{article}
\makeatletter
\ifnum\f@size=12
\if@twoside
\usepackage{tikz}
\fi
\fi
\makeatother
\begin{document}
\begin{tikzpicture}
\node at (0,0) {Package loaded for 12 pt and twosided document. In other cases the compilation will fail!};
\end{tikzpicture}
\end{document}
After OP's edit a simple way since documentclass accepts only integers for fontsize
\documentclass[12pt]{article}
\makeatletter
\ifnum\f@size=12
\usepackage{tikz}
\fi
\makeatother
\begin{document}
\begin{tikzpicture}
\node at (0,0) {Package loaded for 12 pt!};
\end{tikzpicture}
\end{document}
Dimensions are real numbers and thus you have to consider check for less and greater than because not all decimal numbers can represented as binary numbers:
Here is how you can do your calculations:
\documentclass[12pt]{article}
\usepackage{anyfontsize}
\makeatletter
\newlength{\mysize}
\newlength{\testSize}
\setlength{\testSize}{12pt}
\setlength{\mysize}{\f@size pt}
\makeatother
% [how to set if@myxiipt ???]
\makeatletter
\newcommand{\testTS}[1]{
\ifnum #1=0
\ifdim\mysize>\dimexpr0.999\testSize\relax
\ifdim\mysize<\dimexpr1.001\testSize\relax
Class loaded with 12pt option
\else
Class loaded without 12pt option
\fi
\else
Class loaded without 12pt option
\fi
\else
\xdef\mycursize{\f@size pt}
\ifdim\mycursize>\dimexpr0.999\testSize\relax
\ifdim\mycursize<\dimexpr1.001\testSize\relax
This is 12pt text.
\else
This is not 12pt text.
\fi
\else
This is not 12pt text.
\fi
\fi
}
\makeatother
\begin{document}
\testTS{0}
\testTS{1}
\fontsize{11.97}{14}\selectfont
\testTS{0}
\testTS{1}
\end{document}
\f@size(without thept, i.e. in this case only12). – Henri Menke Sep 23 '17 at 01:15