You are looking at historical revision 32807 of this page. It may differ significantly from its current revision.

Outdated egg!

This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for the CHICKEN 4 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

[[tags: egg]]

gmp

Description

A chicken scheme interface to GNU MP 4.1

Author

Peter Keller

Requirements

Requires the syntax-case egg.

Download

gmp.egg

Documentation

The library is split into several parts, which may be loaded/required separately:

gmp_utils
Utility procedures
gmp_integer
Integer routines
gmp_float
Float routines
gmp_rational
Rational arithmetic routines
gmp_random
Random numbers

The library used finalizers to free storage associated with unreferenced GMP data.

In addition to the library, a validation program will be built and installed, named chicken_gmp_test. To test the GMP extension just enter

 $ gmp_test

This is a release of the GNU MP library version 4.1 interface for chicken scheme. It is a pretty comprehensive interface, but without any of the lowlevel functions (mpn_*).

Since the validation code is pretty extensive, it shouldn't take too much work to fix when later revisions of the MP library comes out.

Example

Here is a tiny example of the interface usage:

(require-extension gmp)

(let (	(mpz1 (make-mpz_t))
		(mpz2 (make-mpz_t))
		(mpz3 (make-mpz_t)))

	(mpz_init mpz1)
	(mpz_init mpz2)
	(mpz_init mpz3)

	(mpz_set_ui mpz2 6)
	(mpz_set_str mpz3 "7" 10)
	(mpz_mul mpz1 mpz2 mpz3)

	(print 
		"The answer to " 
		(mpz_get_str #f 10 mpz2) 
		" times "
		(mpz_get_str #f 10 mpz3) 
		" is " 
		(mpz_get_str #f 10 mpz1) 
		".")
	
	(mpz_clear mpz1)
	(mpz_clear mpz2)
	(mpz_clear mpz3))

For the high level functions that I have not implemented: mpf_get_d_2exp mpz_array_init _mpz_realloc mpz_get_d_2exp mpz_getlimbm mpz_import mpz_export mpf_random2, there exists a function that will warn you to stdout when you accidentily use them.

Special functions

Here is an example of how the special function mpf_get_str is handled:

(let (	(mpf1 (make-mpf_t))
		(exp_p (make-mp_exp_t_p)))

	(mpf_init mpf1)
	(mpf_set_ui mpf1 42)

	;; get a string representation placing the exponent into exp_p
	(mpf_get_str #f exp_p 10 10 mpf1)

	;; The ONLY way to see the exponent is to dereference the "pointer"
	;; that is exp_p
	(print "The exponent is " (deref-mp_exp_t_p exp_p) ".")

	(mpf_clear mpf1))

Changelog

License

 Copyright (C) 2002 Peter K. Keller
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

All files in this package are copyrighted (C) 2002 Peter K. Keller regardless if they actually say it or not at the top of the file.