source: trunk/libs/newlib/src/newlib/libm/common/s_fdim.c @ 471

Last change on this file since 471 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.1 KB
Line 
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/*
7FUNCTION
8<<fdim>>, <<fdimf>>---positive difference
9INDEX
10        fdim
11INDEX
12        fdimf
13
14SYNOPSIS
15        #include <math.h>
16        double fdim(double <[x]>, double <[y]>);
17        float fdimf(float <[x]>, float <[y]>);
18
19DESCRIPTION
20The <<fdim>> functions determine the positive difference between their
21arguments, returning:
22.       <[x]> - <[y]>   if <[x]> > <[y]>, or
23        @ifnottex
24.       +0      if <[x]> <= <[y]>, or
25        @end ifnottex
26        @tex
27.       +0      if <[x]> $\leq$ <[y]>, or
28        @end tex
29.       NAN     if either argument is NAN.
30A range error may occur.
31
32RETURNS
33The <<fdim>> functions return the positive difference value.
34
35PORTABILITY
36ANSI C, POSIX.
37
38*/
39
40#include "fdlibm.h"
41
42#ifndef _DOUBLE_IS_32BITS
43
44#ifdef __STDC__
45        double fdim(double x, double y)
46#else
47        double fdim(x,y)
48        double x;
49        double y;
50#endif
51{
52  int c = __fpclassifyd(x);
53  if (c == FP_NAN)  return(x);
54  if (__fpclassifyd(y) == FP_NAN)  return(y);
55  if (c == FP_INFINITE)
56    return HUGE_VAL;
57
58  return x > y ? x - y : 0.0;
59}
60
61#endif /* _DOUBLE_IS_32BITS */
Note: See TracBrowser for help on using the repository browser.