-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use locale independ way to convert string to double #51
Conversation
I hesitate to pull in an entire new dependency just for this one line. If JSON requires the dot to be used, then stringstreams could be used with an imbued locale in order to ignore the global one. What do you think of that approach? |
I heard that it 3-4 times slower in compare with strtod. |
And I find out that this is not final fix,
yeah, |
This prevents invalid JSON output if locale define different then "." for float/double conversation
setlocale used in similart way as Qt/QApplication does
I fix also sprintf case. Not that after reading code I can say that I did not only fix locale issue, The code before this patch used
after this |
|
Let me know what you think of #53 |
I find out about this function from reading something like native_c4database.cc from couchbase-lite-java , and I used it a lot in in my Rust wrapper around couchbase-lite-core. Though have no idea that this is not frequently used function, but I don't see alternative for saving JSON directly.
But why? According to google developers 17 characters enough to encode any number (see kBase10MaximalLength constant in double-conversation code). And it is really inconvenient, you see JSON encoding/decoding function is generated from language types, obviously I can mark any field with float/double to use special function that encode/decode them to stirng, but it is a lot of manual work, and what if I forget to mark field as such? Plus I want to share this data with somebody who use other language (frontend), it will be inconvenient to document every field like - it is really number, but I save it as string, |
Well there is no alternative for saving JSON directly because that's not what we do in Couchbase Lite. We turn domain objects (C# classes, etc) into Fleece by using I don't remember hearing about the Rust wrapper before, that's pretty neat! @snej What are your thoughts on this? |
The replicator encodes documents into JSON when pushing. So JSON-generation issues are definitely important to Couchbase Lite. |
[multiply edited] What about using The (macOS) man page for
We can just put that in a static variable for use in Fleece. |
Found this in a post on the lua mailing list:
I'm working on a fix using that. |
Comparing floating point numbers for equality before and after some transformation is always a problem, because of roundoff. I've had to explain to testers many times that they can't write assertions that compare floats for equality. This is especially bad with 32-bit floats. I don't think anyone who cares about accuracy is going to choose those over 64-bit, when you get fewer than 7 significant [decimal] digits. I came up with the |
In this particular case I suppose that comparing is the only and right way to test equality. You see one thing that you calculate something, obviously For example you have JSON document with two properties If you store and load the same bits representation you can be sure that you have no problem at all. I am not sure that after several cycles for save/load |
Closing in favor of #56 (Thanks for getting us to address the issue though!) |
Actually it isn't; I just checked the C reference docs: "isdigit and isxdigit are the only standard narrow character classification functions that are not affected by the currently installed C locale." Although you may be referring to this: "...although some implementations (e.g. Microsoft in 1252 codepage) may classify additional single-byte characters as digits." I checked |
I tried this yesterday [on macOS] and the speedup was very small. I guess Clang's (Apple's?) |
Related to couchbase/couchbase-lite-core#849 , should fix issue.
Plus this change should speedup json parsing, because of according to dropbox/json11#38 (comment) when I replace in dropbox json library call strtod with google/double-conversation I see speedup in benchmark from 51ms to 40ms.
Though there is
isdigit
in vendor/jsonsl/jsonsl.c .isdigit
locale dependent function also.But this is related to other repository. I should note that I expect that replacing isidigit should also speedup things, because of most compilers can not inline isdigit, so check
if (ch >= '0' && ch <= '9')
is faster.