public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Siddhesh Poyarekar <siddhesh@gotplt.org>,
	Aldy Hernandez <aldyh@redhat.com>,
	"Joseph S. Myers" <joseph@codesourcery.com>,
	GCC patches <gcc-patches@gcc.gnu.org>,
	Andrew MacLeod <amacleod@redhat.com>
Subject: Re: [PATCH] Implement range-op entry for sin/cos.
Date: Thu, 20 Apr 2023 16:20:34 +0200	[thread overview]
Message-ID: <ZEFKMoLryQD46zGS@tucnak> (raw)
In-Reply-To: <ZEFF2l+KePBP2qnN@tucnak>

[-- Attachment #1: Type: text/plain, Size: 1512 bytes --]

On Thu, Apr 20, 2023 at 04:02:02PM +0200, Jakub Jelinek via Gcc-patches wrote:
> So, I wrote following test.

Slightly adjusted to see more info:

x86_64-linux glibc 2.35:
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/sincos{,.c} -lm; /tmp/sincos || 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
sparc-sun-solaris2.11 results are too large to post in detail, but are
sin -0x1.2d97c7f3321d20000000p+2 0x1.00000000000010000000p+0
...
sin 0x1.f6a7a29553c450000000p+2 0x1.00000000000010000000p+0
DOUBLE UPWARD
sin -0x1.f6a7a2955385e0000000p+2 -0x1.00000000000010000000p+0
...
sin 0x1.2d97c7f3325b90000000p+2 -0x1.00000000000010000000p+0
DOUBLE DOWNWARD
where all the DOUBLE UPWARD values have 0x1.00000000000010000000p+0
results and all DOUBLE DOWNWARD values -0x1.00000000000010000000p+0.
So, I think that is 1ulp in all cases in both directions for
-frounding-math.

	Jakub

[-- Attachment #2: sincos.c --]
[-- Type: text/plain, Size: 1753 bytes --]

#define _GNU_SOURCE
#include <math.h>
#include <fenv.h>
#include <stdio.h>
#include <stdlib.h>

#ifdef FLOAT
#define TYPE float
#define SIN sinf
#define COS cosf
#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
#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
#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
#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);
          }
      }
  return ret;
}

  reply	other threads:[~2023-04-20 14:20 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18 13:12 Aldy Hernandez
2023-04-20 12:59 ` Jakub Jelinek
2023-04-20 13:17   ` Siddhesh Poyarekar
2023-04-20 14:02     ` Jakub Jelinek
2023-04-20 14:20       ` Jakub Jelinek [this message]
2023-04-20 15:22       ` Siddhesh Poyarekar
2023-04-20 15:52         ` Jakub Jelinek
2023-04-20 17:57           ` Siddhesh Poyarekar
2023-04-21  1:14             ` Siddhesh Poyarekar
2023-04-21  6:52               ` Jakub Jelinek
2023-04-21 11:20                 ` Siddhesh Poyarekar
2023-04-25  8:59                 ` Aldy Hernandez
2023-04-24 16:03             ` Jakub Jelinek
2023-04-24 16:05               ` Siddhesh Poyarekar
2023-04-24 16:09                 ` Jakub Jelinek
2023-04-24 16:33                 ` Jeff Law
2023-04-21 16:40   ` Jakub Jelinek
2023-04-21 20:43     ` Mikael Morin
2023-04-21 20:45       ` Jakub Jelinek
2023-04-25  9:10       ` Aldy Hernandez
2023-04-25  9:08     ` Aldy Hernandez
2023-04-27 11:13 ` [PATCH] v2: " Jakub Jelinek
2023-04-27 11:46   ` Aldy Hernandez
2023-04-27 11:53     ` Jakub Jelinek
2023-04-27 12:03       ` Aldy Hernandez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZEFKMoLryQD46zGS@tucnak \
    --to=jakub@redhat.com \
    --cc=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=siddhesh@gotplt.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).