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.133.124]) by sourceware.org (Postfix) with ESMTPS id C3EF5395A057 for ; Thu, 27 Jul 2023 09:39:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C3EF5395A057 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690450749; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=PQ2cwCUukY6SlfjxdhbVdINCN1FEFgV10gqNRTWXOm0=; b=MXiJ7xT1LL+s2a1xCnCMh5bbJPk0M7weu1ntB0ZgzfGUrSMcXSHoHVYScsBCJ7B0WWe+2F F2OwGu9ribfHRDQJymKGTX2lnNNNeD1Pm9F1kFNpetU/QGCUMO5QKoW50NnucoAMC3cgqj RBqKRmo5svI0HkUdB+28eosjUKPoaFM= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-456-pvD1LyP6NQymgRyvyjhYCQ-1; Thu, 27 Jul 2023 05:39:05 -0400 X-MC-Unique: pvD1LyP6NQymgRyvyjhYCQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 96DDD2A59541; Thu, 27 Jul 2023 09:39:05 +0000 (UTC) Received: from calimero.vinschen.de (unknown [10.39.193.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 72A6B492B02; Thu, 27 Jul 2023 09:39:05 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id 2209AA80CB2; Thu, 27 Jul 2023 11:39:04 +0200 (CEST) Date: Thu, 27 Jul 2023 11:39:04 +0200 From: Corinna Vinschen To: Jesse Huang Cc: newlib@sourceware.org, kito.cheng@gmail.com Subject: Re: [PATCH] Fix rounding results in lrint() & llrint() when close to 0 Message-ID: Reply-To: newlib@sourceware.org Mail-Followup-To: Jesse Huang , newlib@sourceware.org, kito.cheng@gmail.com References: <20230727084940.2138765-1-jesse.huang@sifive.com> MIME-Version: 1.0 In-Reply-To: <20230727084940.2138765-1-jesse.huang@sifive.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Jul 27 01:49, Jesse Huang via Newlib wrote: > soft-fp should round floating pointer numbers according to the current > rounding mode. However, in the current code of lrint() and llrint(), > there are if statements before the actual rounding computation > > if(j0 < -1) > return 0; > > Where j0 is the exponent of the floating point number. > > It means any number having a exponent less than -1 > (i.e. interval (-0.5, 0.5)) will be rounded to 0 regardeless of the > rounding mode. > > The bug already fixed in glibc in 2006 by moving the check afterwards > the rounding computation, but still persists in newlib. > > This patch fixed it in a similar way to glibc > Ref Commit in glibc: 6624dbc07b5a9fb316ed188ef01f65b8eea8b47c > --- > newlib/libm/common/s_llrint.c | 31 +++++++++++-------------------- > newlib/libm/common/s_lrint.c | 31 +++++++++++-------------------- > newlib/libm/common/sf_llrint.c | 6 ++---- > newlib/libm/common/sf_lrint.c | 6 ++---- > 4 files changed, 26 insertions(+), 48 deletions(-) Pushed. Thanks, Corinna