Change 25401 by [EMAIL PROTECTED] on 2005/09/13 17:51:49
Integrate:
[ 24370]
Convert to test.pl
[ 24371]
Subject: [PATCH] IEEE math for the masses
From: Steve Peters <[EMAIL PROTECTED]>
Date: Fri, 15 Apr 2005 09:10:54 -0500
Message-ID: <[EMAIL PROTECTED]>
(tests added to t/op/exp.t)
[ 24377]
ok($a == $b) better written as cmp_ok($a, '==', $b)
(The latter gives more diagnostics in the case of failure)
[ 24388]
Document the unportability of atan2() edge cases
and remove unportable tests (by Steve Peters)
Affected files ...
... //depot/maint-5.8/perl/pod/perlport.pod#21 integrate
... //depot/maint-5.8/perl/pp.c#57 integrate
... //depot/maint-5.8/perl/t/op/exp.t#2 integrate
Differences ...
==== //depot/maint-5.8/perl/pod/perlport.pod#21 (text) ====
Index: perl/pod/perlport.pod
--- perl/pod/perlport.pod#20~25368~ Sat Sep 10 05:44:18 2005
+++ perl/pod/perlport.pod Tue Sep 13 10:51:49 2005
@@ -1556,6 +1556,17 @@
C<-x> (or C<-X>) determine if a file has an executable file type.
(S<RISC OS>)
+=item atan2 Y,X
+
+Due to issues with various CPUs, math libraries, compilers, and standards,
+results for C<atan2()> may vary depending on any combination of the above.
+Perl attempts to conform to the Open Group/IEEE standards for the results
+returned from C<atan2()>, but cannot force the issue if the system Perl is
+run on does not allow it. (Tru64, HP-UX 10.20)
+
+The current version of the standards for C<atan2()> is available at
+L<http://www.opengroup.org/onlinepubs/009695399/functions/atan2.html>.
+
=item atan2
Due to issues with various CPUs, math libraries, compilers, and standards,
==== //depot/maint-5.8/perl/pp.c#57 (text) ====
Index: perl/pp.c
--- perl/pp.c#56~25394~ Mon Sep 12 14:21:39 2005
+++ perl/pp.c Tue Sep 13 10:51:49 2005
@@ -35,6 +35,14 @@
extern Pid_t getpid (void);
#endif
+/*
+ * Some BSDs and Cygwin default to POSIX math instead of IEEE.
+ * This switches them over to IEEE.
+ */
+#if defined(LIBM_LIB_VERSION)
+ _LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;
+#endif
+
/* variations on pp_null */
PP(pp_stub)
==== //depot/maint-5.8/perl/t/op/exp.t#2 (xtext) ====
Index: perl/t/op/exp.t
--- perl/t/op/exp.t#1~17645~ Fri Jul 19 12:29:57 2002
+++ perl/t/op/exp.t Tue Sep 13 10:51:49 2005
@@ -1,27 +1,59 @@
#!./perl
-# $RCSfile: exp.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:50 $
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ require './test.pl';
+}
-print "1..6\n";
+plan tests => 16;
# compile time evaluation
$s = sqrt(2);
-if (substr($s,0,5) eq '1.414') {print "ok 1\n";} else {print "not ok 1\n";}
+is(substr($s,0,5), '1.414');
$s = exp(1);
-if (substr($s,0,7) eq '2.71828') {print "ok 2\n";} else {print "not ok 2\n";}
+is(substr($s,0,7), '2.71828');
-if (exp(log(1)) == 1) {print "ok 3\n";} else {print "not ok 3\n";}
+cmp_ok(exp(log(1)), '==', 1);
# run time evaluation
$x1 = 1;
$x2 = 2;
$s = sqrt($x2);
-if (substr($s,0,5) eq '1.414') {print "ok 4\n";} else {print "not ok 4\n";}
+is(substr($s,0,5), '1.414');
$s = exp($x1);
-if (substr($s,0,7) eq '2.71828') {print "ok 5\n";} else {print "not ok 5\n";}
+is(substr($s,0,7), '2.71828');
-if (exp(log($x1)) == 1) {print "ok 6\n";} else {print "not ok 6\n";}
+cmp_ok(exp(log($x1)), '==', 1);
+
+# tests for transcendental functions
+
+my $pi = 3.1415926535897931160;
+my $pi_2 = 1.5707963267948965580;
+
+sub round {
+ my $result = shift;
+ return sprintf("%.9f", $result);
+}
+
+# sin() tests
+cmp_ok(sin(0), '==', 0.0);
+cmp_ok(round(sin($pi)), '==', 0.0);
+cmp_ok(round(sin(-1 * $pi)), '==', 0.0);
+cmp_ok(round(sin($pi_2)), '==', 1.0);
+cmp_ok(round(sin(-1 * $pi_2)), '==', -1.0);
+
+# cos() tests
+cmp_ok(cos(0), '==', 1.0);
+cmp_ok(round(cos($pi)), '==', -1.0);
+cmp_ok(round(cos(-1 * $pi)), '==', -1.0);
+cmp_ok(round(cos($pi_2)), '==', 0.0);
+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.
End of Patch.