Send MinGW-Notify mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.osdn.me/mailman/listinfo/mingw-notify
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of MinGW-Notify digest..."


Please do not reply to this notification; the sender address is unable to 
accept incoming e-mail.  If you wish to unsubscribe you can do so at 
https://lists.osdn.me/mailman/listinfo/mingw-notify.



Today's Topics:

   1. [mingw] #41597: std::remquo does not yield the proper result
      for the quotient (MinGW Notification List)
   2. [mingw] #41597: std::remquo does not yield the proper result
      for the quotient (MinGW Notification List)


----------------------------------------------------------------------

Message: 1
Date: Sat, 20 Feb 2021 17:56:15 +0000
From: MinGW Notification List <[email protected]>
To: OSDN Ticket System <[email protected]>
Subject: [MinGW-Notify] [mingw] #41597: std::remquo does not yield the
        proper result for the quotient
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

#41597: std::remquo does not yield the proper result for the quotient

  Open Date: 2021-02-17 21:25
Last Update: 2021-02-20 17:56

URL for this Ticket:
    https://osdn.net//projects/mingw/ticket/41597
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=41597

---------------------------------------------------------------------

Last Changes/Comment on this Ticket:
2021-02-20 17:56 Updated by: keith
 * Owner Update from (None) to keith
 * Component Update from GCC to WSL
 * Details Updated

Comment:

Thanks for bringing this to our attention; FWIW, I can reproduce this, 
cross-compiling with mingw32-gcc version 9.2.0 on GNU/Linux, and running under 
Wine.
It would have been helpful, (and you would have received a quicker response), 
if you had provided the requisite SSCCE ... your sample code was incomplete; 
notwithstanding, I have adapted your sample, (as you should have done):
 #include <cmath> #include <cstdlib> #include <iostream>  extern "C" char 
*basename( char * );  int main( int argc, char **argv ) {   if( argc != 3 )   { 
std::cerr << "Usage: " << basename(*argv) << " dividend divisor" << std::endl;  
   return 1;   }    int quotient;   double divisor = std::strtod( argv[2], 
nullptr );   double dividend = std::strtod( argv[1], nullptr );   double 
remainder = std::remquo( dividend, divisor, &quotient );    std::cout << 
dividend << " / " << divisor << " = " << quotient     << " remainder " << 
remainder << std::endl;    return 0; }When I compile, and run this, I see (as 
you did):
$ mingw32-g++ t-remquo.cc
$ ./a.exe 90.1 90.0
90.1 / 90 = 0 remainder 0.1
Looking in the <cmath> header file, I see that GCC's __builtin_remquo() is 
substituted for the std::remquo() call, and looking in GCC's gcc/builtins.c 
suggests that this should be delegated to MPFR.  However, a study of the 
generated assembly code, (with $ mingw32-g++ -S -masm=intel t-remquo.cc -o 
/dev/stdout | less) reveals that the call is actually delegated to the mingwrt 
remquo() function; thus, this is a MinGW runtime library issue, rather than a 
GCC issue.
I understand the purpose of the fprem1 loop, at the start of the remquo() 
implementation, and believe that it is correct.  However, I cannot make any 
sense, at all, of the bit-twiddling logic which follows; it seems clear that it 
does not do the right thing.  OTOH, if I reimplement the entire remquo() 
function, using MPFR, that does DTRT; alternatively, adding:
 #include <climits>  double remquo( double x, double y, int *q ) { double r = 
remainder( x, y );   *q = (int)(fmod( ((x - r) / y), ((double)(INT_MAX) + 1.0) 
));   return r; }into my t-remquo.cc, (below the original set of #include 
statements), this also appears to successfully work around the issue:
$ mingw32-g++ remquo.cc
$ ./a.exe 90.1 90.0
90.1 / 90 = 1 remainder 0.1


---------------------------------------------------------------------
Ticket Status:

      Reporter: avhaecke
         Owner: keith
          Type: Issues
        Status: Open [Owner assigned]
      Priority: 5 - Medium
     MileStone: (None)
     Component: WSL
      Severity: 5 - Medium
    Resolution: None
---------------------------------------------------------------------

Ticket details:

Context :
This problem was encountered with gcc on MinGW in the following version :
gcc.exe (MinGW.org GCC-6.3.0-1) 6.3.0
Description :
The following code :
 double numer = 90.1 ; double denom = 90 .0 ; int quot ; double result = 
std::remquo(numer, denom, &quot) ; std::cout << "result " << result << 
std::endl ; std::cout << "quot " << quot << std::endl;should yield :
result 0.1
quot 1
As is expected from std::remquo, quot has a magnitude which should be congruent 
(modulo 2 to the nth) to the magnitude of the integral quotient of x/y, n being 
greater or equal than 3.
However with gcc 6.3.0, on MinGW, the above instructions yield :
result 0.1
quot 0
On another version of gcc (gcc 4.9.1 2014), the expected behavior is 
encountered.

-- 
Ticket information of MinGW - Minimalist GNU for Windows project
MinGW - Minimalist GNU for Windows Project is hosted on OSDN

Project URL: https://osdn.net/projects/mingw/
OSDN: https://osdn.net

URL for this Ticket:
    https://osdn.net/projects/mingw/ticket/41597
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=41597


------------------------------

Message: 2
Date: Sat, 20 Feb 2021 18:05:55 +0000
From: MinGW Notification List <[email protected]>
To: OSDN Ticket System <[email protected]>
Subject: [MinGW-Notify] [mingw] #41597: std::remquo does not yield the
        proper result for the quotient
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

#41597: std::remquo does not yield the proper result for the quotient

  Open Date: 2021-02-17 21:25
Last Update: 2021-02-20 18:05

URL for this Ticket:
    https://osdn.net//projects/mingw/ticket/41597
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=41597

---------------------------------------------------------------------

Last Changes/Comment on this Ticket:
2021-02-20 18:05 Updated by: keith

Comment:

Reply To apodtele
Ok. You should upgrade to GCC-9.2.0 and see if it is already fixed.
I agree that it would be prudent for the OP to upgrade to GCC-9.2.0.  However, 
as I noted in my formal analysis of the issue, that isn't going to resolve this 
problem, because it is not a GCC issue; it is a MinGW runtime library issue, 
(although I don't know why GCC directs its __builtin_remquo() call to the MinGW 
remquo() implementation, rather than to its own MPFR-based implementation).

---------------------------------------------------------------------
Ticket Status:

      Reporter: avhaecke
         Owner: keith
          Type: Issues
        Status: Open [Owner assigned]
      Priority: 5 - Medium
     MileStone: (None)
     Component: WSL
      Severity: 5 - Medium
    Resolution: None
---------------------------------------------------------------------

Ticket details:

Context :
This problem was encountered with gcc on MinGW in the following version :
gcc.exe (MinGW.org GCC-6.3.0-1) 6.3.0
Description :
The following code :
 double numer = 90.1 ; double denom = 90 .0 ; int quot ; double result = 
std::remquo(numer, denom, &quot) ; std::cout << "result " << result << 
std::endl ; std::cout << "quot " << quot << std::endl;should yield :
result 0.1
quot 1
As is expected from std::remquo, quot has a magnitude which should be congruent 
(modulo 2 to the nth) to the magnitude of the integral quotient of x/y, n being 
greater or equal than 3.
However with gcc 6.3.0, on MinGW, the above instructions yield :
result 0.1
quot 0
On another version of gcc (gcc 4.9.1 2014), the expected behavior is 
encountered.

-- 
Ticket information of MinGW - Minimalist GNU for Windows project
MinGW - Minimalist GNU for Windows Project is hosted on OSDN

Project URL: https://osdn.net/projects/mingw/
OSDN: https://osdn.net

URL for this Ticket:
    https://osdn.net/projects/mingw/ticket/41597
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=3917&tid=41597


------------------------------

Subject: Digest Footer

_______________________________________________
MinGW-Notify mailing list
[email protected]
https://lists.osdn.me/mailman/listinfo/mingw-notify


------------------------------

End of MinGW-Notify Digest, Vol 41, Issue 13
********************************************

Reply via email to