xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Math/BigInt/t/fallback.t (revision 0:68f95e015346)
1#!/usr/bin/perl -w
2
3# test 'fallback' for overload cos/sin/atan2/exp
4
5use Test;
6use strict;
7
8BEGIN
9  {
10  $| = 1;
11  # to locate the testing files
12  my $location = $0; $location =~ s/fallback.t//i;
13  if ($ENV{PERL_CORE})
14    {
15    # testing with the core distribution
16    @INC = qw(../t/lib);
17    }
18  unshift @INC, qw(../lib);     # to locate the modules
19  if (-d 't')
20    {
21    chdir 't';
22    require File::Spec;
23    unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
24    }
25  else
26    {
27    unshift @INC, $location;
28    }
29  print "# INC = @INC\n";
30
31  plan tests => 8;
32  }
33
34# The tests below test that cos(BigInt) = cos(Scalar) which is DWIM, but not
35# exactly right, ideally cos(BigInt) should truncate to int() and cos(BigFLoat)
36# should calculate the result to X digits accuracy. For now, this is better
37# than die()ing...
38
39use Math::BigInt;
40use Math::BigFloat;
41
42my $bi = Math::BigInt->new(1);
43
44ok (cos($bi), cos(1));
45ok (sin($bi), sin(1));
46ok (exp($bi), exp(1));
47ok (atan2($bi,$bi), atan2(1,1));
48
49my $bf = Math::BigInt->new(1);
50
51ok (cos($bf), cos(1));
52ok (sin($bf), sin(1));
53ok (exp($bf), exp(1));
54ok (atan2($bf,$bf), atan2(1,1));
55
56