jk-jeon / dragonbox

Reference implementation of Dragonbox in C++
Apache License 2.0
588 stars 37 forks source link

Source code incomprehensible #40

Closed DanielBaumert closed 1 year ago

DanielBaumert commented 1 year ago

Hello :D

Can you briefly explain why you do these checks? https://github.com/jk-jeon/dragonbox/blob/34a6cdf99d4afe18008877627dabe1f5bf238e1a/source/dragonbox_to_chars.cpp#L80-L82

Alcaro commented 1 year ago

That's a check for whether 0-9 are consecutive in the current character set. 0-9, A-Z and a-z are consecutive in everything ASCII-based, i.e. on pretty much everything, but there are a few older computer systems where they're not. https://en.wikipedia.org/wiki/EBCDIC#Code_page_layout

But the C++ spec demands that 0-9 are consecutive, so it's a rather unnecessary check. https://eel.is/c++draft/lex.charset "The code unit value of each decimal digit character after the digit 0 (U+0030) shall be one greater than the value of the previous." (A-Z and a-z are not required to be consecutive.)

jk-jeon commented 1 year ago

@Alcaro Thanks for the information, it seems I was over-cautious. Let's remove it then.