MikeMirzayanov / testlib

C++ library to develop competitive programming problems
MIT License
1.43k stars 482 forks source link

mingw-w64 sscanf bug #203

Closed petemud closed 2 weeks ago

petemud commented 4 months ago

There is a bug in mingw-w64 implementation of sscanf when reading doubles (see mingw-w64/bugs/989).

sscanf is used to read doubles here: testlib/0.9.41/testlib.h:3562. And testlib is run on Codeforces under mingw-w64.

I'm guessing it's gonna take a while for it to get fixed and pushed through deployment pipelines.

Meanwhile you can detect compilation target with something like #ifdef __MINGW64_VERSION_MAJOR (see Detect mingw thread) and switch to some alternative that doesn't have bugs under minw-w64, such as std::from_chars

After it gets fixed, you can switch back to sscanf on #if __MINGW64_VERSION_[MAJOR|MINOR|BUGFIX] >= fixed_version

MikeMirzayanov commented 2 weeks ago

I don't think guarantees like scanned == val are expected when using scanf-like functions for floating-point numbers.

petemud commented 2 weeks ago

@MikeMirzayanov Is it not expected that scanfed number equals to cined number or one converted with from_chars? You can argue that it's not expected from scanf, but it's definitely expected from testlib. See where this issue was relevant in a contest https://codeforces.com/blog/entry/127855#comment-1151560