From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30088 invoked by alias); 12 Jul 2006 14:45:03 -0000 Received: (qmail 30000 invoked by uid 22791); 12 Jul 2006 14:45:01 -0000 X-Spam-Check-By: sourceware.org Received: from py-out-1112.google.com (HELO py-out-1112.google.com) (64.233.166.180) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 12 Jul 2006 14:45:00 +0000 Received: by py-out-1112.google.com with SMTP id c30so254567pyc for ; Wed, 12 Jul 2006 07:44:58 -0700 (PDT) Received: by 10.35.9.15 with SMTP id m15mr942005pyi; Wed, 12 Jul 2006 07:44:58 -0700 (PDT) Received: by 10.35.67.3 with HTTP; Wed, 12 Jul 2006 07:44:58 -0700 (PDT) Message-ID: <580cd3b30607120744r7d673234waf810673d9b63d2@mail.gmail.com> Date: Wed, 12 Jul 2006 14:45:00 -0000 From: "Scott Lipcon" To: gcc-help@gcc.gnu.org Subject: floating point warnings, and gcc 4 warnings in general MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_4750_877446.1152715498572" Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2006-07/txt/msg00146.txt.bz2 ------=_Part_4750_877446.1152715498572 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Content-length: 2277 Hi all, I'm trying to figure out how to get gcc to warn on a specific problem that we found in our source code. I've attached a simple test program that has a few places where floating point precision can potentially be lost or cause problems. Specifically: 1) Line 12, returns a double as a float without an explicit cast - loss of precision. Would like a warning here. 2) Line 19, same problem, but with fixed point - returns an int as a short, without a cast - loss of precision, would like a warning 3) Line 31, subtracts a float from a double (the constant is treated as a double, the variable is explicitly cast as a float. In this particular case, as can be seen in the printf on line 34, pi/2 - pi/2 does not equal zero. This seems like it might be harder to check for, but I'd love to see a warning here as well. Note that the method on line 15, where I return a double as an int does have a warning, even without any -W... options: tryFloat.C: In member function `int Test::getDI() const': tryFloat.C:15: warning: return to `int' from `const double' tryFloat.C:15: warning: argument to `int' from `const double' The man page on gcc 3.4 and above seem to imply that -Wextra should have checks for these floating point precision problems - however I've tried gcc 3.3.2, 3.4.x, 4.0.0, and 4.1.1, and no matter how many -W options I add, -pedantic, -ansi, etc, to make the compile as strict as possible, I can't get warnings for these floating point problems. Can anyone point out how to get warnings, or explain why these aren't candidates for a warning? Finally, and probably unrelated, when I used gcc 4.0.0 and 4.1.1, on RedHat Enterprise 4 (ES), the warnings I do get are formatted badly - ie, the warning above (from 3.3.2) shows up as: tryFloat.C: In member function =E2: tryFloat.C:15: warning: converting to =E2 from =E2 I don't know what the =E2 character is, but thats clearly not very useful. The gcc 4.1.1 is a freshly compiled install - I compiled it with RedHat's gcc 3.4.5 using: Configured with: /usr/src/gcc-4.1.1/configure --prefix=3D/usr/local/gcc-4.1.1 --disable-shared --enable-threads=3Dposix --enable-lang=3Dc,c++ and make bootstrap. Any ideas on this one? Thanks very much, Scott Lipcon ------=_Part_4750_877446.1152715498572 Content-Type: application/octet-stream; name=tryFloat.C Content-Transfer-Encoding: base64 X-Attachment-Id: f_epjt12dt Content-Disposition: attachment; filename="tryFloat.C" Content-length: 1302 I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIE1fUEkgMy4xNDE1OTI2NTM1 ODk3OTMyMzg0NgoKY2xhc3MgVGVzdAp7CiAgcHVibGljOgogICAgVGVzdCgp IDogX2QoMC4wKSwgX2koMCkge30KCiAgICB2b2lkIHNldEQoY29uc3QgZG91 YmxlICZkKSB7IF9kID0gZDsgfQogICAgZG91YmxlIGdldEQoKSBjb25zdCB7 IHJldHVybiBfZDsgfQogICAgZmxvYXQgZ2V0REYoKSBjb25zdCB7IHJldHVy biBfZDsgfQoKICAgIC8vIHdhcm5pbmc6IHJldHVybiB0byBgaW50JyBmcm9t IGBjb25zdCBkb3VibGUnCiAgICBpbnQgZ2V0REkoKSBjb25zdCB7IHJldHVy biBfZDsgfQoKICAgIHZvaWQgc2V0SShjb25zdCBpbnQgJmkpIHsgX2kgPSBp OyB9CiAgICBpbnQgZ2V0SSgpIGNvbnN0IHsgcmV0dXJuIF9pOyB9CiAgICBz aG9ydCBnZXRJUygpIGNvbnN0IHsgcmV0dXJuIF9pOyB9CgogIHByaXZhdGU6 CiAgICBkb3VibGUgX2Q7CiAgICBpbnQgX2k7Cn07CgppbnQgbWFpbihpbnQg LyphcmdjKi8sIGNoYXIqKiAvKmFyZ3YqLykKewogIGRvdWJsZSBkID0gKE1f UEkgLyAyLjApIC0gMC4wOwoKICBkb3VibGUgZG91YmxlUmVzID0gKE1fUEkg LyAyLjApIC0gZDsKICBmbG9hdCBmbG9hdFJlcyA9IChNX1BJIC8gMi4wKSAt IChmbG9hdClkOwoKICBwcmludGYoImRvdWJsZTogJS40NWZcbiIsIGRvdWJs ZVJlcyk7CiAgcHJpbnRmKCJmbG9hdDogJS40NWZcbiIsIGZsb2F0UmVzKTsK CiAgVGVzdCB0OwogIHQuc2V0RChNX1BJKTsKICBwcmludGYoImRvdWJsZTog JS40NWZcbiIsIHQuZ2V0RCgpKTsKICBwcmludGYoImZsb2F0OiAlLjQ1Zlxu IiwgdC5nZXRERigpKTsKICBwcmludGYoImludDogJWRcbiIsIHQuZ2V0REko KSk7CgogIHQuc2V0SSg2NjAwMCk7CiAgcHJpbnRmKCJpbnQ6ICVkXG4iLCB0 LmdldEkoKSk7CiAgcHJpbnRmKCJzaG9ydDogJWRcbiIsIHQuZ2V0SVMoKSk7 CiAgcmV0dXJuIDA7Cn0K ------=_Part_4750_877446.1152715498572--