From: Rafael Garcia-Suarez Date: Mon, 14 Apr 2008 14:47:15 +0000 (+0000) Subject: Make atan2(0,0) return undef X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9d6bff35783dc768c5d72663e6e2d31769c5da91;p=p5sagit%2Fp5-mst-13.2.git Make atan2(0,0) return undef p4raw-id: //depot/perl@33676 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 3a0d103..f17311a 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -492,8 +492,7 @@ function, or use the familiar relation: sub tan { sin($_[0]) / cos($_[0]) } -Note that atan2(0, 0) is not well-defined, however the Perl -implmentation returns C<0> for this value. +Perl returns C for C. =item bind SOCKET,NAME X diff --git a/pp.c b/pp.c index d940d10..145e74c 100644 --- a/pp.c +++ b/pp.c @@ -2798,7 +2798,10 @@ PP(pp_atan2) dVAR; dSP; dTARGET; tryAMAGICbin(atan2,0); { dPOPTOPnnrl; - SETn(Perl_atan2(left, right)); + if (left == 0.0 && right == 0.0) + SETs(&PL_sv_undef); + else + SETn(Perl_atan2(left, right)); RETURN; } } diff --git a/t/op/exp.t b/t/op/exp.t index 9bc44b4..c49a34b 100755 --- a/t/op/exp.t +++ b/t/op/exp.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 16; +plan tests => 17; # compile time evaluation @@ -57,3 +57,7 @@ cmp_ok(round(cos(-1 * $pi_2)), '==', 0.0); # atan2() tests were removed due to differing results from calls to # atan2() on various OS's and architectures. See perlport.pod for # more information. + +# Just test that atan2(0,0) is undef, because that's implemented +# from within perl. +ok(!defined(atan2(0,0)), 'atan2(0,0) returns undef');