s_fdim.c 635 B

123456789101112131415161718192021222324252627
  1. /* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
  2. *
  3. * Permission to use, copy, modify, and distribute this software
  4. * is freely granted, provided that this notice is preserved.
  5. */
  6. #include "math.h"
  7. #include "math_private.h"
  8. #include <errno.h>
  9. double fdim(double x, double y)
  10. {
  11. int cx = __fpclassify(x); /* need both NAN and INF */
  12. int cy = __fpclassify(y); /* need both NAN and INF */
  13. if (cx == FP_NAN || cy == NAN)
  14. return x - y;
  15. if (x <= y)
  16. return .0;
  17. double z = x - y;
  18. if (isinf(z) && cx != FP_INFINITE && cy != FP_INFINITE)
  19. __set_errno(ERANGE);
  20. return z;
  21. }
  22. libm_hidden_def(fdim)