public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Thomas dot Koenig at online dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libfortran/19032] modulo generates wrong result for divisor 1 and -1
Date: Fri, 17 Dec 2004 14:29:00 -0000	[thread overview]
Message-ID: <20041217142753.27628.qmail@sourceware.org> (raw)
In-Reply-To: <20041216112828.19032.Thomas.Koenig@online.de>


------- Additional Comments From Thomas dot Koenig at online dot de  2004-12-17 14:27 -------
I've adjusted the subject.

I've had a look at the real modulo and mod case,
but didn't quite understand it - it appeared to
be overly complicated, compared to the straightforward
formula a - floor(a/b)*b.  I'm probably missing something.

Also, here's a new test case.

$ cat mod-array.f90
program main
  integer, parameter :: n=16
  real, dimension(n) :: ar, br, modulo_result, floor_result
  integer, dimension(n) :: ai, bi , imodulo_result, ifloor_result

  ai(1:4) = 5
  ai(5:8) = -5
  ai(9:12) = 1
  ai(13:16) = -1
  bi(1:4) = (/ 3,-3, 1, -1/)
  bi(5:8) = bi(1:4)
  bi(9:12) = bi(1:4)
  bi(13:16) = bi(1:4)
  ar = ai
  br = bi
  modulo_result = modulo(ar,br)
  imodulo_result = modulo(ai,bi)
  floor_result = ar-floor(ar/br)*br
  ifloor_result = nint(real(ai-floor(real(ai)/real(bi))*bi))

  do i=1,n
     if (modulo_result(i) /= floor_result(i) ) then
        print "(A,4F5.0)" ,"real case failed: ", &
             ar(i),br(i), modulo_result(i), floor_result(i)
    end if
    if (imodulo_result(i) /= ifloor_result(i)) then
       print "(A,4I5)", "int case failed: ", &
            ai(i), bi(i), imodulo_result(i), ifloor_result(i)

     end if
  end do
end program main
$ gfortran mod-array.f90 && ./a.out
real case failed:    5.  -1.  -1.   0.
int case failed:     5   -1   -1    0
real case failed:   -5.   1.   1.   0.
int case failed:    -5    1    1    0
real case failed:    1.  -1.  -1.   0.
int case failed:     1   -1   -1    0
real case failed:   -1.   1.   1.   0.
int case failed:    -1    1    1    0


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|modulo generates wrong      |modulo generates wrong
                   |result for divisor -1       |result for divisor 1 and -1


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19032


  parent reply	other threads:[~2004-12-17 14:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-16 11:28 [Bug libfortran/19032] New: modulo generates wrong result Thomas dot Koenig at online dot de
2004-12-16 11:29 ` [Bug libfortran/19032] " Thomas dot Koenig at online dot de
2004-12-16 14:30 ` tobi at gcc dot gnu dot org
2004-12-16 14:41 ` [Bug libfortran/19032] modulo generates wrong result for divisor -1 tobi at gcc dot gnu dot org
2004-12-16 14:42 ` tobi at gcc dot gnu dot org
2004-12-16 22:40 ` Thomas dot Koenig at online dot de
2004-12-17  1:18 ` tobi at gcc dot gnu dot org
2004-12-17 14:29 ` Thomas dot Koenig at online dot de [this message]
2004-12-20 19:08 ` [Bug libfortran/19032] modulo generates wrong result for divisor 1 and -1 tobi at gcc dot gnu dot org
2004-12-20 19:56 ` tobi at gcc dot gnu dot org
2004-12-27 17:13 ` cvs-commit at gcc dot gnu dot org
2004-12-27 17:14 ` tobi at gcc dot gnu dot org
2004-12-27 17:16 ` pinskia at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041217142753.27628.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).