From 9be313f919fa22ff1da5d5585e7c01d4b60778ba Mon Sep 17 00:00:00 2001 From: Martin Nilsson <mani@lysator.liu.se> Date: Sun, 5 May 2002 18:06:29 +0200 Subject: [PATCH] Generate error on sqrt(-1). [bug 3074] Rev: src/modules/_math/math.c:1.43 --- src/modules/_math/math.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/_math/math.c b/src/modules/_math/math.c index c931240b46..9378a0ff28 100644 --- a/src/modules/_math/math.c +++ b/src/modules/_math/math.c @@ -29,7 +29,7 @@ #include <floatingpoint.h> #endif -RCSID("$Id: math.c,v 1.42 2002/01/16 02:56:10 nilsson Exp $"); +RCSID("$Id: math.c,v 1.43 2002/05/05 16:06:29 nilsson Exp $"); #ifndef M_PI #define M_PI 3.1415926535897932384626433832795080 @@ -207,12 +207,15 @@ void f_sqrt(INT32 args) if(sp[-args].type==T_INT) { + /* Note: This algorithm is also implemented in src/stuff.c */ unsigned INT32 n, b, s, y=0; unsigned INT16 x=0; /* FIXME: Note: Regards i as an unsigned value. */ + if(sp[-args].u.integer<0) Pike_error("math: sqrt(x) with (x < 0)\n"); n=sp[-args].u.integer; + for(b=1<<(sizeof(INT32)*8-2); b; b>>=2) { x<<=1; s=b+y; y>>=1; -- GitLab