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 => 12;
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(0);
50
51ok (cos($bf), cos(0));
52ok (sin($bf), sin(0));
53ok (exp($bf), exp(0));
54ok (atan2($bi,$bf), atan2(1,0));
55ok (atan2($bf,$bi), atan2(0,1));
56
57my $bone = Math::BigInt->new(1);
58ok (cos($bone), cos(1));
59ok (sin($bone), sin(1));
60ok (exp($bone), exp(1));
61
62