This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gfortran] patch for PR 15292 missing round and roundf


(2) We can include a implementation of fpclassify(). I don't have such code.

if (x != x) can be used to check for NaN.


if (x - x != 0.0) can be used to check for NaN or infinity.

if (x + x == x) can be used to check for infinity or zero.

See the attached test programlet.

Hope this helps,

Paolo
char * is_nan_test (float x, char *what)
{
  if (x != x)
    return what;
  else
    return "    ";
}

char * is_nan_inf_test (float x, char *what)
{
  if (x - x != 0.0)
    return what;
  else
    return "    ";
}

char * is_inf_zero_test (float x, char *what)
{
  if (x + x == x)
    return what;
  else
    return "    ";
}

void test (float x, char *what)
{
  printf ("%s | %s |  %s   |  %s\n", what,
	  is_nan_test (x, what),
	  is_nan_inf_test (x, what),
	  is_inf_zero_test (x, what));
}

int main()
{
  printf ("     |  NaN |  oo/NaN |  oo/0\n");
  printf ("-----------------------------\n");

  test (0.0, " 0.0");
  test (__builtin_inf(), " +oo");
  test (-__builtin_inf(), " -oo");
  test (__builtin_nan("0x0"), " NaN");
  test (5.0, " 5.0");
  test (-5.0, "-5.0");
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]