xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/bignum/t/bigint.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/usr/bin/perl -w
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate###############################################################################
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gateuse Test;
6*0Sstevel@tonic-gateuse strict;
7*0Sstevel@tonic-gate
8*0Sstevel@tonic-gateBEGIN
9*0Sstevel@tonic-gate  {
10*0Sstevel@tonic-gate  $| = 1;
11*0Sstevel@tonic-gate  chdir 't' if -d 't';
12*0Sstevel@tonic-gate  unshift @INC, '../lib';
13*0Sstevel@tonic-gate  plan tests => 32;
14*0Sstevel@tonic-gate  }
15*0Sstevel@tonic-gate
16*0Sstevel@tonic-gateuse bigint;
17*0Sstevel@tonic-gate
18*0Sstevel@tonic-gate###############################################################################
19*0Sstevel@tonic-gate# _constant tests
20*0Sstevel@tonic-gate
21*0Sstevel@tonic-gateforeach (qw/
22*0Sstevel@tonic-gate  123:123
23*0Sstevel@tonic-gate  123.4:123
24*0Sstevel@tonic-gate  1.4:1
25*0Sstevel@tonic-gate  0.1:0
26*0Sstevel@tonic-gate  -0.1:0
27*0Sstevel@tonic-gate  -1.1:-1
28*0Sstevel@tonic-gate  -123.4:-123
29*0Sstevel@tonic-gate  -123:-123
30*0Sstevel@tonic-gate  123e2:123e2
31*0Sstevel@tonic-gate  123e-1:12
32*0Sstevel@tonic-gate  123e-4:0
33*0Sstevel@tonic-gate  123e-3:0
34*0Sstevel@tonic-gate  123.345e-1:12
35*0Sstevel@tonic-gate  123.456e+2:12345
36*0Sstevel@tonic-gate  1234.567e+3:1234567
37*0Sstevel@tonic-gate  1234.567e+4:1234567E1
38*0Sstevel@tonic-gate  1234.567e+6:1234567E3
39*0Sstevel@tonic-gate  /)
40*0Sstevel@tonic-gate  {
41*0Sstevel@tonic-gate  my ($x,$y) = split /:/;
42*0Sstevel@tonic-gate  print "# Try $x\n";
43*0Sstevel@tonic-gate  ok (bigint::_constant("$x"),"$y");
44*0Sstevel@tonic-gate  }
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate###############################################################################
47*0Sstevel@tonic-gate# general tests
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gatemy $x = 5; ok (ref($x) =~ /^Math::BigInt/);		# :constant
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate# todo:  ok (2 + 2.5,4.5);				# should still work
52*0Sstevel@tonic-gate# todo: $x = 2 + 3.5; ok (ref($x),'Math::BigFloat');
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate$x = 2 ** 255; ok (ref($x) =~ /^Math::BigInt/);
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gateok (12->bfac(),479001600);
57*0Sstevel@tonic-gateok (9/4,2);
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gateok (4.5+4.5,8);					# truncate
60*0Sstevel@tonic-gateok (ref(4.5+4.5) =~ /^Math::BigInt/);
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate###############################################################################
64*0Sstevel@tonic-gate# accurarcy and precision
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gateok_undef (bigint->accuracy());
67*0Sstevel@tonic-gateok (bigint->accuracy(12),12);
68*0Sstevel@tonic-gateok (bigint->accuracy(),12);
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gateok_undef (bigint->precision());
71*0Sstevel@tonic-gateok (bigint->precision(12),12);
72*0Sstevel@tonic-gateok (bigint->precision(),12);
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gateok (bigint->round_mode(),'even');
75*0Sstevel@tonic-gateok (bigint->round_mode('odd'),'odd');
76*0Sstevel@tonic-gateok (bigint->round_mode(),'odd');
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gate###############################################################################
79*0Sstevel@tonic-gate###############################################################################
80*0Sstevel@tonic-gate# Perl 5.005 does not like ok ($x,undef)
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gatesub ok_undef
83*0Sstevel@tonic-gate  {
84*0Sstevel@tonic-gate  my $x = shift;
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate  ok (1,1) and return if !defined $x;
87*0Sstevel@tonic-gate  ok ($x,'undef');
88*0Sstevel@tonic-gate  }
89