From 4b159597af39db858f15fba6b7e49cdbf191469a Mon Sep 17 00:00:00 2001 From: shigek Date: Tue, 26 Aug 2003 13:22:32 +0000 Subject: sqrt() error checking bug fixed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/bigdecimal.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'ext/bigdecimal/bigdecimal.c') diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 6ae02c6748..099331682b 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -3624,18 +3624,23 @@ VpSqrt(Real *y, Real *x) S_LONG nr; double val; + /* Zero, NaN or Infinity ? */ + if(!VpHasVal(x)) { + if(VpIsZero(x)||VpGetSign(x)>0) { + VpAsgn(y,x,1); + goto Exit; + } + VpSetNaN(y); + return VpException(VP_EXCEPTION_OP,"(VpSqrt) SQRT(NaN or negative value)",0); + goto Exit; + } + /* Negative ? */ if(VpGetSign(x) < 0) { VpSetNaN(y); return VpException(VP_EXCEPTION_OP,"(VpSqrt) SQRT(negative value)",0); } - /* NaN or Infinity ? */ - if(!VpHasVal(x)) { - VpAsgn(y,x,1); - goto Exit; - } - /* One ? */ if(VpIsOne(x)) { VpSetOne(y); -- cgit v1.2.3