Discussion:
[Mingw-w64-public] [PATCH] remove cast to int from mantissa for __mingw_printf
Martell Malone
2017-06-12 15:24:17 UTC
Permalink
In this thread https://sourceforge.net/p/mingw-w64/bugs/459/
there is a suggested fix for print with whole numbers

The builtin __mingw_printf is inconsistent with printf on %a format.
I think __mingw_printf is wrong, because obviously 1.0 != 0x0p-63.
vacaboja opened an issue on msys2 for this
https://github.com/msys2/msys2/issues/35
and suggested a fix of removing the case to int
here is a patch that does just that.

Please Review

diff --git a/mingw-w64-crt/stdio/mingw_pformat.c
b/mingw-w64-crt/stdio/mingw_pformat.c
index 445320c0..3c7f0833 100644
--- a/mingw-w64-crt/stdio/mingw_pformat.c
+++ b/mingw-w64-crt/stdio/mingw_pformat.c
@@ -2113,7 +2113,7 @@ void __pformat_emit_xfloat( __pformat_fpreg_t value,
__pformat_t *stream )
/* taking the rightmost digit in each pass...
*/
int c = value.__pformat_fpreg_mantissa & 0xF;
- if( c == (int) value.__pformat_fpreg_mantissa)
+ if( c == value.__pformat_fpreg_mantissa)
{
/* inserting the radix point, when we reach the last,
* (i.e. the most significant digit), unless we found no
Mateusz Mikuła
2017-06-12 15:51:30 UTC
Permalink
All patches for mingw-64 should be signed off.


------ Original Message ------
Subject: [Mingw-w64-public] [PATCH] remove cast to int from mantissa for
__mingw_printf
Date: Mon, 12 Jun 2017 16:24:17 +0100
To: Mingw-w64-public
From: Martell Malone
Post by Martell Malone
In this thread https://sourceforge.net/p/mingw-w64/bugs/459/
there is a suggested fix for print with whole numbers
The builtin __mingw_printf is inconsistent with printf on %a format.
I think __mingw_printf is wrong, because obviously 1.0 != 0x0p-63.
vacaboja opened an issue on msys2 for this
https://github.com/msys2/msys2/issues/35
and suggested a fix of removing the case to int
here is a patch that does just that.
Please Review
diff --git a/mingw-w64-crt/stdio/mingw_pformat.c
b/mingw-w64-crt/stdio/mingw_pformat.c
index 445320c0..3c7f0833 100644
--- a/mingw-w64-crt/stdio/mingw_pformat.c
+++ b/mingw-w64-crt/stdio/mingw_pformat.c
@@ -2113,7 +2113,7 @@ void __pformat_emit_xfloat( __pformat_fpreg_t value,
__pformat_t *stream )
/* taking the rightmost digit in each pass...
*/
int c = value.__pformat_fpreg_mantissa & 0xF;
- if( c == (int) value.__pformat_fpreg_mantissa)
+ if( c == value.__pformat_fpreg_mantissa)
{
/* inserting the radix point, when we reach the last,
* (i.e. the most significant digit), unless we found no
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
lhmouse
2017-06-12 17:24:23 UTC
Permalink
Post by Martell Malone
In this thread https://sourceforge.net/p/mingw-w64/bugs/459/
there is a suggested fix for print with whole numbers
The builtin __mingw_printf is inconsistent with printf on %a format.
I think __mingw_printf is wrong, because obviously 1.0 != 0x0p-63.
vacaboja opened an issue on msys2 for this
https://github.com/msys2/msys2/issues/35
and suggested a fix of removing the case to int
here is a patch that does just that.
According to the discussion on that ticket, this patch looks correct.
But why was there such a suspicious cast? It might be there to silence a warning about comparison between signed and unsigned integers, which is enabled by `-Wsign-compare` or `-Wall` in C++ or `-Wextra` in C. If you do see such a warning, I suggest you 1) redeclare `c` as `unsigned` instead of `int`, or 2) cast `c` back to `unsigned` before the comparison.
--
Best regards,
LH_Mouse
Liu Hao
2017-06-15 03:44:47 UTC
Permalink
Post by Martell Malone
In this thread https://sourceforge.net/p/mingw-w64/bugs/459/
there is a suggested fix for print with whole numbers
The builtin __mingw_printf is inconsistent with printf on %a format.
I think __mingw_printf is wrong, because obviously 1.0 != 0x0p-63.
vacaboja opened an issue on msys2 for this
https://github.com/msys2/msys2/issues/35
and suggested a fix of removing the case to int
here is a patch that does just that.
Please Review
The patch does fix the bug, imperfectly nevertheless...

With this patch applied now the result is as follows:
```
E:\Desktop>expand -t4 test.c
#include <stdio.h>

int main(){
__builtin_printf("%a %a\n", 1.0, 1.1);
__mingw_printf("%a %a\n", 1.0, 1.1);
}
E:\Desktop>gcc test.c -L.

E:\Desktop>a.exe
0x1.000000p+0 0x1.19999ap+0
0x8p-3 0x8.cccccccccccdp-3
```

`0x8p-3 = 8 * 2^-3 = 8 * 1 / 8 = 1` hence the result is correct.
But it still does not agree with `printf` from MSVCRT.
--
Best regards,
LH_Mouse
Loading...