diff options
author | shigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-26 13:22:32 +0000 |
---|---|---|
committer | shigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-26 13:22:32 +0000 |
commit | c07d378c832ad4f774da307c0623b113c4502b30 (patch) | |
tree | 1495a9914d4396e13d3eb1ccee787f5715e21ff5 /ext/bigdecimal/bigdecimal.c | |
parent | 7234d2add454744088999af5b0dde65e5ab0c437 (diff) | |
download | ruby-c07d378c832ad4f774da307c0623b113c4502b30.tar.gz ruby-c07d378c832ad4f774da307c0623b113c4502b30.tar.xz ruby-c07d378c832ad4f774da307c0623b113c4502b30.zip |
sqrt() error checking bug fixed.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/bigdecimal.c')
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 6ae02c674..099331682 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); |