summaryrefslogtreecommitdiff
path: root/libm/s_fdim.c
blob: 6ed695c3d755551b509e18d2ef7d27c345297aef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* Copyright (C) 2002 by  Red Hat, Incorporated. All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * is freely granted, provided that this notice is preserved.
 */

#include "math.h"
#include "math_private.h"
#include <errno.h>

double fdim(double x, double y)
{
  int cx = __fpclassify(x); /* need both NAN and INF */
  int cy = __fpclassify(y); /* need both NAN and INF */
  if (cx == FP_NAN || cy == NAN)
    return x - y;

  if (x <= y)
	  return .0;

  double z = x - y;
  if (isinf(z) && cx != FP_INFINITE && cy != FP_INFINITE)
	  __set_errno(ERANGE);

  return z;
}
libm_hidden_def(fdim)