⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqrt.c

📁 cfront是最开始c++语言到C语言的转换工具
💻 C
字号:
/*ident	"@(#)cls4:lib/complex/complex/sqrt.c	1.1" *//******************************************************************************* C++ source for the C++ Language System, Release 3.0.  This productis a new release of the original cfront developed in the computerscience research center of AT&T Bell Laboratories.Copyright (c) 1991 AT&T and UNIX System Laboratories, Inc.Copyright (c) 1984, 1989, 1990 AT&T.  All Rights Reserved.THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE of AT&T and UNIX SystemLaboratories, Inc.  The copyright notice above does not evidenceany actual or intended publication of such source code.*******************************************************************************/#include <complex.h>#define	SQRT_DANGER	1e17# define PERIL(t)	(t > SQRT_DANGER || (t < 1/SQRT_DANGER && t != 0))/* * * 7-25-83, note from Leonie Rose - * Stu Feldman says that the peril tests for the following function * are "acceptable" for now, but certain things like * sqrt(1e10 + 1e-30*i) will cause floating exceptions. * */complexsqrt(complex z){	complex  answer;	double  r_old,  partial;/*	Check for possible overflow, and fixup if necessary.*/	double x = abs(z.re);	double y = abs(z.im);	if (x > y && PERIL(x)) {     		z.im /= x;    		z.re /= x;  /* z.re is replaced by 1 or -1 */     		partial = sqrt(x);     	}	else if PERIL(y) {      		z.im /= y;  /* roles of z.re, z.im reversed from previous */     		z.re /= y;     		partial = sqrt(y);     	}	else partial = 1;/*	Main computation:	Use half angle formulas to compute angular part of the square root.	The sign of sin_old is the same as that for sin_new, which means that the	upper half plane gets mapped to the first quadrant, and	the lower half plane to the fourth quandrant.*/	if (r_old = sqrt(z.re*z.re + z.im*z.im)) {    		double r_new = partial * sqrt(r_old);    		double cos_old = z.re/r_old;    		double sin_old = z.im/r_old;    		double cos_new = sqrt( (1 + cos_old)/2 );   		double sin_new = (cos_new == 0)? 1 : sin_old/(2*cos_new);    		answer.re = r_new * cos_new;    		answer.im = r_new * sin_new;    	}	return answer;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -