Re: [Mingw-w64-public] [PATCH] crt: arm: Fix rounding for FE_TONEAREST in llrint*
在 2019/4/19 下午11:18, Martin Storsjö 写道: > Signed-off-by: Martin Storsjö > --- > mingw-w64-crt/math/llrint.c | 19 +-- > mingw-w64-crt/math/llrintf.c | 19 +-- > mingw-w64-crt/math/llrintl.c | 19 +-- > 3 files changed, 51 insertions(+), 6 deletions(-) > > This looks good to me. -- Best regards, LH_Mouse signature.asc Description: OpenPGP digital signature ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] wrong declaration of InetNtopA and InetNtopW
在 2019/4/19 下午4:59, Vincent Torri 写道: > when will this hit git or next mingw-w64 release ? > For this small change I will leave it on this mailing list for discussion. If there is no objection I may push it a couple of days later. This means that this fix will be shipped with the next major release, and with the next minor release of the current version by backporting. But I have no idea what that will happen. JonY will know about it. -- Best regards, LH_Mouse signature.asc Description: OpenPGP digital signature ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
[Mingw-w64-public] [PATCH] crt: arm: Fix rounding for FE_TONEAREST in llrint*
Signed-off-by: Martin Storsjö --- mingw-w64-crt/math/llrint.c | 19 +-- mingw-w64-crt/math/llrintf.c | 19 +-- mingw-w64-crt/math/llrintl.c | 19 +-- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/mingw-w64-crt/math/llrint.c b/mingw-w64-crt/math/llrint.c index 8b138c07f..4ba7af7e6 100644 --- a/mingw-w64-crt/math/llrint.c +++ b/mingw-w64-crt/math/llrint.c @@ -19,8 +19,23 @@ long long llrint (double x) retval = (long long)ceil(x); else if (mode == FE_TOWARDZERO) retval = x >= 0 ? (long long)floor(x) : (long long)ceil(x); - else -retval = x >= 0 ? (long long)floor(x + 0.5) : (long long)ceil(x - 0.5); + else { +// Break `x` into integral and fractional parts. +double intg, frac; +frac = modf(x, &intg); +frac = fabs(frac); +// Convert the truncated integral part to an integer. +retval = intg; +if (frac < 0.5) { + // Round towards zero. +} else if (frac > 0.5) { + // Round towards infinities. + retval += signbit(x) ? -1 : 1; +} else { + // Round to the nearest even number. + retval += retval % 2; +} + } #endif return retval; } diff --git a/mingw-w64-crt/math/llrintf.c b/mingw-w64-crt/math/llrintf.c index 1b2a422ea..e8085ec4e 100644 --- a/mingw-w64-crt/math/llrintf.c +++ b/mingw-w64-crt/math/llrintf.c @@ -19,8 +19,23 @@ long long llrintf (float x) retval = (long long)ceilf(x); else if (mode == FE_TOWARDZERO) retval = x >= 0 ? (long long)floorf(x) : (long long)ceilf(x); - else -retval = x >= 0 ? (long long)floorf(x + 0.5) : (long long)ceilf(x - 0.5); + else { +// Break `x` into integral and fractional parts. +float intg, frac; +frac = modff(x, &intg); +frac = fabsf(frac); +// Convert the truncated integral part to an integer. +retval = intg; +if (frac < 0.5) { + // Round towards zero. +} else if (frac > 0.5) { + // Round towards infinities. + retval += signbit(x) ? -1 : 1; +} else { + // Round to the nearest even number. + retval += retval % 2; +} + } #endif return retval; } diff --git a/mingw-w64-crt/math/llrintl.c b/mingw-w64-crt/math/llrintl.c index ac06ab295..6a2bf73d8 100644 --- a/mingw-w64-crt/math/llrintl.c +++ b/mingw-w64-crt/math/llrintl.c @@ -19,8 +19,23 @@ long long llrintl (long double x) retval = (long long)ceil(x); else if (mode == FE_TOWARDZERO) retval = x >= 0 ? (long long)floor(x) : (long long)ceil(x); - else -retval = x >= 0 ? (long long)floor(x + 0.5) : (long long)ceil(x - 0.5); + else { +// Break `x` into integral and fractional parts. +long double intg, frac; +frac = modfl(x, &intg); +frac = fabsl(frac); +// Convert the truncated integral part to an integer. +retval = intg; +if (frac < 0.5) { + // Round towards zero. +} else if (frac > 0.5) { + // Round towards infinities. + retval += signbit(x) ? -1 : 1; +} else { + // Round to the nearest even number. + retval += retval % 2; +} + } #endif return retval; } -- 2.17.1 ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] crt: arm: Fix rounding for FE_TONEAREST in llrint*
On Fri, 19 Apr 2019, Liu Hao wrote: 在 2019/4/19 上午4:00, Martin Storsjö 写道: Signed-off-by: Martin Storsjö --- mingw-w64-crt/math/llrint.c | 20 ++-- mingw-w64-crt/math/llrintf.c | 20 ++-- mingw-w64-crt/math/llrintl.c | 20 ++-- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/mingw-w64-crt/math/llrint.c b/mingw-w64-crt/math/llrint.c index 8b138c07f..a7dbe792a 100644 --- a/mingw-w64-crt/math/llrint.c +++ b/mingw-w64-crt/math/llrint.c @@ -19,8 +19,24 @@ long long llrint (double x) retval = (long long)ceil(x); else if (mode == FE_TOWARDZERO) retval = x >= 0 ? (long long)floor(x) : (long long)ceil(x); - else -retval = x >= 0 ? (long long)floor(x + 0.5) : (long long)ceil(x - 0.5); + else { +double integral; +double frac = modf(x, &integral); For the type `double`, `modf()` is okay. For `float` and `long double` I would suggest using `modff()` and `modfl()`, respectively. +long long iintegral = (long long)integral; +if (frac == 0.5) { + if (iintegral & 1) +retval = iintegral + 1; + else +retval = iintegral; +} else if (frac == -0.5) { + if (iintegral & 1) +retval = iintegral-+ 1; Is this `-+` thing a typo? Yes, it was a typo. It did compile fine though :-) BTW, this function seems unnecessarily complex, especially for non-boundary values (those do not end with `.5`). `modf()` will have truncated the result, so there is no need to call `floor()` or `ceil()` thereafter. An optimum solution might look like this: long long llrint(double x) { // ... if(mode == FE_TONEAREST) { // Break `x` into integral and fractional parts. double intg, frac; frac = modf(x, &intg); frac = fabs(frac); // Convert the truncated integral part to an integer. long long retval = intg; if(frac < 0.5) { // Round towards zero. return retval; } if(frac > 0.5) { // Round towards infinities. return retval + (signbit(x) ? -1 : 1); } // Round to the nearest even number. return retval + retval % 2; } // ... } Thanks, will resend it in that form. // Martin ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] wrong declaration of InetNtopA and InetNtopW
when will this hit git or next mingw-w64 release ? On Fri, Apr 19, 2019 at 10:35 AM Liu Hao wrote: > > 在 2019/4/19 下午3:29, Vincent Torri 写道: > > hello > > > > in ws2tcpip.h, i have the following declarations of these 2 functions : > > > > WINSOCK_API_LINKAGE LPCWSTR WSAAPI InetNtopW(INT Family, PVOID pAddr, > > LPWSTR pStringBuf, size_t StringBufSIze); > > WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, PVOID pAddr, > > LPSTR pStringBuf, size_t StringBufSize); > > > > that is the 2nd parameter is a void * > > > > But in the doc : > > > > https://docs.microsoft.com/fr-fr/windows/desktop/api/ws2tcpip/nf-ws2tcpip-inet_ntop > > https://docs.microsoft.com/fr-fr/windows/desktop/api/ws2tcpip/nf-ws2tcpip-inetntopw > > > > the 2nd parameter is a const void * > > > > is it normal or is it a bug in the declaration ? > > > > thank you > > > > Vincent Torri > > > > > > It looks like typos. The patch attached should fix this issue. > > > > -- > Best regards, > LH_Mouse ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] wrong declaration of InetNtopA and InetNtopW
在 2019/4/19 下午3:29, Vincent Torri 写道: > hello > > in ws2tcpip.h, i have the following declarations of these 2 functions : > > WINSOCK_API_LINKAGE LPCWSTR WSAAPI InetNtopW(INT Family, PVOID pAddr, > LPWSTR pStringBuf, size_t StringBufSIze); > WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, PVOID pAddr, > LPSTR pStringBuf, size_t StringBufSize); > > that is the 2nd parameter is a void * > > But in the doc : > > https://docs.microsoft.com/fr-fr/windows/desktop/api/ws2tcpip/nf-ws2tcpip-inet_ntop > https://docs.microsoft.com/fr-fr/windows/desktop/api/ws2tcpip/nf-ws2tcpip-inetntopw > > the 2nd parameter is a const void * > > is it normal or is it a bug in the declaration ? > > thank you > > Vincent Torri > > It looks like typos. The patch attached should fix this issue. -- Best regards, LH_Mouse From 0c4170ffcd3ef4718820027669cfb1d3d59b8175 Mon Sep 17 00:00:00 2001 From: Liu Hao Date: Fri, 19 Apr 2019 16:34:10 +0800 Subject: [PATCH] include/ws2tcpip.h: Fix prototypes of `InetNtop{A,W}`. Signed-off-by: Liu Hao --- mingw-w64-headers/include/ws2tcpip.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mingw-w64-headers/include/ws2tcpip.h b/mingw-w64-headers/include/ws2tcpip.h index ed562cdd..e8b0abc8 100644 --- a/mingw-w64-headers/include/ws2tcpip.h +++ b/mingw-w64-headers/include/ws2tcpip.h @@ -447,8 +447,8 @@ WINSOCK_API_LINKAGE int WSAAPI WSASetSocketSecurity( #define InetNtopA inet_ntop -WINSOCK_API_LINKAGE LPCWSTR WSAAPI InetNtopW(INT Family, PVOID pAddr, LPWSTR pStringBuf, size_t StringBufSIze); -WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, PVOID pAddr, LPSTR pStringBuf, size_t StringBufSize); +WINSOCK_API_LINKAGE LPCWSTR WSAAPI InetNtopW(INT Family, PCVOID pAddr, LPWSTR pStringBuf, size_t StringBufSIze); +WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, PCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize); #define InetNtop __MINGW_NAME_AW(InetNtop) -- 2.17.1 signature.asc Description: OpenPGP digital signature ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
[Mingw-w64-public] wrong declaration of InetNtopA and InetNtopW
hello in ws2tcpip.h, i have the following declarations of these 2 functions : WINSOCK_API_LINKAGE LPCWSTR WSAAPI InetNtopW(INT Family, PVOID pAddr, LPWSTR pStringBuf, size_t StringBufSIze); WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, PVOID pAddr, LPSTR pStringBuf, size_t StringBufSize); that is the 2nd parameter is a void * But in the doc : https://docs.microsoft.com/fr-fr/windows/desktop/api/ws2tcpip/nf-ws2tcpip-inet_ntop https://docs.microsoft.com/fr-fr/windows/desktop/api/ws2tcpip/nf-ws2tcpip-inetntopw the 2nd parameter is a const void * is it normal or is it a bug in the declaration ? thank you Vincent Torri ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public