sccn / liblsl

C++ lsl library for multi-modal time-synched data transmission over the local network
Other
108 stars 63 forks source link

Make floating point conversions locale-independent #25

Closed tstenner closed 5 years ago

tstenner commented 5 years ago

Fixes at least https://github.com/sccn/liblsl/issues/24 and https://github.com/sccn/lsl_archived/issues/119.

tstenner commented 5 years ago

Paging @sheinke and @maltesen

sheinke commented 5 years ago

Hi together, thx so much for fixing this :) I owe you guys, would have never suspected locales. Keep up the good work !

tstenner commented 5 years ago

to_string(float) and to_string(double) should remain separate, so that the precision can be set correctly: 8 for float, and 16 for double. You should also use showpoint: http://www.cplusplus.com/reference/ios/showpoint/. This gives output in significant figures (left and right side of the decimal) rather than precision (right side of the decimal).

Done.

template <> double from_string should remain separate from template <> float from_string for a slight performance improvement (less casting).

In a loop the version with casts was about 2% slower. The only case where LSL calls from_string<float> with multiple values is in push_chunk_str with float streams and pull_chunk_f with string streams, both of which will so slow enough already that it doesn't matter.