[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-glpk] str2num() is locale dependent
From: |
xypron |
Subject: |
[Bug-glpk] str2num() is locale dependent |
Date: |
Sat, 23 May 2009 13:07:58 -0700 (PDT) |
Hello Andrew,
I tried to call the GLPK library from Java under Debian.
I received the following error:
transp.mod:58: d requires numeric data
Context: ...peka 275 ; param d : New-York Chicago Topeka := Seattle 2.51
The problem could be traced back to
val = strtod("2,1", &endptr);
printf("strtod('2,1') = %f\n", val);
val = strtod("2.1", &endptr);
printf("strtod('2.1') = %f\n", val);
printing
strtod('2,1') = 2,100000
strtod('2.1') = 2,000000
strtod is locale-dependent.
In Germany ',' is the decimal separator.
I found the following description on the net:
The radix character is defined in the program's locale (category
LC_NUMERIC).
In the POSIX locale, or in a locale where the radix character is not
defined,
the radix character defaults to a period ('.').
I guess the GLPK library should work whatever locale the main program is
using.
Could you, please, fix function
int str2num(const char *str, double *_val)
in glplib11.c not to be locale dependent.
The following code could do the trick:
#include <locale.h>
...
struct lconv * lc;
lc = localeconv();
setlocale ( LC_NUMERIC, 'C');
...
setlocale ( LC_NUMERIC, lc->decimal_point);
Best regards
Xypron
--
View this message in context:
http://www.nabble.com/str2num%28%29-is-locale-dependent-tp23687810p23687810.html
Sent from the Gnu - GLPK - Bugs mailing list archive at Nabble.com.
- [Bug-glpk] str2num() is locale dependent,
xypron <=