Austin Schuh | bb1338c | 2024-06-15 19:31:16 -0700 | [diff] [blame^] | 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 either: |
| 11 | # |
| 12 | # * the GNU Lesser General Public License as published by the Free |
| 13 | # Software Foundation; either version 3 of the License, or (at your |
| 14 | # option) any later version. |
| 15 | # |
| 16 | # or |
| 17 | # |
| 18 | # * the GNU General Public License as published by the Free Software |
| 19 | # Foundation; either version 2 of the License, or (at your option) any |
| 20 | # later version. |
| 21 | # |
| 22 | # or both in parallel, as here. |
| 23 | # |
| 24 | # The GNU MP Library is distributed in the hope that it will be useful, but |
| 25 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 26 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 27 | # for more details. |
| 28 | # |
| 29 | # You should have received copies of the GNU General Public License and the |
| 30 | # GNU Lesser General Public License along with the GNU MP Library. If not, |
| 31 | # see https://www.gnu.org/licenses/. |
| 32 | |
| 33 | use strict; |
| 34 | |
| 35 | |
| 36 | use GMP; |
| 37 | print "using GMP module $GMP::VERSION and GMP library ",GMP::version(),"\n"; |
| 38 | |
| 39 | |
| 40 | use GMP::Mpz qw(:all); |
| 41 | print "the 200th fibonacci number is ", fib(200), "\n"; |
| 42 | print "next prime after 10**30 is (probably) ", nextprime(mpz(10)**30), "\n"; |
| 43 | |
| 44 | |
| 45 | use GMP::Mpq qw(:constants); |
| 46 | print "the 7th harmonic number is ", 1+1/2+1/3+1/4+1/5+1/6+1/7, "\n"; |
| 47 | use GMP::Mpq qw(:noconstants); |
| 48 | |
| 49 | |
| 50 | use GMP::Mpf qw(mpf); |
| 51 | my $f = mpf(1,180); |
| 52 | $f >>= 180; |
| 53 | $f += 1; |
| 54 | print "a sample mpf is $f\n"; |