Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 Feb 2021 12:39:29 -0800
From:      Steve Kargl <sgk@troutmask.apl.washington.edu>
To:        freebsd-current@freebsd.org
Subject:   hypothl(x) mishandles subnormal numbers.
Message-ID:  <20210206203929.GA45801@troutmask.apl.washington.edu>

next in thread | raw e-mail | index | archive | help
I've long forgotten by freebsd bugzilla password.  
So, if someone would like to submit a bug report,
here's a test program.

% cc -o z -O2 -fno-builtin z.c -lm
% ./z
Via scaling and sqrtl
x=2.853684e-4932 y=1.444012e-4922 a=1.444012e-4922
x=0x1.b2933cafa0bb8p-16383 y=0x1.fffffffffffffp-16351 a=0x1.000000006ca4c8p-16350

Via hypotl
x=2.853684e-4932 y=1.444012e-4922 z=nan
x=0x1.b2933cafa0bb8p-16383 y=0x1.fffffffffffffp-16351 z=nan

% cat z.c
#include <stdio.h>
#include <math.h>

#if defined(__i386__)
#include <ieeefp.h>
#endif

int main()
{
  long double x, y, z, a;

#if defined(__i386__)
        fpsetprec(FP_PE);
#endif

   x = 0x3.6526795f4176ep-16384L;
   y = 0x3.ffffffffffffep-16352L;
   z = hypotl(x, y);

   if (x > y) {
      a = y / x;
      a = x * sqrtl(1 + a);
   } else {
      a = x / y;
      a = y * sqrtl(a + 1);
   }

   printf("Via scaling and sqrtl\n");
   printf("x=%Le y=%Le a=%Le\n", x, y, a);
   printf("x=%La y=%La a=%La\n", x, y, a);

   printf("\nVia hypotl\n");
   printf("x=%Le y=%Le z=%Le\n", x, y, z);
   printf("x=%La y=%La z=%La\n", x, y, z);

   return 0;
}

-- 
Steve



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20210206203929.GA45801>