logoalt Hacker News

geocar • yesterday at 10:45 AM • 1 reply • view on HN

> Many games and applications store floating point values in text file formats.

And why, pray tell, would those games and applications ship with text files containing floating point values that were invalid?

Certainly if they produce the values, strtod() is sure to work, and worrying about errors at that level just doesn't make any sense at all.

> This has caused bugs in those programs

I'm sorry this just isn't true: The programmer caused the bugs in those programs and nobody else.

Meanwhile users who produce text files with floating point numbers in their locale expect program that load those text files to tolerate their locale, and those programs should not be using strtod()!


Replies

daemin • yesterday at 4:02 PM

The floating point values were valid, they were stored in the text files (unknowingly) in a locale dependent way, either by having a program use a locale sensitive functions to write the values, or because the values were written by hand using the developer's native way of number formatting. The values were then read using the locale dependent functions (like strtod) and if run on a machine with a locale that formatted numbers differently (i.e. using comma for decimal separator) they would return incorrect values.

This caused issues in the game as the values would be significantly different than originally designed, and it would be hard to test for since the people testing the game would usually be using a similar locale to the developer writing the game, and therefore they would only become apparent upon release or wider testing. Now the fix was to explicitly specify the locale before reading the data files, but it still took time to find and implement the fix.

➕ show 1 reply