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 D791D3858D28 for ; Mon, 24 Apr 2023 16:03:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D791D3858D28 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=1682352239; 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=LQT2wnYrbwyNusXBNVhUokL5C86M1pLh5Fi5ukQwyBo=; b=hDF/t77peELc/I9hWcyqTXCcZp7wfsmLKzscOdHOsC5rqQP6XhDlUoFRkxyeeDQ3Y3dZOq XxQRwpFwysRyrPD66BGEPzhvjoH6NkbFaS55C0VtPdk6UlymelczHEElYcJ8rnSDas+wIT fllNoDMRx+5L3T6GcrguxFFTvHmLXc4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [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-663-1VOrR72zPcmwTVxahjXJbw-1; Mon, 24 Apr 2023 12:03:55 -0400 X-MC-Unique: 1VOrR72zPcmwTVxahjXJbw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B6E81C02D24; Mon, 24 Apr 2023 16:03:55 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.156]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4A841121318; Mon, 24 Apr 2023 16:03:54 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 33OG3qmW2356308 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 24 Apr 2023 18:03:52 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 33OG3oNe2356307; Mon, 24 Apr 2023 18:03:50 +0200 Date: Mon, 24 Apr 2023 18:03:50 +0200 From: Jakub Jelinek To: Siddhesh Poyarekar Cc: Aldy Hernandez , "Joseph S. Myers" , GCC patches , Andrew MacLeod Subject: Re: [PATCH] Implement range-op entry for sin/cos. Message-ID: Reply-To: Jakub Jelinek References: <20230418131250.310916-1-aldyh@redhat.com> <64abfdef-8eae-9ce9-af62-c57c14c9ffbb@gotplt.org> MIME-Version: 1.0 In-Reply-To: <64abfdef-8eae-9ce9-af62-c57c14c9ffbb@gotplt.org> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="GhGoZNkQtQe7+SAd" Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_LOTSOFHASH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --GhGoZNkQtQe7+SAd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Apr 20, 2023 at 01:57:55PM -0400, Siddhesh Poyarekar wrote: > > Similarly for other functions which have other ranges, perhaps not with so > > nice round numbers. Say asin has [-pi/2, pi/2] range, those numbers aren't > > exactly representable, but is it any worse to round those values to -inf or > > +inf or worse give something 1-5 ulps further from that interval comparing > > to other 1-5ulps errors? I've extended my hack^^^test to include sqrt and this time it seems that the boundary in that case holds even for non-standard rounding modes for glibc: for i in FLOAT DOUBLE LDOUBLE FLOAT128; do for j in TONEAREST UPWARD DOWNWARD TOWARDZERO; do gcc -D$i -DROUND=FE_$j -g -O1 -o /tmp/sincossqrt{,.c} -lm; /tmp/sincossqrt || echo $i $j; done; done sin -0x1.2d97c800000000000000p+2 0x1.00000200000000000000p+0 sin -0x1.2d97c800000000000000p+2 0x1.00000200000000000000p+0 sin 0x1.f9cbe200000000000000p+7 0x1.00000200000000000000p+0 FLOAT UPWARD cos -0x1.f9cbe200000000000000p+8 -0x1.00000200000000000000p+0 sin -0x1.f9cbe200000000000000p+7 -0x1.00000200000000000000p+0 sin 0x1.2d97c800000000000000p+2 -0x1.00000200000000000000p+0 sin 0x1.2d97c800000000000000p+2 -0x1.00000200000000000000p+0 cos 0x1.f9cbe200000000000000p+8 -0x1.00000200000000000000p+0 cos 0x1.f9cbe200000000000000p+8 -0x1.00000200000000000000p+0 FLOAT DOWNWARD Jakub --GhGoZNkQtQe7+SAd Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="sincossqrt.c" #define _GNU_SOURCE #include #include #include #include #ifdef FLOAT #define TYPE float #define SIN sinf #define COS cosf #define SQRT sqrtf #ifdef M_PI_2f #define PI2 M_PI_2f #else #define PI2 1.570796326794896619231321691639751442f #endif #define PRINT(str) printf ("%s %.20a %.20a\n", str, val, res) #define NEXTAFTER nextafterf #elif defined DOUBLE #define TYPE double #define SIN sin #define COS cos #define SQRT sqrt #ifdef M_PI_2 #define PI2 M_PI_2 #else #define PI2 1.570796326794896619231321691639751442f #endif #define NEXTAFTER nextafter #define PRINT(str) printf ("%s %.20a %.20a\n", str, val, res) #elif defined LDOUBLE #define TYPE long double #define SIN sinl #define COS cosl #define SQRT sqrtl #ifdef M_PI_2l #define PI2 M_PI_2l #else #define PI2 1.570796326794896619231321691639751442f #endif #define NEXTAFTER nextafterl #define PRINT(str) printf ("%s %.20La %.20La\n", str, val, res) #elif defined FLOAT128 #define TYPE _Float128 #define SIN sinf128 #define COS cosf128 #define SQRT sqrtf128 #ifdef M_PI_2f128 #define PI2 M_PI_2f128 #else #define PI2 1.570796326794896619231321691639751442f #endif #define NEXTAFTER nextafterf128 #define PRINT(str) __builtin_abort () #endif int main () { int ret = 0; #ifdef ROUND fesetround (ROUND); #endif for (int i = -1024; i <= 1024; i++) for (int j = -1; j <= 1; j += 2) { TYPE val = ((TYPE) i) * PI2; TYPE inf = j * __builtin_inf (); for (int k = 0; k < 1000; k++) { TYPE res = SIN (val); if (res < (TYPE) -1.0 || res > (TYPE) 1.0) { PRINT ("sin"); ret = 1; } res = COS (val); if (res < (TYPE) -1.0 || res > (TYPE) 1.0) { PRINT ("cos"); ret = 1; } val = NEXTAFTER (val, inf); } } for (int j = -1; j <= 1; j += 2) { TYPE val = 0; TYPE inf = j * __builtin_inf (); if (j < 0) val = -val; for (int k = 0; k < 1000; k++) { TYPE res = SQRT (val); if (res < (TYPE) -0.0) { PRINT ("sqrt"); ret = 1; } } } return ret; } --GhGoZNkQtQe7+SAd--