Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4349 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
#include 
61
62
 
63
64
 
65
	double hypot(double x, double y)/* wrapper hypot */
66
#else
67
	double hypot(x,y)		/* wrapper hypot */
68
	double x,y;
69
#endif
70
{
71
#ifdef _IEEE_LIBM
72
	return __ieee754_hypot(x,y);
73
#else
74
	double z;
75
	struct exception exc;
76
	z = __ieee754_hypot(x,y);
77
	if(_LIB_VERSION == _IEEE_) return z;
78
	if((!finite(z))&&finite(x)&&finite(y)) {
79
	    /* hypot(finite,finite) overflow */
80
#ifndef HUGE_VAL
81
#define HUGE_VAL inf
82
	    double inf = 0.0;
83
84
 
85
#endif
86
	    exc.type = OVERFLOW;
87
	    exc.name = "hypot";
88
	    exc.err = 0;
89
	    exc.arg1 = x;
90
	    exc.arg2 = y;
91
	    if (_LIB_VERSION == _SVID_)
92
	       exc.retval = HUGE;
93
	    else
94
	       exc.retval = HUGE_VAL;
95
	    if (_LIB_VERSION == _POSIX_)
96
	       errno = ERANGE;
97
	    else if (!matherr(&exc)) {
98
	     	errno = ERANGE;
99
	    }
100
	    if (exc.err != 0)
101
	       errno = exc.err;
102
            return exc.retval;
103
	} else
104
	    return z;
105
#endif
106
}
107
108
 
109