This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Rename a variable
[perl5.git] / t / op / exp.t
index a475502..5878f44 100644 (file)
@@ -4,11 +4,13 @@
 
 BEGIN {
     chdir 't' if -d 't';
-    @INC = '../lib';
     require './test.pl';
+    set_up_inc('../lib');
 }
 
-plan tests => 34;
+use Config;
+
+plan tests => 31;
 
 # compile time evaluation
 
@@ -78,10 +80,12 @@ is(substr($s,0,5), '0.693', 'run time log(2)');
 
 cmp_ok(exp(log($x1)), '==', 1, 'run time exp(log(1)) == 1');
 
-# tests for transcendental functions
+# NOTE: do NOT test the trigonometric functions at [+-]Pi
+# and expect to get exact results like 0, 1, -1, because
+# you may not be able to feed them exactly [+-]Pi given
+# all the variations of different long doubles.
 
-my $pi = 3.1415926535897931160;
-my $pi_2 = 1.5707963267948965580;
+my $pi_2 = 1.5707963267949;
 
 sub round {
    my $result = shift;
@@ -90,19 +94,15 @@ sub round {
 
 # sin() tests
 cmp_ok(sin(0), '==', 0.0, 'sin(0) == 0');
-cmp_ok(round(sin($pi)), '==', 0.0, 'sin(pi) == 0');
-cmp_ok(round(sin(-1 * $pi)), '==', 0.0, 'sin(-pi) == 0');
-cmp_ok(round(sin($pi_2)), '==', 1.0, 'sin(pi/2) == 1');
-cmp_ok(round(sin(-1 * $pi_2)), '==', -1.0, 'sin(-pi/2) == -1');
+cmp_ok(abs(sin($pi_2) - 1), '<', 1e-9, 'sin(pi/2) == 1');
+cmp_ok(abs(sin(-1 * $pi_2) - -1), '<', 1e-9, 'sin(-pi/2) == -1');
 
 cmp_ok(round(sin($x1)), '==', '0.841470985', "sin(1)");
 
 # cos() tests
 cmp_ok(cos(0), '==', 1.0, 'cos(0) == 1');
-cmp_ok(round(cos($pi)), '==', -1.0, 'cos(pi) == -1');
-cmp_ok(round(cos(-1 * $pi)), '==', -1.0, 'cos(-pi) == -1');
-cmp_ok(round(cos($pi_2)), '==', 0.0, 'cos(pi/2) == 0');
-cmp_ok(round(cos(-1 * $pi_2)), '==', 0.0, 'cos(-pi/2) == 0');
+cmp_ok(abs(cos($pi_2)), '<', 1e-9, 'cos(pi/2) == 0');
+cmp_ok(abs(cos(-1 * $pi_2)), '<', 1e-9, 'cos(-pi/2) == 0');
 
 cmp_ok(round(cos($x1)), '==', '0.540302306', "cos(1)");
 
@@ -111,3 +111,11 @@ cmp_ok(round(atan2($x1, $x2)), '==', '0.463647609', "atan2($x1, $x2)");
 # atan2() tests testing with -0.0, 0.0, -1.0, 1.0 were removed due to
 # differing results from calls to atan2() on various OS's and
 # architectures.  See perlport.pod for more information.
+
+SKIP: {
+    unless ($Config{usequadmath}) {
+        skip "need usequadmath", 1;
+    }
+    # For quadmath we have a known precision.  
+    is(sqrt(2), '1.4142135623730950488016887242097', "quadmath sqrt");
+}