# Tag Info

2

Here is a solution without using any special package: \newcount\tmpnum \def\definestepfunction#1#2#3{% \def#1##1{\def\sfv{##1}\dostepfunction#2;;\end#3\endgame} } \def\dostepfunction#1;{% \ifdim\sfv pt<#1pt \outofrange \fi \dostepfunctionA#1;% } \def\dostepfunctionA#1;#2;{% \ifx;#2;\outofrange \fi \advance\tmpnum by1 \ifdim\sfv ...

1

Based on the answer given by John Kormylo, and after reading the doc of pgf, I got a more simple solution based on pgfmaths, which is applicable on more general cases. The following program tests in which interval is a value, for the intervals with bounds are (for example) \bzero=0, \bone=1.7, \btwo=2.3, \bthree=5.6. \documentclass{article} ...

1

Just set up suitably the third argument of \definetestfunction, where you can use #1 to refer to the argument passed to \test (or whatever name you choose for the function). \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\definestepfunction}{mmm} { % #1 is the function's name % #2 is the semicolon separated subdivision ...

0

Here is a pgfmath version: \documentclass{article} \usepackage{pgfmath}% part of the tikz package \newcommand{\steps}[1]% #1 = unknown real (text) {\bgroup% local definitions \pgfmathint{#1}% or \pgfmathparse{int(#1)} \let\less=\pgfmathresult \pgfmathparse{int(ceil(#1))} \let\more=\pgfmathresult \$\less \leq #1 \leq \more \Rightarrow #1 \in ...

3

A complementary approach to percusse's answer would be to use the LaTeX3 FPU (this provides an IEEE 754 floating point implementation in an expandable form): \documentclass{article} \usepackage{expl3} \ExplSyntaxOn \cs_new_eq:NN \fpeval \fp_eval:n \ExplSyntaxOff \protected\def\fpset#1#2{\edef#1{\fpeval{#2}}} \begin{document} ...

3

There is a strict limitation in TeX about how big numbers can get which is plus minus 16384. Hence anything going above or anything that comes sufficiently close to zero in the divisor causes overflows. Here exp(-9...) is practically zero for TeX and it is done. Instead you can use more precise calculation engines written for TeX for example FP or TikZ' ...

Top 50 recent answers are included