4 ms·
Cool. Somebody still needs to teach sscanf how to parse floats though. https://github.com/jart/cosmopolitan/issues/456 https://github.com/jart/cosmopolitan/iss
by smcameron 3y ago
Cool. Somebody still needs to teach sscanf how to parse floats though. https://github.com/jart/cosmopolitan/issues/456 https://github.com/jart/cosmopolitan/issues/456
The code to do it would probably go in here: https://github.com/jart/cosmopolitan/blob/master/libc/stdio/vcscanf.c https://github.com/jart/cosmopolitan/blob/master/libc/stdio/...
I mean, I know why it's not done (parsing floats correctly is a lot harder than it would at first seem to be) and I'm not complaining, more like hinting to some of the fine people that haunt this website who might find such a task interesting.
- matheusmoreira 3y agoIs anyone working on this? I'll try it out. I've been reading all I can about floats the past few days in order to add support for them in my language. Perfect opportunity.
- jart 3y agoI'm so happy to hear you're interested in this problem. There's two packages in the Cosmo repo you could depend on for doing this: third_party/double-conversion/ and third_party/gdtoa/. Both libraries are pretty good, but I think double-conversion is the more impressive of the two. It'd be great to see scanf() parse floats with double-conversion if it's possible. One last thing, if any of the non-standardized features of our scanf() implementation get in your way, then I'm not super attached to them and they can be deleted.
- matheusmoreira 3y agoI see. I'll try those libraries out. Was about to try writing my own algorithm despite not having a math background. The libraries will definitely be easier. Cosmopolitan can actually link against those despite being the libc? I'm building my copy of cosmopolitan right now. If I succeed, I'll send you a pull request on GitHub.
- matheusmoreira 3y agoPull request sent. https://github.com/jart/cosmopolitan/pull/924 https://github.com/jart/cosmopolitan/pull/924 Oops, I only now realized there's a test suite. I'll be adding tests too... After I get some sleep.