Skip to content
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

new c lib: scanf of floats %aefg unsupported #51

Open
aralbrec opened this issue Jan 30, 2017 · 2 comments
Open

new c lib: scanf of floats %aefg unsupported #51

aralbrec opened this issue Jan 30, 2017 · 2 comments

Comments

@aralbrec
Copy link
Member

aralbrec commented Jan 30, 2017

In the new c lib you can printf floats but you can't scanf them. The recommended workaround is to first scan as a string using %s or %[ and then use strtod() or atof() to do the float conversion.

What is missing is a state machine in the stdio library that examines an incoming char stream and decides where a float ends. This is complicated by the fact that floats can take on a number of forms:

  • 123
  • 123.
  • .
  • .123
  • 123.123
  • variations with exponent e
  • hex floats 0xabc.123P-28
  • special strings "nan", "infinity" etc
@suborb
Copy link
Member

suborb commented Jan 30, 2017

There's code that handles the common cases in the classic library - we read from the file and put it into a temporary buffer on the stack which atof() then parses. It's in libsrc/stdio/__scanf_handle_f.asm

It follows the 99% rule so would need extension for the new library, but could be a quick win whilst you work on full c99 compatibility.

@aralbrec
Copy link
Member Author

Yes maybe a temporary partial solution is ok. The underlying implementation of strtod/atof in the new c lib can do all the float formats listed above so it just needs a buffer to act on that is gathered by scanf. But maybe a %f only solution can be implemented for the decimal float case so that a simple state machine can be employed.

@suborb suborb added newlib and removed newlib labels Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants