new floating point parser/converter
this version is intended to be fully conformant to the ISO C, POSIX, and IEEE standards for conversion of decimal/hex floating point strings to float, double, and long double (ld64 or ld80 only at present) values. in particular, all results are intended to be rounded correctly according to the current rounding mode. further, this implementation aims to set the floating point underflow, overflow, and inexact flags to reflect the conversion performed. a moderate amount of testing has been performed (by nsz and myself) prior to integration of the code in musl, but it still may have bugs. so far, only strto(d|ld|f) use the new code. scanf integration will be done as a separate commit, and i will add implementations of the wide character functions later.
This commit is contained in:
parent
3be616c1df
commit
415c4cd7fd
5 changed files with 477 additions and 94 deletions
|
|
@ -1,6 +1,15 @@
|
|||
#include <stdlib.h>
|
||||
#include "floatscan.h"
|
||||
#include "stdio_impl.h"
|
||||
|
||||
double strtod(const char *s, char **p)
|
||||
{
|
||||
return strtold(s, p);
|
||||
FILE f = {
|
||||
.buf = (void *)s, .rpos = (void *)s,
|
||||
.rend = (void *)-1, .lock = -1
|
||||
};
|
||||
off_t cnt;
|
||||
double y = __floatscan(&f, -1, 1, 1, &cnt);
|
||||
if (p) *p = (char *)s + cnt;
|
||||
return y;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue