mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-20 17:40:30 +00:00
Make quality improvements
- Write some more unit tests - memcpy() on ARM is now faster - Address the Musl complex math FIXME comments - Some libm funcs like pow() now support setting errno - Import the latest and greatest math functions from ARM - Use more accurate atan2f() and log1pf() implementations - atoi() and atol() will no longer saturate or clobber errno
This commit is contained in:
parent
af8f2bd19f
commit
592f6ebc20
122 changed files with 6305 additions and 3859 deletions
|
@ -16,34 +16,29 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Decodes decimal integer from ASCII string.
|
||||
* Turns string into long.
|
||||
*
|
||||
* @param s is a non-null nul-terminated string
|
||||
* Decimal is the only radix supported. Leading whitespace (as specified
|
||||
* by the isspace() function) is skipped over. Unlike strtol(), the atoi
|
||||
* function has undefined behavior on error and it never changes `errno`
|
||||
*
|
||||
* @param nptr is a non-null nul-terminated string
|
||||
* @return the decoded signed saturated integer
|
||||
*/
|
||||
long atol(const char *s) {
|
||||
long atol(const char *nptr) {
|
||||
long x;
|
||||
int c, d;
|
||||
do c = *s++;
|
||||
while (c == ' ' || c == '\t');
|
||||
do c = *nptr++;
|
||||
while (isspace(c));
|
||||
d = c == '-' ? -1 : 1;
|
||||
if (c == '-' || c == '+') c = *s++;
|
||||
for (x = 0; isdigit(c); c = *s++) {
|
||||
if (ckd_mul(&x, x, 10) || ckd_add(&x, x, (c - '0') * d)) {
|
||||
errno = ERANGE;
|
||||
if (d > 0) {
|
||||
return LONG_MAX;
|
||||
} else {
|
||||
return LONG_MIN;
|
||||
}
|
||||
}
|
||||
if (c == '-' || c == '+') c = *nptr++;
|
||||
for (x = 0; isdigit(c); c = *nptr++) {
|
||||
x *= 10;
|
||||
x += (c - '0') * d;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue