--- parser3/src/main/pa_int.C 2026/01/06 16:36:39 1.3 +++ parser3/src/main/pa_int.C 2026/01/07 01:10:05 1.4 @@ -9,7 +9,7 @@ #include "pa_string.h" #include "pa_exception.h" -volatile const char * IDENT_PA_INT_C="$Id: pa_int.C,v 1.3 2026/01/06 16:36:39 moko Exp $" IDENT_PA_INT_H; +volatile const char * IDENT_PA_INT_C="$Id: pa_int.C,v 1.4 2026/01/07 01:10:05 moko Exp $" IDENT_PA_INT_H; #ifdef PA_WIDE_INT int check4int(pa_wint avalue){ @@ -274,6 +274,27 @@ FormatType format_type(const char* fmt){ return result; } +#ifdef PA_WIDE_INT + +#if defined(_MSC_VER) && (_MSC_VER < 1900) +// old VS: %I64d +#define PA_INTMOD "I64" +#else +// C99: %lld +#define PA_INTMOD "ll" +#endif + +static const char* wide_int_fmt(const char *fmt, char *dst){ + const size_t len = strlen(fmt); + const size_t head = len - 1; + memcpy(dst, fmt, head); + memcpy(dst + head, PA_INTMOD, strlen(PA_INTMOD)); + dst[head + strlen(PA_INTMOD)] = fmt[head]; + dst[head + strlen(PA_INTMOD) + 1] = '\0'; + return dst; +} +#endif + const char* format_double(double value, const char* fmt) { char local_buf[MAX_NUMBER]; @@ -286,12 +307,26 @@ const char* format_double(double value, break; case FormatUInt: if(value >= 0){ // on Apple M1 (uint) is 0 +#ifdef PA_WIDE_INT + char fmt_buf[strlen(fmt)+4]; + size=snprintf(local_buf, sizeof(local_buf), wide_int_fmt(fmt, fmt_buf), (unsigned long long)clip2wint(value)); // WUINT_MAX == WINT_MAX +#else size=snprintf(local_buf, sizeof(local_buf), fmt, clip2uint(value)); - break; +#endif + } else { + // for unsigned formats, wrap negatives to uint as unsigned wint would exceed the 53-bit range + size=snprintf(local_buf, sizeof(local_buf), fmt, clip2int(value)); } - case FormatInt: + break; + case FormatInt:{ +#ifdef PA_WIDE_INT + char fmt_buf[strlen(fmt)+4]; + size=snprintf(local_buf, sizeof(local_buf), wide_int_fmt(fmt, fmt_buf), (long long)clip2wint(value)); +#else size=snprintf(local_buf, sizeof(local_buf), fmt, clip2int(value)); +#endif break; + } case FormatInvalid: throw Exception(PARSER_RUNTIME, 0, "Incorrect format string '%s' was specified.", fmt); }