NatLabRockies / NatLabRockies/OpenStudio

std::stod conversions are locale dependent (EpwFile)

Open
#3,700 0 comments 0 reactions 1 assignee View on GitHub

@tanushree04 is already working on this.

Since Jul 20, 2020.

severity - Normal Bug
Dominant language
C++
Stars
646
Forks
237
Avg merge
3d 11h
Merged PRs (30d)
10

Description

On a VM I have a locale with LC_NUMERIC=fr_FR.UTF-8 (full locale below). This means the thousand separator is . and the decimal one is ,, so basically the opposite of the US.

This test fails as a result

$ ctest -VV -R "RubyTest-EpwFile_Test-file"

The assertion that fails is here:

https://github.com/NREL/OpenStudio/blob/0ff2827ee6664cca0b440afd1fa3ee87b1480e6c/openstudiocore/ruby/test/EpwFile_Test.rb#L51

the string "39.74" ends up converted as 39.0 because of the locale.

The std::stod calls that doesn't handle the decimal portion correctly is here, and it's called with std::string latitude = "39.74".

https://github.com/NREL/OpenStudio/blob/0ff2827ee6664cca0b440afd1fa3ee87b1480e6c/openstudiocore/src/utilities/filetypes/EpwFile.cpp#L4457


Locale

$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=fr_FR.UTF-8
LC_TIME=fr_FR.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=fr_FR.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=fr_FR.UTF-8
LC_NAME=fr_FR.UTF-8
LC_ADDRESS=fr_FR.UTF-8
LC_TELEPHONE=fr_FR.UTF-8
LC_MEASUREMENT=fr_FR.UTF-8
LC_IDENTIFICATION=fr_FR.UTF-8
LC_ALL=

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.