LaTeX forum ⇒ Math & Sciencenumerical conditions Topic is solved

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Posts: 39
Joined: Thu Oct 20, 2016 3:41 pm

numerical conditions

Postby kent » Sat Sep 09, 2017 2:06 pm

I often should have liked to be able to test for numerical conditions in my PGF macros.
Let me illustrate with one simple example:
Let A and B be two given poinst where we have access to their coordinates, say A = (\xA,\yA) and B = (\xB,\yB).
I would then like to be able to check if A = B within some tolerance.
But how should I test to see, say, for \dx = \xB-\xA that abs(\dx) < \eps for a small defined value of \eps (i.e 0.0005)?
As far as I know the Latex \ifthenelse cannot be used.
Kent Holing, NORWAY

Posts: 204
Joined: Thu Dec 04, 2008 4:39 am

Postby mas » Sun Sep 10, 2017 3:41 am

Looking at the pgf manual, Section 90, you can see that there is a pgfmath library which has commands to do what you need. I am just pasting below from the manual (page 939):
Comparison and logical functions
In addition to the commands described in Section 89.3.5, the following command was provided by Christian
Defines \pgfmathresult 1.0 if |<x>−<y>|< 0.0001, but 0.0 otherwise. As a side-effect, the global boolean
\ifpgfmathcomparison will be set accordingly.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

Posts: 39
Joined: Thu Oct 20, 2016 3:41 pm

Postby kent » Tue Sep 12, 2017 2:33 pm

Thanks, I see I need to upgrade the PGF version I am using or could anybody supply the code needed/mentioned?

User avatar
Stefan Kottwitz
Site Admin
Posts: 8602
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany

Postby Stefan Kottwitz » Tue Sep 12, 2017 11:20 pm

Hi Kent!

It's probably good to update in any case. I remember you worked on an intersection topic, that also was solvable with PGF 3 aka TikZ 3. It provides a lot more features than PGF 2. Otherwise you may re-program already existing new features.

You may consider to update the whole TeX installation. LaTeX evolves, new features, packages, and bug fixes appear.

Site admin

Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 5 guests