Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1906 serge 1
 
2
/*
3
 * ====================================================
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * Developed at SunPro, a Sun Microsystems, Inc. business.
7
 * Permission to use, copy, modify, and distribute this
8
 * software is freely granted, provided that this notice
9
 * is preserved.
10
 * ====================================================
11
 */
12
13
 
14
FUNCTION
15
	<>, <>---distance from origin
16
INDEX
17
	hypot
18
INDEX
19
	hypotf
20
21
 
22
	#include 
23
	double hypot(double <[x]>, double <[y]>);
24
	float hypotf(float <[x]>, float <[y]>);
25
26
 
27
	double hypot(<[x]>, <[y]>)
28
	double <[x]>, <[y]>;
29
30
 
31
	float <[x]>, <[y]>;
32
33
 
34
	<> calculates the Euclidean distance
35
	@tex
36
	$\sqrt{x^2+y^2}$
37
	@end tex
38
	@ifnottex
39
	<*<[x]> + <[y]>*<[y]>)>>
40
	@end ifnottex
41
	between the origin (0,0) and a point represented by the
42
	Cartesian coordinates (<[x]>,<[y]>).  <> differs only
43
	in the type of its arguments and result.
44
45
 
46
	Normally, the distance value is returned.  On overflow,
47
	<> returns <> and sets <> to
48
	<>.
49
50
 
51
52
 
53
	<> and <> are not ANSI C.  */
54
55
 
56
 * wrapper hypot(x,y)
57
 */
58
59
 
60
61
 
62
#include 
63
64
 
65
66
 
67
	double hypot(double x, double y)/* wrapper hypot */
68
#else
69
	double hypot(x,y)		/* wrapper hypot */
70
	double x,y;
71
#endif
72
{
73
#ifdef _IEEE_LIBM
74
	return __ieee754_hypot(x,y);
75
#else
76
	double z;
77
	struct exception exc;
78
	z = __ieee754_hypot(x,y);
79
	if(_LIB_VERSION == _IEEE_) return z;
80
	if((!finite(z))&&finite(x)&&finite(y)) {
81
	    /* hypot(finite,finite) overflow */
82
#ifndef HUGE_VAL
83
#define HUGE_VAL inf
84
	    double inf = 0.0;
85
86
 
87
#endif
88
	    exc.type = OVERFLOW;
89
	    exc.name = "hypot";
90
	    exc.err = 0;
91
	    exc.arg1 = x;
92
	    exc.arg2 = y;
93
	    if (_LIB_VERSION == _SVID_)
94
	       exc.retval = HUGE;
95
	    else
96
	       exc.retval = HUGE_VAL;
97
	    if (_LIB_VERSION == _POSIX_)
98
	       errno = ERANGE;
99
	    else if (!matherr(&exc)) {
100
	     	errno = ERANGE;
101
	    }
102
	    if (exc.err != 0)
103
	       errno = exc.err;
104
            return exc.retval;
105
	} else
106
	    return z;
107
#endif
108
}
109
110
 
111