From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 72D0A3858C3A for ; Thu, 14 Oct 2021 17:15:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 72D0A3858C3A Received: by mail-wr1-x429.google.com with SMTP id y3so21733394wrl.1 for ; Thu, 14 Oct 2021 10:15:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3uvjinbRPPxQBdWmLcnLl6412IAyY1DTskFhWQsA1UE=; b=mirsUhhKXMlBLbOugVwk5ChFvmcuje0j8acJpz9xbBsMDJDx9i0lLxojyomaMj2Uxe HvoGyneujo4XTRjm5KGZ7F8JZ8nWH0Jlr8msFSDZdCQ39CjbWrqGyjif0hZXxIrEI38s I+5F8WABxH8gd/YYR3U7v/LcxRz2cQxy9qNwPSpoIN66XW58VT1a5Zd5MyqqtlhWPSFG THLkwbolU0WE5HKHT+CcSjb4z756Shj1vM0imd1SrP0tZ1y4FTAcSpw5yhQkRJMFJHq4 Ak3uFA26boPsN/yMJ/PCvaHIAXoKqeu0eNraGmTOWNRkSQMUPcMZoPj8/eDNf5dYVjR8 9kcg== X-Gm-Message-State: AOAM533sTiSqQ8h91JOs51egnzXmy6iAR6qSJIDgk++bEUcQ5e5FEspL x9Y3NMWRvJQ+41dqf6UYtPKVL1RLYvF1I9egM84= X-Google-Smtp-Source: ABdhPJyFXPUy8Px26cxuQd4kykLp6UdUY6ihfxJcI2NUPaQLY1d/6PIV1ZvfbiDbZcZpMTWx1eS43psW7QUoDagC2uo= X-Received: by 2002:a5d:54cc:: with SMTP id x12mr7999254wrv.343.1634231708490; Thu, 14 Oct 2021 10:15:08 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Thu, 14 Oct 2021 18:14:57 +0100 Message-ID: Subject: Re: C programing problem where <= is interpreted as < when using GCC 11.2.0 To: frijolithedog 1 Cc: "gcc-help@gcc.gnu.org" X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Oct 2021 17:15:10 -0000 On Thu, 14 Oct 2021 at 16:21, frijolithedog 1 via Gcc-help < gcc-help@gcc.gnu.org> wrote: > I am having a C programing problem where <= is interpreted as < when using > GCC 11.2.0 > > I was debugging a larger program which I broke down into smaller sections > of code and I noticed > the following code was not working correctly: > > #include > #include > #include > > int main(void) > { > float n, step; > > step = 0.1; > > for (n = 2; n <= 10; n = n + step ) > printf("%3.4f\n", n ); /* This stops at > 9.9000 and not at 10.0000 */ > > } > > I tried the above code only using the following include statement > #include > but the result was the same. > See https://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate and hundreds of other pages explaining the properties of floating-point numbers: https://docs.python.org/3/tutorial/floatingpoint.html https://en.wikipedia.org/wiki/Floating-point_arithmetic#Representable_numbers,_conversion_and_rounding For the full story: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html