L4Re/OLD/libc_newlib

Annotated libm/math/w_hypot.c

31:7dcb28dd4615
2019-12-08 Paul Boddie Moved reent, string and malloc-related code into separate libraries/packages.
paul@2 1
paul@2 2
/* @(#)w_hypot.c 5.1 93/09/24 */
paul@2 3
/*
paul@2 4
 * ====================================================
paul@2 5
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
paul@2 6
 *
paul@2 7
 * Developed at SunPro, a Sun Microsystems, Inc. business.
paul@2 8
 * Permission to use, copy, modify, and distribute this
paul@2 9
 * software is freely granted, provided that this notice 
paul@2 10
 * is preserved.
paul@2 11
 * ====================================================
paul@2 12
 */
paul@2 13
paul@2 14
/*
paul@2 15
FUNCTION
paul@2 16
	<<hypot>>, <<hypotf>>---distance from origin
paul@2 17
INDEX
paul@2 18
	hypot
paul@2 19
INDEX
paul@2 20
	hypotf
paul@2 21
paul@2 22
SYNOPSIS
paul@2 23
	#include <math.h>
paul@2 24
	double hypot(double <[x]>, double <[y]>);
paul@2 25
	float hypotf(float <[x]>, float <[y]>);
paul@2 26
paul@2 27
DESCRIPTION
paul@2 28
	<<hypot>> calculates the Euclidean distance
paul@2 29
	@tex
paul@2 30
	$\sqrt{x^2+y^2}$
paul@2 31
	@end tex
paul@2 32
	@ifnottex
paul@2 33
	<<sqrt(<[x]>*<[x]> + <[y]>*<[y]>)>>
paul@2 34
	@end ifnottex
paul@2 35
	between the origin (0,0) and a point represented by the
paul@2 36
	Cartesian coordinates (<[x]>,<[y]>).  <<hypotf>> differs only
paul@2 37
	in the type of its arguments and result.
paul@2 38
paul@2 39
RETURNS
paul@2 40
	Normally, the distance value is returned.  On overflow,
paul@2 41
	<<hypot>> returns <<HUGE_VAL>> and sets <<errno>> to
paul@2 42
	<<ERANGE>>.
paul@2 43
paul@2 44
PORTABILITY
paul@2 45
	<<hypot>> and <<hypotf>> are not ANSI C.  */
paul@2 46
paul@2 47
/*
paul@2 48
 * wrapper hypot(x,y)
paul@2 49
 */
paul@2 50
paul@2 51
#include "fdlibm.h"
paul@2 52
#include <errno.h>
paul@2 53
paul@2 54
#ifndef _DOUBLE_IS_32BITS
paul@2 55
paul@2 56
#ifdef __STDC__
paul@2 57
	double hypot(double x, double y)/* wrapper hypot */
paul@2 58
#else
paul@2 59
	double hypot(x,y)		/* wrapper hypot */
paul@2 60
	double x,y;
paul@2 61
#endif
paul@2 62
{
paul@2 63
#ifdef _IEEE_LIBM
paul@2 64
	return __ieee754_hypot(x,y);
paul@2 65
#else
paul@2 66
	double z;
paul@2 67
	z = __ieee754_hypot(x,y);
paul@2 68
	if(_LIB_VERSION == _IEEE_) return z;
paul@2 69
	if((!finite(z))&&finite(x)&&finite(y)) {
paul@2 70
	    /* hypot(finite,finite) overflow */
paul@2 71
	    errno = ERANGE;
paul@2 72
	    return HUGE_VAL;
paul@2 73
	} else
paul@2 74
	    return z;
paul@2 75
#endif
paul@2 76
}
paul@2 77
paul@2 78
#endif /* defined(_DOUBLE_IS_32BITS) */