Skip to content
Snippets Groups Projects
Commit 9be313f9 authored by Martin Nilsson's avatar Martin Nilsson
Browse files

Generate error on sqrt(-1). [bug 3074]

Rev: src/modules/_math/math.c:1.43
parent 27ade329
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <floatingpoint.h> #include <floatingpoint.h>
#endif #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 #ifndef M_PI
#define M_PI 3.1415926535897932384626433832795080 #define M_PI 3.1415926535897932384626433832795080
...@@ -207,12 +207,15 @@ void f_sqrt(INT32 args) ...@@ -207,12 +207,15 @@ void f_sqrt(INT32 args)
if(sp[-args].type==T_INT) if(sp[-args].type==T_INT)
{ {
/* Note: This algorithm is also implemented in src/stuff.c */
unsigned INT32 n, b, s, y=0; unsigned INT32 n, b, s, y=0;
unsigned INT16 x=0; unsigned INT16 x=0;
/* FIXME: Note: Regards i as an unsigned value. */ /* 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; n=sp[-args].u.integer;
for(b=1<<(sizeof(INT32)*8-2); b; b>>=2) for(b=1<<(sizeof(INT32)*8-2); b; b>>=2)
{ {
x<<=1; s=b+y; y>>=1; x<<=1; s=b+y; y>>=1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment