--- parser3/src/include/pa_int.h 2026/01/06 16:36:39 1.2 +++ parser3/src/include/pa_int.h 2026/09/15 20:48:14 1.7 @@ -1,21 +1,21 @@ /** @file Parser: pa_int and support functions decls. - Copyright (c) 2001-2026 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) Authors: Konstantin Morshnev , Alexandr Petrosian */ #ifndef PA_INT_H #define PA_INT_H -#define IDENT_PA_INT_H "$Id: pa_int.h,v 1.2 2026/01/06 16:36:39 moko Exp $" +#define IDENT_PA_INT_H "$Id: pa_int.h,v 1.7 2026/09/15 20:48:14 moko Exp $" // includes #include "pa_memory.h" #include "pa_types.h" -//#define PA_WIDE_INT +#define PA_WIDE_INT #ifdef PA_WIDE_INT // int53, -(2^53-1) .. +(2^53-1) safe convertion from double #define PA_WINT_MIN -9007199254740991LL @@ -28,7 +28,7 @@ int check4int(pa_wint avalue); #define PA_WINT_MAX INT_MAX typedef int pa_wint; typedef uint pa_uwint; -static int check4int(pa_wint avalue){ return avalue; } +inline int check4int(pa_wint avalue){ return avalue; } #endif inline int clip2int(double value) { @@ -45,7 +45,8 @@ inline uint clip2uint(double value) { /// Commonly used, templated to work with any integer type -template char* pa_itoa(T n, T base=10){ +template char* pa_itoa(T n){ + const T base=10; char buf[MAX_NUMBER + 1]; char* pos=buf + MAX_NUMBER; *pos='\0'; @@ -66,24 +67,7 @@ template char* pa_itoa(T n, return pa_strdup(pos, buf + MAX_NUMBER - pos); } -static char* pa_itoa(int i, int base=10){ // custom to support INT_MIN - char buf[MAX_NUMBER + 1]; - char* pos=buf + MAX_NUMBER; - *pos='\0'; - - bool negative=i < 0; - unsigned int n= i < 0 ? -i : i; - - do { - *(--pos)=(char)(n % base) + '0'; - n/=base; - } while (n > 0); - - if (negative) { - *(--pos) = '-'; - } - return pa_strdup(pos, buf + MAX_NUMBER - pos); -} +char* pa_itoa(int); // custom to support INT_MIN template char* pa_uitoa(T n, T base=10){ char buf[MAX_NUMBER + 1]; @@ -111,4 +95,8 @@ uint64_t pa_atoul(const char *str, int b const char* format_double(double value, const char *fmt); +// comparing doubles with exact == is unreliable - compare by ULP-distance instead. +#define ULP_EQ_DEFAULT_DIST 3 +bool ulp_eq_double(double a, double b, uint64_t max_ulp=ULP_EQ_DEFAULT_DIST); + #endif