Upload Tizen:Base source
[external/gmp.git] / demos / perl / sample.pl
1 #!/usr/bin/perl -w
2
3 # Some sample GMP module operations
4
5 # Copyright 2001, 2004 Free Software Foundation, Inc.
6 #
7 # This file is part of the GNU MP Library.
8 #
9 # The GNU MP Library is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU Lesser General Public License as published
11 # by the Free Software Foundation; either version 3 of the License, or (at
12 # your option) any later version.
13 #
14 # The GNU MP Library is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17 # License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public License
20 # along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
21
22 use strict;
23
24
25 use GMP;
26 print "using GMP module $GMP::VERSION and GMP library ",GMP::version(),"\n";
27
28
29 use GMP::Mpz qw(:all);
30 print "the 200th fibonacci number is ", fib(200), "\n";
31 print "next prime after 10**30 is (probably) ", nextprime(mpz(10)**30), "\n";
32
33
34 use GMP::Mpq qw(:constants);
35 print "the 7th harmonic number is ", 1+1/2+1/3+1/4+1/5+1/6+1/7, "\n";
36 use GMP::Mpq qw(:noconstants);
37
38
39 use GMP::Mpf qw(mpf);
40 my $f = mpf(1,180);
41 $f >>= 180;
42 $f += 1;
43 print "a sample mpf is $f\n";