summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-27 03:51:56 (GMT)
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-27 03:51:56 (GMT)
commit9be503f332515719475216e7788e6a7fab6c78d0 (patch)
tree4c9a9b32d33742b525282b7cfbcebd6b9a762aea /math.c
parentf64358db7d5f9991bd2c8f6f382ee32767a1c26a (diff)
* math.c (math_atan2): change the behavior when x and y are zero.
* test/ruby/test_math.rb (test_atan2): add tests for the above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r--math.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/math.c b/math.c
index 23bca55..5461763 100644
--- a/math.c
+++ b/math.c
@@ -55,7 +55,13 @@ math_atan2(VALUE obj, VALUE y, VALUE x)
Need_Float2(y, x);
dx = RFLOAT_VALUE(x);
dy = RFLOAT_VALUE(y);
- if (dx == 0.0 && dy == 0.0) domain_error("atan2");
+ if (dx == 0.0 && dy == 0.0) {
+ if (!signbit(dx))
+ return DBL2NUM(dy);
+ if (!signbit(dy))
+ return DBL2NUM(M_PI);
+ return DBL2NUM(-M_PI);
+ }
if (isinf(dx) && isinf(dy)) domain_error("atan2");
return DBL2NUM(atan2(dy, dx));
}