public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* sqrtl behavior inconsistent with sqrt and sqrtf
@ 2020-10-27 11:17 airplanemath
  2020-10-27 11:44 ` airplanemath
  2020-10-27 13:51 ` Ken Brown
  0 siblings, 2 replies; 3+ messages in thread
From: airplanemath @ 2020-10-27 11:17 UTC (permalink / raw)
  To: cygwin

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

Compiling and running the attached program with the command line below
produces the output below:

[-- Attachment #2: Test program for sqrtl, sqrt, and sqrtf --]
[-- Type: text/plain, Size: 373 bytes --]

#include <math.h>
#include <stdio.h>

int main() {
  long double a, b;
  double c, d;
  float f, g;
  a = (long double) -INFINITY;
  c = (double) -INFINITY;
  f = (float) -INFINITY;
  b = sqrtl(a);
  d = sqrt(c);
  g = sqrtf(f);
  printf("Long double: %4Lf %4Lf\n", a, b);
  printf("Double:      %4lf %4lf\n", c, d);
  printf("Float:       %4f %4f\n", f, g);
  return 0;
}

[-- Attachment #3: Type: text/plain, Size: 327 bytes --]


$ gcc -O0 -Og test_sqrt.c -o test_sqrt && ./test_sqrt
Long double: -inf -inf
Double:      -inf -nan
Float:       -inf -nan

I suspect the behavior for long double should be the same as for double
and float (sqrt(-inf) = nan), but I'm not sure where to change that.
I'm running a snapshot of Cygwin 3.2.0, if that's important.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: sqrtl behavior inconsistent with sqrt and sqrtf
  2020-10-27 11:17 sqrtl behavior inconsistent with sqrt and sqrtf airplanemath
@ 2020-10-27 11:44 ` airplanemath
  2020-10-27 13:51 ` Ken Brown
  1 sibling, 0 replies; 3+ messages in thread
From: airplanemath @ 2020-10-27 11:44 UTC (permalink / raw)
  To: cygwin

airplanemath via Cygwin <cygwin@cygwin.com> writes:

> Compiling and running the attached program with the command line below
> produces the output below:
>
> $ gcc -O0 -Og test_sqrt.c -o test_sqrt && ./test_sqrt
> Long double: -inf -inf
> Double:      -inf -nan
> Float:       -inf -nan
>
> I suspect the behavior for long double should be the same as for double
> and float (sqrt(-inf) = nan), but I'm not sure where to change that.
> I'm running a snapshot of Cygwin 3.2.0, if that's important.

The mail archive says I'm bad at attaching things.
Program source included below:

#include <math.h>
#include <stdio.h>

int main() {
  long double a, b;
  double c, d;
  float f, g;
  a = (long double) -INFINITY;
  c = (double) -INFINITY;
  f = (float) -INFINITY;
  b = sqrtl(a);
  d = sqrt(c);
  g = sqrtf(f);
  printf("Long double: %4Lf %4Lf\n", a, b);
  printf("Double:      %4lf %4lf\n", c, d);
  printf("Float:       %4f %4f\n", f, g);
  return 0;
}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: sqrtl behavior inconsistent with sqrt and sqrtf
  2020-10-27 11:17 sqrtl behavior inconsistent with sqrt and sqrtf airplanemath
  2020-10-27 11:44 ` airplanemath
@ 2020-10-27 13:51 ` Ken Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Ken Brown @ 2020-10-27 13:51 UTC (permalink / raw)
  To: airplanemath, cygwin

On 10/27/2020 7:17 AM, airplanemath via Cygwin wrote:
> Compiling and running the attached program with the command line below
> produces the output below:
> 
> 
> 
> $ gcc -O0 -Og test_sqrt.c -o test_sqrt && ./test_sqrt
> Long double: -inf -inf
> Double:      -inf -nan
> Float:       -inf -nan
> 
> I suspect the behavior for long double should be the same as for double
> and float (sqrt(-inf) = nan), but I'm not sure where to change that.
> I'm running a snapshot of Cygwin 3.2.0, if that's important.

This is again a bug in the mingw-w64 math code that was imported into Cygwin. 
I'll send a fix to the cygwin-patches list.

Ken

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-27 13:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 11:17 sqrtl behavior inconsistent with sqrt and sqrtf airplanemath
2020-10-27 11:44 ` airplanemath
2020-10-27 13:51 ` Ken Brown

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).