|
|
| version 1.5, 2026/01/07 13:40:02 | version 1.6, 2026/01/07 14:19:45 |
|---|---|
| Line 144 int pa_atoi(const char* str, int base, c | Line 144 int pa_atoi(const char* str, int base, c |
| } | } |
| if(negative){ | if(negative){ |
| const uint min_abs = (uint)(-( (uint)INT_MIN + 1 )) + 1; | const uint min_abs = (uint)0 - (uint)INT_MIN; |
| uint result=pa_ato_any<uint>(str, base, problem_source, min_abs); | uint result=pa_ato_any<uint>(str, base, problem_source, min_abs); |
| if(result==min_abs) return INT_MIN; | if(result==min_abs) return INT_MIN; |
| return -(int)result; | return -(int)result; |
| Line 177 pa_wint pa_atowi(const char* str, int ba | Line 177 pa_wint pa_atowi(const char* str, int ba |
| } | } |
| if(negative){ | if(negative){ |
| const pa_uwint min_abs = (pa_uwint)(-( (pa_wint)PA_WINT_MIN + 1 )) + 1; | const pa_uwint min_abs = (pa_uwint)0 - (pa_wint)PA_WINT_MIN; |
| pa_uwint result=pa_ato_any<pa_uwint>(str, base, problem_source, min_abs); | pa_uwint result=pa_ato_any<pa_uwint>(str, base, problem_source, min_abs); |
| if(result==min_abs) return PA_WINT_MIN; | if(result==min_abs) return PA_WINT_MIN; |
| return -(pa_wint)result; | return -(pa_wint)result; |
| Line 234 double pa_atod(const char* str, const St | Line 234 double pa_atod(const char* str, const St |
| // format: %[flags][width][.precision]type https://msdn.microsoft.com/ru-ru/library/56e442dc(en-us,VS.80).aspx | // format: %[flags][width][.precision]type https://msdn.microsoft.com/ru-ru/library/56e442dc(en-us,VS.80).aspx |
| // flags: '-', '+', ' ', '#', '0' https://msdn.microsoft.com/ru-ru/library/8aky45ct(en-us,VS.80).aspx | // flags: '-', '+', ' ', '#', '0' https://msdn.microsoft.com/ru-ru/library/8aky45ct(en-us,VS.80).aspx |
| // width, precision: non negative decimal number | // width, precision: non negative decimal number |
| #define MAX_FORMAT_LEN 10 // %+0XX.XXg\0 | |
| enum FormatType { | enum FormatType { |
| FormatInvalid, | FormatInvalid, |
| FormatInt, | FormatInt, |
| Line 292 FormatType format_type(const char* fmt){ | Line 295 FormatType format_type(const char* fmt){ |
| return FormatInvalid; // no chars allowed after 'type' | return FormatInvalid; // no chars allowed after 'type' |
| } | } |
| } | } |
| return result; | return pos-fmt > MAX_FORMAT_LEN ? FormatInvalid : result; |
| } | } |
| #ifdef PA_WIDE_INT | #ifdef PA_WIDE_INT |
| Line 329 const char* format_double(double value, | Line 332 const char* format_double(double value, |
| case FormatUInt: | case FormatUInt: |
| if(value >= 0){ // on Apple M1 (uint)<negative value> is 0 | if(value >= 0){ // on Apple M1 (uint)<negative value> is 0 |
| #ifdef PA_WIDE_INT | #ifdef PA_WIDE_INT |
| char fmt_buf[strlen(fmt)+4]; | char fmt_buf[MAX_FORMAT_LEN+4]; |
| size=snprintf(local_buf, sizeof(local_buf), wide_int_fmt(fmt, fmt_buf), (unsigned long long)clip2wint(value)); // WUINT_MAX == WINT_MAX | size=snprintf(local_buf, sizeof(local_buf), wide_int_fmt(fmt, fmt_buf), (unsigned long long)clip2wint(value)); // WUINT_MAX == WINT_MAX |
| #else | #else |
| size=snprintf(local_buf, sizeof(local_buf), fmt, clip2uint(value)); | size=snprintf(local_buf, sizeof(local_buf), fmt, clip2uint(value)); |
| Line 341 const char* format_double(double value, | Line 344 const char* format_double(double value, |
| break; | break; |
| case FormatInt:{ | case FormatInt:{ |
| #ifdef PA_WIDE_INT | #ifdef PA_WIDE_INT |
| char fmt_buf[strlen(fmt)+4]; | char fmt_buf[MAX_FORMAT_LEN+4]; |
| size=snprintf(local_buf, sizeof(local_buf), wide_int_fmt(fmt, fmt_buf), (long long)clip2wint(value)); | size=snprintf(local_buf, sizeof(local_buf), wide_int_fmt(fmt, fmt_buf), (long long)clip2wint(value)); |
| #else | #else |
| size=snprintf(local_buf, sizeof(local_buf), fmt, clip2int(value)); | size=snprintf(local_buf, sizeof(local_buf), fmt, clip2int(value)); |