1259262Stijl#	$OpenBSD: sqroot.m4,v 1.3 2003/06/03 02:56:11 millert Exp $
216748Sjmallett#	$NetBSD: sqroot.m4,v 1.4 1995/09/28 05:38:01 tls Exp $
31590Srgrimes#
41590Srgrimes# Copyright (c) 1989, 1993
51590Srgrimes#	The Regents of the University of California.  All rights reserved.
61590Srgrimes#
71590Srgrimes# This code is derived from software contributed to Berkeley by
81590Srgrimes# Ozan Yigit.
91590Srgrimes#
101590Srgrimes# Redistribution and use in source and binary forms, with or without
111590Srgrimes# modification, are permitted provided that the following conditions
121590Srgrimes# are met:
131590Srgrimes# 1. Redistributions of source code must retain the above copyright
141590Srgrimes#    notice, this list of conditions and the following disclaimer.
151590Srgrimes# 2. Redistributions in binary form must reproduce the above copyright
161590Srgrimes#    notice, this list of conditions and the following disclaimer in the
171590Srgrimes#    documentation and/or other materials provided with the distribution.
18259262Stijl# 3. Neither the name of the University nor the names of its contributors
191590Srgrimes#    may be used to endorse or promote products derived from this software
201590Srgrimes#    without specific prior written permission.
211590Srgrimes#
221590Srgrimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231590Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241590Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251590Srgrimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261590Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271590Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281590Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291590Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301590Srgrimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311590Srgrimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321590Srgrimes# SUCH DAMAGE.
331590Srgrimes#
34216370Sjoel# $FreeBSD$
35216370Sjoel#
361590Srgrimes#	@(#)sqroot.m4	8.1 (Berkeley) 6/6/93
371590Srgrimes#
381590Srgrimes
391590Srgrimesdefine(square_root, 
401590Srgrimes	`ifelse(eval($1<0),1,negative-square-root,
411590Srgrimes			     `square_root_aux($1, 1, eval(($1+1)/2))')')
421590Srgrimesdefine(square_root_aux,
431590Srgrimes	`ifelse($3, $2, $3,
441590Srgrimes		$3, eval($1/$2), $3,
451590Srgrimes		`square_root_aux($1, $3, eval(($3+($1/$3))/2))')')
46