xref: /csrg-svn/usr.bin/m4/TEST/sqroot.m4 (revision 38816)
1*38816Sbostic#
2*38816Sbostic# Copyright (c) 1989 The Regents of the University of California.
3*38816Sbostic# All rights reserved.
4*38816Sbostic#
5*38816Sbostic# This code is derived from software contributed to Berkeley by
6*38816Sbostic# Ozan Yigit.
7*38816Sbostic#
8*38816Sbostic# Redistribution and use in source and binary forms are permitted
9*38816Sbostic# provided that the above copyright notice and this paragraph are
10*38816Sbostic# duplicated in all such forms and that any documentation,
11*38816Sbostic# advertising materials, and other materials related to such
12*38816Sbostic# distribution and use acknowledge that the software was developed
13*38816Sbostic# by the University of California, Berkeley.  The name of the
14*38816Sbostic# University may not be used to endorse or promote products derived
15*38816Sbostic# from this software without specific prior written permission.
16*38816Sbostic# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17*38816Sbostic# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18*38816Sbostic# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19*38816Sbostic#
20*38816Sbostic#	@(#)sqroot.m4	5.1 (Berkeley) 08/28/89
21*38816Sbostic#
22*38816Sbostic
23*38816Sbosticdefine(square_root,
24*38816Sbostic	`ifelse(eval($1<0),1,negative-square-root,
25*38816Sbostic			     `square_root_aux($1, 1, eval(($1+1)/2))')')
26*38816Sbosticdefine(square_root_aux,
27*38816Sbostic	`ifelse($3, $2, $3,
28*38816Sbostic		$3, eval($1/$2), $3,
29*38816Sbostic		`square_root_aux($1, $3, eval(($3+($1/$3))/2))')')
30