Precision argument for float string formatting#242
Precision argument for float string formatting#242JakeHagen wants to merge 1 commit intosgkit-dev:mainfrom
Conversation
|
This looks great, thanks @JakeHagen! The "glue" side of this is a bit tricky, and I'm happy to step in to sort that out. I think the main thing required now is some thorough testing of ftoa itself. This would be done here. There's a lot of corner cases to consider I'm afraid. What might be a useful thing to do is to use you python implementation to compare with the equivalent string generated by Python's fixed precision formatting of numbers for a range of values, and then choose some representative cases from that to generate the C test cases. This is a fundamental function, so we do want to make sure we've got all the bases covered. Regarding your more sophisticated proposal above - I'd rather keep things simple for now and make sure that the semantics we have are well defined and in-line with other implementations (so we can say "a precision of 5 e.g. is equivalent to f"{x:.5f}" in Python"). I don't think there's much point in trying to save a few zeros in the output as vcztools s primarily going to be used to generate input for other programs, where the size isn't all that important (and float cols that need more than 3 decimals of precision are rare anyway). |
This function works when the precision value is hardcoded but I am having trouble getting the precision argument from python to the c function. I also added a python implementation and tests that I will remove if this gets pulled.
While writing this I started thinking there might be better way. What if the function only added precision when it would round the decimals down to zero using only three decimals. I think the below function would accomplish something like that. It can probably be further optimized to only do extra work when needed.