Bug 429110 - "atan2" function doesn't work as expected
Summary: "atan2" function doesn't work as expected
Status: RESOLVED FIXED
Alias: None
Product: LabPlot2
Classification: Applications
Component: frontend (show other bugs)
Version: 2.8.1
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Stefan Gerlach
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-14 19:30 UTC by Orestes Mas
Modified: 2020-11-21 18:06 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 2.8.2
Sentry Crash Report:


Attachments
Video showing the bug (1.45 MB, video/mp4)
2020-11-17 23:22 UTC, Orestes Mas
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Orestes Mas 2020-11-14 19:30:42 UTC
SUMMARY

The "atan2" function does not yeld the expected values


STEPS TO REPRODUCE
1. Create new project -> Add a worksheet -> Add an xy-plot -> Add a new xy-curve from a mathematical equation.
2. As equation, type: "180*atan(1)/pi" and press "recalculate" button.
3. Should appear a stright line plot of value 45 as arctan(1)=45 degrees.
4. Now change the equation to "180*atan2(1,1)/pi", and press "recalculate" again. The plot should not change, as the "atan2" function is supposed to be defined as "atan2(Y,X) = atan(Y/X)" but being quadrant-aware. Instead, a straight-line plot of 90 degrees appears, which is erroneous.


OBSERVED RESULT
A value of 90 degrees


EXPECTED RESULT
A value of 45 degrees


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 5.14.5
KDE Frameworks Version: 5.54.0
Qt Version: 5.11.3

ADDITIONAL INFORMATION
Labplot2 v2.8.1 compiled from source (git commit d0573f64a0)
Comment 1 Stefan Gerlach 2020-11-15 13:54:57 UTC
I can not reproduce the problem. Compiling 2.8.1 on Debian 10 stable and using
180*atan2(1,1)/pi gives me 45, as expected.
Can you try again and make a screenshot to see a possible problem?
Comment 2 Orestes Mas 2020-11-17 23:22:08 UTC
Created attachment 133417 [details]
Video showing the bug
Comment 3 Orestes Mas 2020-11-17 23:24:01 UTC
(In reply to Stefan Gerlach from comment #1)
> I can not reproduce the problem. Compiling 2.8.1 on Debian 10 stable and
> using
> 180*atan2(1,1)/pi gives me 45, as expected.
> Can you try again and make a screenshot to see a possible problem?


Ok, I think you and me are both right. It seems a locale problem: my default system locale is catalan, which has the comma as a decimal separator by default.
If I start Labplot with an english locale (like yours, perhaps?), the atan2 function works as expected.

Please see the attached video, where the problem is shown and also shows other related issues: if either argument of the atan2 function is a floating point number, the only accepted decimal separator is a comma, which is indistinguishable from the separator between the two «atan2» arguments. This confuses the parser and leads to funny results.

Perhaps other character (like the semicolon, for instance) should be used as functions' argument separator when the system locale uses the comma as a decimal separator. I've seen that in other languages...
Comment 4 Stefan Gerlach 2020-11-21 17:54:27 UTC
Git commit 443fbde0057f2d34df13b154c260505180b39fed by Stefan Gerlach.
Committed on 21/11/2020 at 17:51.
Pushed by sgerlach into branch 'master'.

Support semicolon as function argument separator in parser to improve support for locale with comma decimal separator
FIXED-IN: 2.8.2

M  +3    -0    ChangeLog
M  +3    -0    src/backend/gsl/parser.y

https://invent.kde.org/education/labplot/commit/443fbde0057f2d34df13b154c260505180b39fed
Comment 5 Stefan Gerlach 2020-11-21 18:06:16 UTC
The parser now supports a semicolon as function argument separator for locale that have a comma already as decimal separator. A comma is still supported for these locale since some expressions (that may be used before) work with it.