public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/103531] New: Prpose compiler warning when ceil functions used on integral value
@ 2021-12-02 13:51 eyalroz1 at gmx dot com
  2021-12-02 14:06 ` [Bug c/103531] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: eyalroz1 at gmx dot com @ 2021-12-02 13:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103531

            Bug ID: 103531
           Summary: Prpose compiler warning when ceil functions used on
                    integral value
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eyalroz1 at gmx dot com
  Target Milestone: ---

The ceil functions (ceil() and ceilf() in C) take floating-point arguments:
double or float.

If the programmer passes an integer value to one of these functions, it'll get
converted to float/double, and the function will be idempotent. It is thus
typically useless to do so, but also harmless in itself.

But this is _not_ harmless when the programmer assumes they are running ceil()
on what they believe is a floating-point value, but actually isn't. A "typical"
example:

forgot_whether_this_type_is_integral_t x = get_x();
int covers_half = ceil(x / 2); 

If x is a floating-point value, this codes will act as expected; but if it's
integral, it will actually place the _floor_ of x / 2.0 in covers_half.

I propose, therefore, that invoking ceil()/ceilf() on an integral value trigger
a warning. Alternatively, that some more complicated conditions trigger the
warning, e.g. invoking ceil() on the result of an integer division or integer
multiplication.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-03  7:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02 13:51 [Bug c/103531] New: Prpose compiler warning when ceil functions used on integral value eyalroz1 at gmx dot com
2021-12-02 14:06 ` [Bug c/103531] " rguenth at gcc dot gnu.org
2021-12-02 19:50 ` [Bug c/103531] Propose compiler warning when ceil/ceilf " eyalroz1 at gmx dot com
2021-12-03  4:03 ` egallager at gcc dot gnu.org
2021-12-03  7:37 ` eyalroz1 at gmx dot com

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).