File: s_fdim.c

package info (click to toggle)
picolibc 1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 31,616 kB
  • sloc: ansic: 312,308; asm: 22,739; perl: 2,414; sh: 1,619; python: 1,019; pascal: 329; exp: 287; makefile: 164; xml: 40; cpp: 10
file content (57 lines) | stat: -rw-r--r-- 1,092 bytes parent folder | download | duplicates (3)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* 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.
 */
/*
FUNCTION
<<fdim>>, <<fdimf>>---positive difference
INDEX
	fdim
INDEX
	fdimf

SYNOPSIS
	#include <math.h>
	double fdim(double <[x]>, double <[y]>);
	float fdimf(float <[x]>, float <[y]>);

DESCRIPTION
The <<fdim>> functions determine the positive difference between their
arguments, returning:
.	<[x]> - <[y]>	if <[x]> > <[y]>, or
	@ifnottex
.	+0	if <[x]> <= <[y]>, or
	@end ifnottex
	@tex
.	+0	if <[x]> $\leq$ <[y]>, or
	@end tex
.	NAN	if either argument is NAN.
A range error may occur.

RETURNS
The <<fdim>> functions return the positive difference value.

PORTABILITY
ANSI C, POSIX.

*/

#include "fdlibm.h"

#ifdef _NEED_FLOAT64

__float64
fdim64(__float64 x, __float64 y)
{
  if (isnan(x) || isnan(y)) return(x+y);

  __float64 z = x > y ? x - y : _F_64(0.0);
  if (!isinf(x) && !isinf(y))
    z = check_oflow(z);
  return z;
}

_MATH_ALIAS_d_dd(fdim)

#endif /* _NEED_FLOAT64 */