INIshell-ng

Issue 873: Tinyexpr decimal separator problem

Reported by Michael Reisecker, Feb 8, 2021

I have just noticed something weird:

When building normally, tinyexpr does not recognize a dot as decimal 
separator on my computer.
When building in debug mode (through Qt Creator) it works as 
expected.

Simply calling
printf("%f\n", te_interp("5.2", 0));
will yield "nan", unless in debug mode where it is 5.2.

Error code 5 is returned, but I can't find the documentation for 
it...

The same line works fine as a minimal separate example outside of 
Inishell (it is the 1st example of the documentation┬╣).

I have a German keyboard set, but momentarily switching to English 
and then re-building does not change anything.

[1] https://github.com/codeplea/tinyexpr#short-example

Comment 1 by Mathias Bavay, Feb 19, 2021

On top of my head, I would say this is a locale problem. Depending 
on how you build it, it might end up using a different locale and 
therefore different decimal separator. Maybe we could force 
"C" locale for LC_NUMERIC at start to be sure that the 
generated INIs are all compatible? See 
https://cplusplus.com/reference/clocale/setlocale/ and 
https://en.cppreference.com/w/cpp/locale/LC_categories (and you 
could already in your shell do 'export LC_NUMERIC="C"' 
before recompiling to see if this does the trick... but also 
expecting some trouble until all the locale stuff works!)

Comment 2 by Michael Reisecker, Feb 21, 2021

I have just committed a fix following your suggestion, thank you.

I can't say I fully comprehend it though, it seems to me that 
tinyexpr line 240┬╣ looks for '.' and in the debugger this is what 
appears to be passed to the function - no comma in sight. Is the 
localization then performed in the equality operator??
In any case I also fixed the decimal separator of the Number panel 
to use a dot.

By the way, it did not matter for the INI files (they would always 
have '.'

Closing, but this obviously assumes that all software will strictly 
use '.' - feel free to reopen if we must take more care here.

[1] 
https://models.slf.ch/p/inishell-ng/source/tree/master/lib/tinyexpr.c
#L240
Status: Fixed

Created: 7 months 10 days ago by Michael Reisecker

Updated: 6 months 28 days ago

Status: Fixed

Followed by: 1 person

Labels:
Priority:Medium
Type:Defect