alashworth / test-issue-import

0 stars 0 forks source link

Generated C++ code does not compile when using real literals #84

Open alashworth opened 5 years ago

alashworth commented 5 years ago

Issue by pvdbrand Monday Nov 16, 2015 at 12:56 GMT Originally opened as https://github.com/stan-dev/stan/issues/1690


When I use real (floating point) literals in my Stan model, then the generated C++ code does not compile on my machine. The cause is that my LC_NUMERIC environment variable is set to nl_NL.UTF-8, which makes boost::lexical_cast output floating point numbers with a comma as a decimal separator.

Example: w[1] <- 1.23;

Should compile to: stan::math::assign(get_base1_lhs(w,1,"w",1), 1.23);

But instead it compiles to (note the decimal separator!): stan::math::assign(get_base1_lhs(w,1,"w",1), 1,23.0);

The offending boost::lexical_cast call is in lang/generator.hpp in expression_visgen::operator()(const double_literal& x).

alashworth commented 5 years ago

Comment by syclik Monday Nov 16, 2015 at 13:33 GMT


Thanks for reporting the bug.

What is your LC_NUMERIC environment variable set to? I'll try to replicate that behavior on my machine.

On Nov 16, 2015, at 7:56 AM, pvdbrand notifications@github.com wrote:

When I use real (floating point) literals in my Stan model, then the generated C++ code does not compile on my machine. The cause is that my LC_NUMERIC environment variable is set to nl_NL.UTF-8, which makes boost::lexical_cast output floating point numbers with a comma as a decimal separator.

Example: w[1] <- 1.23;

Should compile to: stan::math::assign(get_base1_lhs(w,1,"w",1), 1.23);

But instead it compiles to (note the decimal separator!): stan::math::assign(get_base1_lhs(w,1,"w",1), 1,23.0);

The offending boost::lexical_cast call is in lang/generator.hpp in expression_visgen::operator()(const double_literal& x).

— Reply to this email directly or view it on GitHub.

alashworth commented 5 years ago

Comment by pvdbrand Monday Nov 16, 2015 at 13:40 GMT


My LC_NUMERIC environment variable is set to nl_NL.UTF-8.

I use Xubuntu. To change the locale I go to Settings -> Language Support -> Regional Formats, then I choose "Nederland" under "Display number, dates, ...". You may need to install another language (Dutch in my case) first. You need to reboot to make the settings take effect. Other flavors of Linux will work similarly I guess.

You can check your current settings by running the command "locale" in a terminal.

Btw, I just changed the settings to en_US.UTF-8 and the model compiles fine.

alashworth commented 5 years ago

Comment by syclik Monday Nov 16, 2015 at 15:27 GMT


Thanks. Sorry about that -- I didn't realize you had provided the LC_NUMERIC variable. I'll try to see if we can disable that through Boost somehow.

On Mon, Nov 16, 2015 at 8:40 AM, pvdbrand notifications@github.com wrote:

My LC_NUMERIC environment variable is set to nl_NL.UTF-8.

I use Xubuntu. To change the locale I go to Settings -> Language Support -> Regional Formats, then I choose "Nederland" under "Display number, dates, ...". You may need to install another language (Dutch in my case) first. You need to reboot to make the settings take effect. Other flavors of Linux will work similarly I guess.

You can check your current settings by running the command "locale" in a terminal.

Btw, I just changed the settings to en_US.UTF-8 and the model compiles fine.

— Reply to this email directly or view it on GitHub https://github.com/stan-dev/stan/issues/1690#issuecomment-157029380.

alashworth commented 5 years ago

Comment by syclik Tuesday Nov 17, 2015 at 23:22 GMT


@mitzimorris, do you know how to deal with converting strings to numbers? We're having some interactions with the LC_NUMERIC environment variable.

alashworth commented 5 years ago

Comment by mitzimorris Wednesday Nov 18, 2015 at 12:51 GMT


I will change the generator code. as noted, the boost::lexical_cast call is the culprit.

I've found several discussions of the problem and proposed workarounds. Will investigate which is appropriate for the stan compiler.

alashworth commented 5 years ago

Comment by syclik Wednesday Nov 18, 2015 at 14:59 GMT


Thanks! I found some of those discussions and they were way over my head.

On Nov 18, 2015, at 7:51 AM, Mitzi Morris notifications@github.com wrote:

I will change the generator code. as noted, the boost::lexical_cast call is the culprit.

I've found several discussions of the problem and proposed workarounds. Will investigate which is appropriate for the stan compiler.

— Reply to this email directly or view it on GitHub.