From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1DEB3385841F for ; Sun, 16 Jan 2022 18:07:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1DEB3385841F Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-551-DdbdKj4uPs6Q47V49AmARQ-1; Sun, 16 Jan 2022 13:07:00 -0500 X-MC-Unique: DdbdKj4uPs6Q47V49AmARQ-1 Received: by mail-qt1-f199.google.com with SMTP id 99-20020aed316c000000b002ca8fa65563so1676450qtg.23 for ; Sun, 16 Jan 2022 10:07:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jtPRBd43JVT4DpBwHx6GaYD6EfI93wd1HhVZLc5UOwE=; b=ftvkSV55Jr19bGUyRUH/UD1DdEAYZZph9ooCc8GqqhBVh/nnRrJmhektchj6rD2FaF asgOGvygpM+KwdR0kVaWs91svp5UBinQjpxhDkSG7jSSyC3tHN2YR6gFVoMFYaCBimzt vTBHug7nyBlDkYTZI4VfZvFQgssl53bYU3gRFCI9OJvUZ0+UqylV3yDSeJQF/J986kSj PCmXNb8IFxvj3Za38rQLP8kj5WjXIFeabgV8AKSGi4Zsaue4mRGorEdC4BTRxw2bOWoi WfSAyFrfwS5wvY042uyeSAcd+1Ps32ZYfyqP0ZCmKXeAy6DG0jdXTknpv6AMUd7C3jWE qIHw== X-Gm-Message-State: AOAM53189pviCry2BCj2/mrpbFSjUc1BwXb9uhXTJMRdxcJ9drJR4Beb c5GzK1LJ5APTWOF+5+QAZdZUIwPGMM5pI7uHQNJefh+bF61kHSXXHBa5i9eEbQeM38VTxxsFx6p KijJiclAUgEyhucU= X-Received: by 2002:a37:717:: with SMTP id 23mr10824202qkh.592.1642356419783; Sun, 16 Jan 2022 10:06:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxj6gjRQ5Ovm+c12rJqiJSqiHwXxTHKhJ5+nf//mLDwyX0ltyKl/BIK2heMJqH24hAcCOTi5A== X-Received: by 2002:a37:717:: with SMTP id 23mr10824195qkh.592.1642356419548; Sun, 16 Jan 2022 10:06:59 -0800 (PST) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id o10sm7994149qtx.33.2022.01.16.10.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jan 2022 10:06:58 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 4/6] libstdc++: Adjust fast_float's over/underflow behavior for conformnace Date: Sun, 16 Jan 2022 13:06:50 -0500 Message-Id: <20220116180652.3694791-4-ppalka@redhat.com> X-Mailer: git-send-email 2.35.0.rc1 In-Reply-To: <20220116180652.3694791-1-ppalka@redhat.com> References: <20220116180652.3694791-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Jan 2022 18:07:08 -0000 This makes fast_float handle the situation where std::from_chars is specified to return result_out_of_range, i.e. when the parsed value is outside the representable range of the floating-point type. This adjusts fast_float's behavior in case of over/underflow: instead of returning errc{} and setting value to +-0 or +-infinity, return result_out_of_range and don't modify value, as per [charconv.from.chars]/1. libstdc++-v3/ChangeLog: * src/c++17/fast_float/LOCAL_PATCHES: Update. * src/c++17/fast_float/fast_float.h (from_chars_advanced): In case of over/underflow, return errc::result_out_of_range and don't modify 'value'. --- libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES | 1 + libstdc++-v3/src/c++17/fast_float/fast_float.h | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES index e9d7bba6195..1f90f9d1d85 100644 --- a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES +++ b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES @@ -1 +1,2 @@ r12-???? +r12-???? diff --git a/libstdc++-v3/src/c++17/fast_float/fast_float.h b/libstdc++-v3/src/c++17/fast_float/fast_float.h index c908719ec3a..97d28940944 100644 --- a/libstdc++-v3/src/c++17/fast_float/fast_float.h +++ b/libstdc++-v3/src/c++17/fast_float/fast_float.h @@ -2884,6 +2884,15 @@ from_chars_result from_chars_advanced(const char *first, const char *last, // If we called compute_float>(pns.exponent, pns.mantissa) and we have an invalid power (am.power2 < 0), // then we need to go the long way around again. This is very uncommon. if(am.power2 < 0) { am = digit_comp(pns, am); } + + if((pns.mantissa != 0 && am.mantissa == 0 && am.power2 == 0) || am.power2 == binary_format::infinite_power()) { + // In case of over/underflow, return result_out_of_range and don't modify value, + // as per [charconv.from.chars]/1. Note that LWG 3081 wants to modify value in + // this case too. + answer.ec = std::errc::result_out_of_range; + return answer; + } + to_float(pns.negative, am, value); return answer; } -- 2.35.0.rc1