xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/bignum/t/bignum.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 => 20;
14*0Sstevel@tonic-gate  }
15*0Sstevel@tonic-gate
16*0Sstevel@tonic-gateuse bignum;
17*0Sstevel@tonic-gate
18*0Sstevel@tonic-gate###############################################################################
19*0Sstevel@tonic-gate# general tests
20*0Sstevel@tonic-gate
21*0Sstevel@tonic-gatemy $x = 5; ok (ref($x) =~ /^Math::BigInt/);		# :constant
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gateok (2 + 2.5,4.5);
24*0Sstevel@tonic-gate$x = 2 + 3.5; ok (ref($x),'Math::BigFloat');
25*0Sstevel@tonic-gateok (2 * 2.1,4.2);
26*0Sstevel@tonic-gate$x = 2 + 2.1; ok (ref($x),'Math::BigFloat');
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate$x = 2 ** 255; ok (ref($x) =~ /^Math::BigInt/);
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate# see if Math::BigInt constant and upgrading works
31*0Sstevel@tonic-gateok (Math::BigInt::bsqrt('12'),'3.464101615137754587054892683011744733886');
32*0Sstevel@tonic-gateok (sqrt(12),'3.464101615137754587054892683011744733886');
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gateok (2/3,"0.6666666666666666666666666666666666666667");
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate#ok (2 ** 0.5, 'NaN');	# should be sqrt(2);
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gateok (12->bfac(),479001600);
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate# see if Math::BigFloat constant works
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate#                     0123456789          0123456789	<- default 40
43*0Sstevel@tonic-gate#           0123456789          0123456789
44*0Sstevel@tonic-gateok (1/3, '0.3333333333333333333333333333333333333333');
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate###############################################################################
47*0Sstevel@tonic-gate# accurarcy and precision
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gateok_undef (bignum->accuracy());
50*0Sstevel@tonic-gateok (bignum->accuracy(12),12);
51*0Sstevel@tonic-gateok (bignum->accuracy(),12);
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gateok_undef (bignum->precision());
54*0Sstevel@tonic-gateok (bignum->precision(12),12);
55*0Sstevel@tonic-gateok (bignum->precision(),12);
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gateok (bignum->round_mode(),'even');
58*0Sstevel@tonic-gateok (bignum->round_mode('odd'),'odd');
59*0Sstevel@tonic-gateok (bignum->round_mode(),'odd');
60*0Sstevel@tonic-gate
61*0Sstevel@tonic-gate###############################################################################
62*0Sstevel@tonic-gate###############################################################################
63*0Sstevel@tonic-gate# Perl 5.005 does not like ok ($x,undef)
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gatesub ok_undef
66*0Sstevel@tonic-gate  {
67*0Sstevel@tonic-gate  my $x = shift;
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate  ok (1,1) and return if !defined $x;
70*0Sstevel@tonic-gate  ok ($x,'undef');
71*0Sstevel@tonic-gate  }
72