4

I continue to test the transition from fp to xfp. The results are good but two macros resist: \FPifint and\FPClip. I did not find how to replace them in xfp. I have numbers (decimal numbers [+,-,0,...,9 and "."] only). I want to know if a number is an integer but with the first condition (there is a second ...) :

1.0 , 15.00 etc .. are integers

\FPifint works like this. I found some solutions but not entirely satisfactory and I prefer to avoid loading another package.

  1. biblatex with \ifinteger (not test)
  2. xstring with \IsInteger (I don't need all the stuff)
  3. Memoir with \checkifinteger(wrong solution)
  4. lua with lua_isinteger (not test)

I tried to find a personal solution :

% !TEX TS-program = lualatex-dev

\documentclass{article}
\usepackage{xfp,pgffor} 
 %xfp because i wanted to use \fpeval for some tests
\newif\ifinteger

\makeatletter
\def\removedot#1.{#1}
\newcommand\getinteger[1]{\expandafter\@getinteger#1.\@nil}
\def\@getinteger#1.#2\@nil{%
  \ifx\empty#2\empty
    \integertrue
    \else
    \ifnum\removedot#2=0   
        \integertrue
     \else 
       \integerfalse
     \fi
  \fi
}

\parindent=0pt

\begin{document}
\foreach \value in {+1 ,-1.00,0.75,10000,0.9998}{
\getinteger{\value}
\ifinteger
\value{} is considered an integer
\else
\value{} is not considered  an integer
\fi
\\}

\end{document}

Firstly I'm not sure if my code is correct and I would like to know how to translate this with expl3 (or perhaps the macro comes with xfp ?)

I'm also looking for a macro to remove all unnecessary zeros from a decimal like FPClip

There is another condition: I would like to accept as integers, decimal numbers ending for example with 999. Thus 1.999 or .999 will be considered as decimal. With my code the idea was to test # 2 but I did not find a satisfactory method

enter image description here

3
  • you can test if round(#1)=#1 or given your final note check that abs(round(#1)-#1)<.001 Jan 5, 2020 at 17:46
  • How you write the test with xfp. I don't know the syntax .. There is no example in the doc. Jan 5, 2020 at 18:08
  • 1
    we are working on the doc but texdoc interface3 then look at the l3fp chapter shows the syntax, I'll post something here. Jan 5, 2020 at 18:09

1 Answer 1

6

You could just use fpeval and a latex2e test but I use an expl3 conditional here

enter image description here

\documentclass{article}

\usepackage{xfp}

\ExplSyntaxOn
\newcommand\test[1]{
\fp_compare:nTF{0.01 < abs(round(#1)-#1)}
}
\ExplSyntaxOff
\begin{document}


10 \test{10}{no}{yes}


9.99 \test{9.99}{no}{yes}

1.2 \test{1.2}{no}{yes}

\end{document}
3
  • It's on my todo list : learn how to use expl3. Thanks it's the beginning of a great learning Jan 5, 2020 at 18:43
  • Is it a problem in a package to mix latex2e and expl3 ? Jan 5, 2020 at 18:54
  • 3
    @AlainMatthes that is the exact purpose of expl3, to make the l3 programming layer available in 2e documents and packages Jan 5, 2020 at 18:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .