blob: 8a10ee1ebb213ddf5c7dd2fa51b80b8941428e6b [file] [log] [blame]
Austin Schuhbb1338c2024-06-15 19:31:16 -07001#!/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
33use strict;
34
35
36use GMP;
37print "using GMP module $GMP::VERSION and GMP library ",GMP::version(),"\n";
38
39
40use GMP::Mpz qw(:all);
41print "the 200th fibonacci number is ", fib(200), "\n";
42print "next prime after 10**30 is (probably) ", nextprime(mpz(10)**30), "\n";
43
44
45use GMP::Mpq qw(:constants);
46print "the 7th harmonic number is ", 1+1/2+1/3+1/4+1/5+1/6+1/7, "\n";
47use GMP::Mpq qw(:noconstants);
48
49
50use GMP::Mpf qw(mpf);
51my $f = mpf(1,180);
52$f >>= 180;
53$f += 1;
54print "a sample mpf is $f\n";