Import of GNU MP 2.0.2

This is a clean import with only the non-x86 bits removed. Makefiles and
other will follow.

Requested by:	Andrey Chernov
Made world by:	Chuck Robey
This commit is contained in:
markm 1996-10-20 08:09:18 +00:00
parent 7b57c06f48
commit d2329033b3
318 changed files with 46304 additions and 2090 deletions

481
gnu/lib/libgmp/COPYING.LIB Normal file
View File

@ -0,0 +1,481 @@
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,154 @@
Here is how to compile GNU MP.
INSTALLING GMP
==============
You probably want to use the GNU C compiler to build this library.
With other compilers the speed of the library will be 3-10 times
slower for many CPU:s. The reason for this is that the GNU C compiler
will use inline assembler for some important operations, while other C
compilers will have to stick to plain C code.
These instructions are only for the impatient. Others should read the install
instructions in the manual, gmp.info. Use "info -f gmp.info", or, if you
don't have info, use type "C-h i g (gmp.info)Top" in emacs.
This is how to build the library:
Here are short instructions how to install MP, and some examples that help you
get started using MP.
Type "make" to build libgmp.a and libmp.a. The former is the main
GNU MP library. The latter is the Berkeley MP compatible library.
First, you need to compile, and optionally install, MP. Since you're
impatient, try this:
If you don't have GCC, type "make CC=cc". The compilation should, at
least with GCC, proceed without any kind of warnings from the compiler
programs. On the DEC Alpha, you have to use GCC because of bugs in DEC's
own compiler. GCC 2.3.3 for x86, Alpha, and HP-PA has bugs that make
several functions be mis-optimized. Later version of GCC does not have
this problem.
./configure; make
To build and run the tests, do "make check".
If that fails, or you care about the performance of MP, you need to read the
full instructions in the chapter "Installing MP", in the manual.
The documentation is an a texinfo file, gmp.texi.
Next, you need to try some small test programs, for example the ones below.
To create the documentation from the texinfo source, type "make doc".
This requires the "tex" and "makeinfo" commands to be available in
your search path. If you have only one of them, you can create the
dvi file (for the paper manual) with "make gmp.dvi", and the info file
(for the GNU online manual facility) with "make gmp.info".
In MP programs, all variables need to be initialized before they are assigned,
and cleared out before program flow leaves the scope in which it was declared.
Here is an example of a program that reads two numbers from the command line,
multiplies them, and prints the result to stdout.
You need version 2.06 or later of texinfo in order to build the
documentation.
#include <stdio.h>
#include <gmp.h> /* All MP programs need to include gmp.h */
Please report problems to tege@gnu.ai.mit.edu.
main (int argc, char **argv)
{
mpz_t a, b, p;
/* Initialize variables */
mpz_init (a);
mpz_init (b);
mpz_init (p);
/* Assign a and b from base 10 strings in argv */
mpz_set_str (a, argv[1], 10);
mpz_set_str (b, argv[2], 10);
/* Multiply a and b and put the result in p */
mpz_mul (p, a, b);
/* Print p in base 10 */
mpz_out_str (stdout, 10, p);
fputc ('\n', stdout);
/* Clear out variables */
mpz_clear (a);
mpz_clear (b);
mpz_clear (p);
exit (0);
}
In practice, that example would be written like this instead:
#include <stdio.h>
#include <gmp.h>
main (int argc, char **argv)
{
mpz_t a, b, p;
/* Initialize and assign a and b from base 10 strings in argv */
mpz_init_set_str (a, argv[1], 10);
mpz_init_set_str (b, argv[2], 10);
/* Initialize p */
mpz_init (p);
/* Multiply a and b and put the result in p */
mpz_mul (p, a, b);
/* Print p in base 10 */
mpz_out_str (stdout, 10, p);
fputc ('\n', stdout);
/* Since we're about to exit, no need to clear out variables */
exit (0);
}
Finally, you have to compile your test program, and link it with the MP
library. Assuming your working directory is still the gmp source directory,
type:
gcc -g -I. example.c libgmp.a
Now try to run the example:
a.out 98365871231256752134 319378318340103345227
31415926535897932384618573336104570964418
The functions used here all operate on the domain of signed integers.
Functions operating on that domain have names starting with "mpz_". There are
many more such functions than used in these examples. See the chapter
"Integer Functions" in the manual, for a complete list.
There are two other main classes of functions in MP. They operate on rational
numbers and floating-point numbers, respectively. The chapters "Rational
Number Functions", and "Floating-point Functions" documents these classes.
To run a set of tests, do "make check". This will take a while.
To create the printable documentation from the texinfo source, type "make
dvi". This requires the "tex" command to be available in your search path.
To install the library, do "make install".
If you decide to use MP, It is a good idea you read at least the chapter "MP
Basics" in the manual.
Known Build Problems
--------------------
Note that GCC 2.7.2 (as well as 2.6.3) for the RS/6000 and PowerPC can not
be used to compile GMP, due to a bug in GCC. If you want to use GCC, you
need to apply the patch at the end of this file, or use a later version of
the compiler.
If you are on a Sequent Symmetry, use GAS instead of the system's assembler
due to the latter's serious bugs.
The system compiler on NeXT is a massacred and old gcc, even if the
compiler calls itself cc. This compiler cannot be used to build GMP. You
need to get a real gcc, and install that before you compile GMP. (NeXT
might have fixed this in newer releases of their system.)
Please report other problems to bug-gmp@prep.ai.mit.edu.
Patch to apply to GCC 2.6.3 and 2.7.2:
*** config/rs6000/rs6000.md Sun Feb 11 08:22:11 1996
--- config/rs6000/rs6000.md.new Sun Feb 18 03:33:37 1996
***************
*** 920,926 ****
(set (match_operand:SI 0 "gpc_reg_operand" "=r")
(not:SI (match_dup 1)))]
""
! "nor. %0,%2,%1"
[(set_attr "type" "compare")])
(define_insn ""
--- 920,926 ----
(set (match_operand:SI 0 "gpc_reg_operand" "=r")
(not:SI (match_dup 1)))]
""
! "nor. %0,%1,%1"
[(set_attr "type" "compare")])
(define_insn ""

210
gnu/lib/libgmp/Makefile.in Normal file
View File

@ -0,0 +1,210 @@
# Top Makefile for GNU MP
# Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc.
# This file is part of the GNU MP Library.
# The GNU MP Library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
# The GNU MP 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 Library General Public
# License for more details.
# You should have received a copy of the GNU Library General Public License
# along with the GNU MP Library; see the file COPYING.LIB. If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.
srcdir = .
prefix = /usr/local
exec_prefix = $(prefix)
libdir = $(exec_prefix)/lib
infodir = $(prefix)/info
includedir = $(prefix)/include
CC = gcc
LOCAL_CC = $(CC)
CFLAGS = -g -O
XCFLAGS =
AR = ar
AR_FLAGS = rc
RANLIB_TEST = [ -f /usr/bin/ranlib -o -f /bin/ranlib ]
RANLIB = ranlib
SHELL = /bin/sh
INSTALL = $(srcdir)/install.sh -c
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL)
MAKEINFO = makeinfo
MAKEINFOFLAGS =
TEXI2DVI = texi2dvi
LN = ln -s
#### host and target specific makefile fragments come in here.
###
SRCS = memory.c mp_set_fns.c mp_clz_tab.c version.c stack-alloc.c mp_bpl.c \
extract-double.c insert-double.c
OBJS = memory.o mp_set_fns.o mp_clz_tab.o version.o stack-alloc.o mp_bpl.o \
extract-double.o insert-double.o
FILES = gmp.h mp.h gmp-impl.h longlong.h urandom.h move-if-change \
mkinstalldirs INSTALL COPYING.LIB ChangeLog Makefile.in \
NEWS README SPEED TODO config.guess config.sub configure configure.in \
gmp.info* gmp.texi texinfo.tex $(SRCS)
INCLUDES = -I. -Impn -I$(srcdir)
FLAGS_TO_PASS = "CC=$(CC)" "CFLAGS=$(CFLAGS)" "XCFLAGS=$(XCFLAGS)"
all: libgmp.a
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $(XCFLAGS) $<
libgmp.a: mpn/libmpn.a mpz/libmpz.a mpf/libmpf.a mpq/libmpq.a $(OBJS)
rm -rf tmpdir
mkdir tmpdir
for i in mpn mpz mpf mpq; \
do \
mkdir tmpdir/$$i; \
( cd tmpdir/$$i; $(AR) x ../../$$i/lib$$i.a ); \
done
cp $(OBJS) tmpdir
cd tmpdir; $(AR) $(AR_FLAGS) $@ *.o */*.o
if $(RANLIB_TEST) ; then $(RANLIB) tmpdir/$@; else true; fi
mv tmpdir/$@ .
rm -rf tmpdir
libmp.a: mpn/libmpn.a mpbsd/libmpbsd.a $(OBJS)
rm -rf tmpdir
mkdir tmpdir
for i in mpn mpbsd; \
do \
mkdir tmpdir/$$i; \
( cd tmpdir/$$i; $(AR) x ../../$$i/lib$$i.a ); \
done
cp $(OBJS) tmpdir
cd tmpdir; $(AR) $(AR_FLAGS) $@ *.o */*.o
if $(RANLIB_TEST) ; then $(RANLIB) tmpdir/$@; else true; fi
mv tmpdir/$@ .
rm -rf tmpdir
mpn/libmpn.a: force
cd mpn; $(MAKE) $(FLAGS_TO_PASS) libmpn.a
mpz/libmpz.a: force
cd mpz; $(MAKE) $(FLAGS_TO_PASS) libmpz.a
mpf/libmpf.a: force
cd mpf; $(MAKE) $(FLAGS_TO_PASS) libmpf.a
mpq/libmpq.a: force
cd mpq; $(MAKE) $(FLAGS_TO_PASS) libmpq.a
mpbsd/libmpbsd.a: force
cd mpbsd; $(MAKE) $(FLAGS_TO_PASS) libmpbsd.a
check: libgmp.a
cd mpz/tests; $(MAKE) $(FLAGS_TO_PASS) check
cd mpq/tests; $(MAKE) $(FLAGS_TO_PASS) check
cd mpf/tests; $(MAKE) $(FLAGS_TO_PASS) check
doc: gmp.dvi gmp.info
info: $(srcdir)/gmp.info
$(srcdir)/gmp.info: $(srcdir)/gmp.texi
cd $(srcdir); $(MAKEINFO) gmp.texi
dvi: gmp.dvi
gmp.dvi: $(srcdir)/gmp.texi
rm -f tmp.texi
$(LN) $(srcdir)/gmp.texi tmp.texi
TEXINPUTS=.:$(srcdir) $(TEXI2DVI) tmp.texi
rm -f tmp.texi
mv tmp.dvi gmp.dvi
rm -f tmp.*
ps: gmp.ps
gmp.ps: gmp.dvi
dvips gmp.dvi -o gmp.ps
html: gmp_toc.html
gmp_toc.html: $(srcdir)/gmp.texi
texi2html -acc -split_chapter $(srcdir)/gmp.texi
# The semicolon is to prevent the install.sh -> install default rule
# from doing anything. Having it run true helps avoid problems and
# noise from versions of make which don't like to have null commands.
install: install-normal ; @true
install-strip: install-normal
install-normal: installdirs libgmp.a gmp.info install-info-files
$(INSTALL_DATA) libgmp.a $(libdir)/libgmp.a
-chmod a-x $(libdir)/libgmp.a
$(INSTALL_DATA) $(srcdir)/gmp.h $(includedir)/gmp.h
-chmod a-x $(includedir)/gmp.h
install-bsdmp: installdirs libmp.a gmp.info install-info-files
$(INSTALL_DATA) libmp.a $(libdir)/libmp.a
-chmod a-x $(libdir)/libmp.a
$(INSTALL_DATA) $(srcdir)/mp.h $(includedir)/mp.h
-chmod a-x $(includedir)/mp.h
install-info-files: installdirs $(srcdir)/gmp.info
cd $(srcdir); for f in gmp.info*; \
do $(INSTALL_DATA) $$f $(infodir)/$$f; done
-chmod a-x $(infodir)/gmp.info*
# Attempt to edit the info directory node
if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
install-info --dir-file=$(infodir)/dir $(infodir)/gmp.info; \
else true; fi
installdirs: $(srcdir)/mkinstalldirs
$(srcdir)/mkinstalldirs $(includedir) $(libdir) $(infodir)
uninstall:
rm -f $(libdir)/libgmp.a
rm -f $(includedir)/gmp.h
rm -f $(libdir)/libmp.a
rm -f $(includedir)/mp.h
rm -f $(infodir)/gmp.info*
clean mostlyclean:
rm -f *.o libgmp.a libmp.a gmp.dvi gmp.ps tmp.* tmp-*
rm -f gmp.?? gmp.??s gmp.log gmp.toc gmp.*aux gmp*.html
-cd mpn; $(MAKE) $@
-cd mpz; $(MAKE) $@
-cd mpf; $(MAKE) $@
-cd mpq; $(MAKE) $@
-cd mpbsd; $(MAKE) $@
distclean: clean
rm -f Makefile config.status
-cd mpn; $(MAKE) $@
-cd mpz; $(MAKE) $@
-cd mpf; $(MAKE) $@
-cd mpq; $(MAKE) $@
-cd mpbsd; $(MAKE) $@
maintainer-clean: distclean
rm -f $(srcdir)/gmp.info*
TAGS: force
cd $(srcdir); etags *.[ch] mp*/*.c mpn/generic/*.c >TAGS
dist:
@echo "sorry, not supported target"
@exit 1
Makefile: $(srcdir)/Makefile.in $(host_makefile_frag) $(target_makefile_frag)
$(SHELL) ./config.status
H = $(srcdir)/gmp.h $(srcdir)/gmp-impl.h mpn/gmp-mparam.h
extract-double.o: $(srcdir)/extract-double.c $(H)
insert-double.o: $(srcdir)/insert-double.c $(H)
memory.o: $(srcdir)/memory.c $(H)
mp_bpl.o: $(srcdir)/mp_bpl.c
mp_clz_tab.o: $(srcdir)/mp_clz_tab.c
mp_set_fns.o: $(srcdir)/mp_set_fns.c $(H)
stack-alloc.o: $(srcdir)/stack-alloc.c $(srcdir)/stack-alloc.h
version.o: $(srcdir)/version.c
force:
.PNONY: check install install-bsdmp install-info-files install-strip uninstall
.PHONY: doc clean distclean maintainer-clean force info dvi

56
gnu/lib/libgmp/NEWS Normal file
View File

@ -0,0 +1,56 @@
NOTEWORTHY CHANGES IN GNU MP IN VERSION 2
* Division routines in the mpz class have changed. There are three classes of
functions, that rounds the quotient to -infinity, 0, and +infinity,
respectively. The first class of functions have names that begin with
mpz_fdiv (f is short for floor), the second class' names begin with mpz_tdiv
(t is short for trunc), and the third class' names begin with mpz_cdiv (c is
short for ceil).
The old division routines beginning with mpz_m are similar to the new
mpz_fdiv, with the exception that some of the new functions return useful
values.
The old function names can still be used. All the old functions names will
now do floor division, not trunc division as some of them used to. This was
changed to make the functions more compatible with common mathematical
practice.
The mpz_mod and mpz_mod_ui functions now compute the mathematical mod
function. I.e., the sign of the 2nd argument is ignored.
* The mpq assignment functions do not canonicalize their results. A new
function, mpq_canonicalize must be called by the user if the result is not
known to be canonical.
* The mpn functions are now documented. These functions are intended for
very time critical applications, or applications that need full control over
memory allocation. Note that the mpn interface is irregular and hard to
use.
* New functions for arbitrary precision floating point arithmetic. Names
begin with `mpf_'. Associated type mpf_t.
* New and improved mpz functions, including much faster GCD, fast exact
division (mpz_divexact), bit scan (mpz_scan0 and mpz_scan1), and number
theoretical functions like Jacobi (mpz_jacobi) and multiplicative inverse
(mpz_invert).
* New variable types (mpz_t and mpq_t) are available that makes syntax of
mpz and mpq calls nicer (no need for & before variables). The MP_INT and
MP_RAT types are still available for compatibility.
* Uses GNU configure. This makes it possible to choose target architecture
and CPU variant, and to compile into a separate object directory.
* Carefully optimized assembly for important inner loops. Support for DEC
Alpha, Amd 29000, HPPA 1.0 and 1.1, Intel pentium and generic x86, Intel
i960, Motorola MC68000, MC68020, MC88100, and MC88110, Motorola/IBM
PowerPC, National NS32000, IBM POWER, MIPS R3000, R4000, SPARCv7,
SuperSPARC, generic SPARCv8, and DEC VAX. Some support also for ARM,
Clipper, IBM ROMP (RT), and Pyramid AP/XP.
* Faster. Thanks to the assembler code, new algorithms, and general tuning.
In particular, the speed on machines without GCC is improved.
* Support for machines without alloca.
* Now under the LGPL.
INCOMPATIBILITIES BETWEEN GMP 1 AND GMP 2
* mpq assignment functions do not canonicalize their results.
* mpz division functions round differently.
* mpz mod functions now really compute mod.
* mpz_powm and mpz_powm_ui now really use mod for reduction.

270
gnu/lib/libgmp/PROJECTS Normal file
View File

@ -0,0 +1,270 @@
IDEAS ABOUT THINGS TO WORK ON
* mpq_cmp: Maybe the most sensible thing to do would be to multiply the, say,
4 most significant limbs of each operand and compare them. If that is not
sufficient, do the same for 8 limbs, etc.
* Write mpi, the Multiple Precision Interval Arithmetic layer.
* Write `mpX_eval' that take lambda-like expressions and a list of operands.
* As a general rule, recognize special operand values in mpz and mpf, and
use shortcuts for speed. Examples: Recognize (small or all) 2^n in
multiplication and division. Recognize small bases in mpz_pow_ui.
* Implement lazy allocation? mpz->d == 0 would mean no allocation made yet.
* Maybe store one-limb numbers according to Per Bothner's idea:
struct {
mp_ptr d;
union {
mp_limb val; /* if (d == NULL). */
mp_size size; /* Length of data array, if (d != NULL). */
} u;
};
Problem: We can't normalize to that format unless we free the space
pointed to by d, and therefore small values will not be stored in a
canonical way.
* Document complexity of all functions.
* Add predicate functions mpz_fits_signedlong_p, mpz_fits_unsignedlong_p,
mpz_fits_signedint_p, etc.
mpz_floor (mpz, mpq), mpz_trunc (mpz, mpq), mpz_round (mpz, mpq).
* Better random number generators. There should be fast (like mpz_random),
very good (mpz_veryrandom), and special purpose (like mpz_random2). Sizes
in *bits*, not in limbs.
* It'd be possible to have an interface "s = add(a,b)" with automatic GC.
If the mpz_xinit routine remembers the address of the variable we could
walk-and-mark the list of remembered variables, and free the space
occupied by the remembered variables that didn't get marked. Fairly
standard.
* Improve speed for non-gcc compilers by defining umul_ppmm, udiv_qrnnd,
etc, to call __umul_ppmm, __udiv_qrnnd. A typical definition for
umul_ppmm would be
#define umul_ppmm(ph,pl,m0,m1) \
{unsigned long __ph; (pl) = __umul_ppmm (&__ph, (m0), (m1)); (ph) = __ph;}
In order to maintain just one version of longlong.h (gmp and gcc), this
has to be done outside of longlong.h.
Bennet Yee at CMU proposes:
* mpz_{put,get}_raw for memory oriented I/O like other *_raw functions.
* A function mpfatal that is called for exceptions. Let the user override
a default definition.
* Make all computation mpz_* functions return a signed int indicating if the
result was zero, positive, or negative?
* Implement mpz_cmpabs, mpz_xor, mpz_to_double, mpz_to_si, mpz_lcm, mpz_dpb,
mpz_ldb, various bit string operations. Also mpz_@_si for most @??
* Add macros for looping efficiently over a number's limbs:
MPZ_LOOP_OVER_LIMBS_INCREASING(num,limb)
{ user code manipulating limb}
MPZ_LOOP_OVER_LIMBS_DECREASING(num,limb)
{ user code manipulating limb}
Brian Beuning proposes:
1. An array of small primes
3. A function to factor a mpz_t. [How do we return the factors? Maybe
we just return one arbitrary factor? In the latter case, we have to
use a data structure that records the state of the factoring routine.]
4. A routine to look for "small" divisors of an mpz_t
5. A 'multiply mod n' routine based on Montgomery's algorithm.
Dough Lea proposes:
1. A way to find out if an integer fits into a signed int, and if so, a
way to convert it out.
2. Similarly for double precision float conversion.
3. A function to convert the ratio of two integers to a double. This
can be useful for mixed mode operations with integers, rationals, and
doubles.
Elliptic curve method description in the Chapter `Algorithms in Number
Theory' in the Handbook of Theoretical Computer Science, Elsevier,
Amsterdam, 1990. Also in Carl Pomerance's lecture notes on Cryptology and
Computational Number Theory, 1990.
* Harald Kirsh suggests:
mpq_set_str (MP_RAT *r, char *numerator, char *denominator).
* New function: mpq_get_ifstr (int_str, frac_str, base,
precision_in_som_way, rational_number). Convert RATIONAL_NUMBER to a
string in BASE and put the integer part in INT_STR and the fraction part
in FRAC_STR. (This function would do a division of the numerator and the
denominator.)
* Should mpz_powm* handle negative exponents?
* udiv_qrnnd: If the denominator is normalized, the n0 argument has very
little effect on the quotient. Maybe we can assume it is 0, and
compensate at a later stage?
* Better sqrt: First calculate the reciprocal square root, then multiply by
the operand to get the square root. The reciprocal square root can be
obtained through Newton-Raphson without division. To compute sqrt(A), the
iteration is,
2
x = x (3 - A x )/2.
i+1 i i
The final result can be computed without division using,
sqrt(A) = A x .
n
* Newton-Raphson using multiplication: We get twice as many correct digits
in each iteration. So if we square x(k) as part of the iteration, the
result will have the leading digits in common with the entire result from
iteration k-1. A _mpn_mul_lowpart could help us take advantage of this.
* Peter Montgomery: If 0 <= a, b < p < 2^31 and I want a modular product
a*b modulo p and the long long type is unavailable, then I can write
typedef signed long slong;
typedef unsigned long ulong;
slong a, b, p, quot, rem;
quot = (slong) (0.5 + (double)a * (double)b / (double)p);
rem = (slong)((ulong)a * (ulong)b - (ulong)p * (ulong)quot);
if (rem < 0} {rem += p; quot--;}
* Speed modulo arithmetic, using Montgomery's method or my pre-inversion
method. In either case, special arithmetic calls would be needed,
mpz_mmmul, mpz_mmadd, mpz_mmsub, plus some kind of initialization
functions. Better yet: Write a new mpr layer.
* mpz_powm* should not use division to reduce the result in the loop, but
instead pre-compute the reciprocal of the MOD argument and do reduced_val
= val-val*reciprocal(MOD)*MOD, or use Montgomery's method.
* mpz_mod_2expplussi -- to reduce a bignum modulo (2**n)+s
* It would be a quite important feature never to allocate more memory than
really necessary for a result. Sometimes we can achieve this cheaply, by
deferring reallocation until the result size is known.
* New macro in longlong.h: shift_rhl that extracts a word by shifting two
words as a unit. (Supported by i386, i860, HP-PA, POWER, 29k.) Useful
for shifting multiple precision numbers.
* The installation procedure should make a test run of multiplication to
decide the threshold values for algorithm switching between the available
methods.
* Fast output conversion of x to base B:
1. Find n, such that (B^n > x).
2. Set y to (x*2^m)/(B^n), where m large enough to make 2^n ~~ B^n
3. Multiply the low half of y by B^(n/2), and recursively convert the
result. Truncate the low half of y and convert that recursively.
Complexity: O(M(n)log(n))+O(D(n))!
* Improve division using Newton-Raphson. Check out "Newton Iteration and
Integer Division" by Stephen Tate in "Synthesis of Parallel Algorithms",
Morgan Kaufmann, 1993 ("beware of some errors"...)
* Improve implementation of Karatsuba's algorithm. For most operand sizes,
we can reduce the number of operations by splitting differently.
* Faster multiplication: The best approach is to first implement Toom-Cook.
People report that it beats Karatsuba's algorithm already at about 100
limbs. FFT would probably never beat a well-written Toom-Cook (not even for
millions of bits).
FFT:
{
* Multiplication could be done with Montgomery's method combined with
the "three primes" method described in Lipson. Maybe this would be
faster than to Nussbaumer's method with 3 (simple) moduli?
* Maybe the modular tricks below are not needed: We are using very
special numbers, Fermat numbers with a small base and a large exponent,
and maybe it's possible to just subtract and add?
* Modify Nussbaumer's convolution algorithm, to use 3 words for each
coefficient, calculating in 3 relatively prime moduli (e.g.
0xffffffff, 0x100000000, and 0x7fff on a 32-bit computer). Both all
operations and CRR would be very fast with such numbers.
* Optimize the Schoenhage-Stassen multiplication algorithm. Take advantage
of the real valued input to save half of the operations and half of the
memory. Use recursive FFT with large base cases, since recursive FFT has
better memory locality. A normal FFT get 100% cache misses for large
enough operands.
* In the 3-prime convolution method, it might sometimes be a win to use 2,
3, or 5 primes. Imagine that using 3 primes would require a transform
length of 2^n. But 2 primes might still sometimes give us correct
results with that same transform length, or 5 primes might allow us to
decrease the transform size to 2^(n-1).
To optimize floating-point based complex FFT we have to think of:
1. The normal implementation accesses all input exactly once for each of
the log(n) passes. This means that we will get 0% cache hit when n >
our cache. Remedy: Reorganize computation to compute partial passes,
maybe similar to a standard recursive FFT implementation. Use a large
`base case' to make any extra overhead of this organization negligible.
2. Use base-4, base-8 and base-16 FFT instead of just radix-2. This can
reduce the number of operations by 2x.
3. Inputs are real-valued. According to Knuth's "Seminumerical
Algorithms", exercise 4.6.4-14, we can save half the memory and half
the operations if we take advantage of that.
4. Maybe make it possible to write the innermost loop in assembly, since
that could win us another 2x speedup. (If we write our FFT to avoid
cache-miss (see #1 above) it might be logical to write the `base case'
in assembly.)
5. Avoid multiplication by 1, i, -1, -i. Similarly, optimize
multiplication by (+-\/2 +- i\/2).
6. Put as many bits as possible in each double (but don't waste time if
that doesn't make the transform size become smaller).
7. For n > some large number, we will get accuracy problems because of the
limited precision of our floating point arithmetic. This can easily be
solved by using the Karatsuba trick a few times until our operands
become small enough.
8. Precompute the roots-of-unity and store them in a vector.
}
* When a division result is going to be just one limb, (i.e. nsize-dsize is
small) normalization could be done in the division loop.
* Never allocate temporary space for a source param that overlaps with a
destination param needing reallocation. Instead malloc a new block for
the destination (and free the source before returning to the caller).
* Parallel addition. Since each processors have to tell it is ready to the
next processor, we can use simplified synchronization, and actually write
it in C: For each processor (apart from the least significant):
while (*svar != my_number)
;
*svar = my_number + 1;
The least significant processor does this:
*svar = my_number + 1; /* i.e., *svar = 1 */
Before starting the addition, one processor has to store 0 in *svar.
Other things to think about for parallel addition: To avoid false
(cache-line) sharing, allocate blocks on cache-line boundaries.
Local Variables:
mode: text
fill-column: 77
fill-prefix: " "
version-control: never
End:

View File

@ -1,61 +1,137 @@
THE GNU MP LIBRARY
GNU MP is a library for arbitrary precision arithmetic, operating on
signed integers and rational numbers. It has a rich set of functions,
and the functions have a regular interface.
GNU MP is a library for arbitrary precision arithmetic, operating on signed
integers, rational numbers, and floating point numbers. It has a rich set
of functions, and the functions have a regular interface.
I have tried to make these functions as fast as possible, both for small
operands and for huge operands. The speed is achieved by using fullwords
as the basic arithmetic type, by using fast algorithms, by defining inline
assembler for mixed sized multiplication and division (i.e 32*32->64 bit
multiplication and 64/32->32,32 bit division), and by hacking the code
with emphasis on speed (and not simplicity and elegance).
GNU MP is designed to be as fast as possible, both for small operands and for
huge operands. The speed is achieved by using fullwords as the basic
arithmetic type, by using fast algorithms, by carefully optimized assembly
code for the most common inner loops for a lots of CPUs, and by a general
emphasis on speed (instead of simplicity or elegance).
The speed of GNU MP is about 5 to 100 times that of Berkeley MP for
small operands. The speed-up increases with the operand sizes for
certain operations, for which GNU MP has asymptotically faster algorithms.
The speed of GNU MP is believed to be faster than any other similar library.
The advantage for GNU MP increases with the operand sizes for certain
operations, since GNU MP in many cases has asymptotically faster algorithms.
There are four classes of functions in GNU MP.
GETTING STARTED
1. Signed integer arithmetic functions, mpz_*. The set of functions are
intended to be easy to use, being rich and regular.
First, you have to configure and compiler GNU MP. Simply typing
To use these functions, include the file "gmp.h".
./configure; make
will normally do a reasonable job, but will not give optimal library
execution speed. So unless you're very unpatient, please read the detailed
instructions in the file INSTALL or in gmp.texi.
Once you have compiled the library, you should write some small example, and
make sure you can compile them. A typical compilation command is this:
gcc -g your-file.c -I<gmp-source-dir> <gmp-bin-dir>libgmp.a -lm
If you have installed the library, you can simply do:
gcc -g your-file.c -lgmp -lm
The -lm is normally not needed, since only a few functions in GNU MP use the
math library.
Here is a sample program that declares 2 variables, initializes them as
required, and sets one of them from a signed integer, and the other from a
string of digits. It then prints the product of the two numbers in base 10.
#include <stdio.h>
#include "gmp.h"
main ()
{
mpz_t a, b, p;
mpz_init (a); /* initialize variables */
mpz_init (b);
mpz_init (p);
mpz_set_si (a, 756839); /* assign variables */
mpz_set_str (b, "314159265358979323846", 0);
mpz_mul (p, a, b); /* generate product */
mpz_out_str (stdout, 10, p); /* print number without newline */
puts (""); /* print newline */
mpz_clear (a); /* clear out variables */
mpz_clear (b);
mpz_clear (p);
exit (0);
}
This might look tedious, with all initializing and clearing. Fortunately
some of these operations can be combined, and other operations can often be
avoided. The example above would be written differently by an experienced
GNU MP user:
#include <stdio.h>
#include "gmp.h"
main ()
{
mpz_t b, p;
mpz_init (p);
mpz_init_set_str (b, "314159265358979323846", 0);
mpz_mul_ui (p, b, 756839); /* generate product */
mpz_out_str (stdout, 10, p); /* print number without newline */
puts (""); /* print newline */
exit (0);
}
OVERVIEW OF GNU MP
There are five classes of functions in GNU MP.
1. Signed integer arithmetic functions, mpz_*. These functions are intended
to be easy to use, with their regular interface. The associated type is
`mpz_t'.
2. Rational arithmetic functions, mpq_*. For now, just a small set of
functions necessary for basic rational arithmetics.
functions necessary for basic rational arithmetics. The associated type
is `mpq_t'.
To use these functions, include the file "gmp.h".
3. Floating-point arithmetic functions, mpf_*. If the C type `double'
doesn't give enough precision for your application, declare your
variables as `mpf_t' instead, set the precision to any number desired,
and call the functions in the mpf class for the arithmetic operations.
3. Positive-integer, low-level, harder-to-use, but for small operands
about twice as fast than the mpz_* functions are the functions in the
mpn_* class. No memory management is performed. The caller must
ensure enough space is available for the results. The set of
functions is not quite regular, nor is the calling interface. These
functions accept input arguments in the form of pairs consisting of a
pointer to the least significant word, and a integral size telling how
many limbs (= words) the pointer points to.
4. Positive-integer, hard-to-use, very low overhead functions are in the
mpn_* class. No memory management is performed. The caller must ensure
enough space is available for the results. The set of functions is not
regular, nor is the calling interface. These functions accept input
arguments in the form of pairs consisting of a pointer to the least
significant word, and a integral size telling how many limbs (= words)
the pointer points to.
Almost all calculations, in the entire package, are made in these
Almost all calculations, in the entire package, are made by calling these
low-level functions.
These functions are not fully documented in this release. They will
probably be so in a future release.
5. Berkeley MP compatible functions.
4. Berkeley MP compatible functions.
To use these functions, include the file "mp.h". You can test if you are
using the GNU version by testing if the symbol __GNU_MP__ is defined.
To use these functions, include the file "mp.h". You can test if you
are using the GNU version by testing if the symbol __GNU_MP__ is
defined.
For more information on how to use GNU MP, please refer to the documentation.
It is composed from the file gmp.texi, and can be displayed on the screen or
printed. How to do that, as well how to build the library, is described in
the INSTALL file in this directory.
REPORTING BUGS
If you find a bug in the library, please make sure to tell us about it!
You can report bugs, and propose modifications and enhancements to
tege@gnu.ai.mit.edu. How to report a bug is further described in
the texinfo documentation, see the file gmp.texi.
Report bugs and propose modifications and enhancements to
bug-gmp@prep.ai.mit.edu. What information is needed in a good bug report is
described in the manual.

156
gnu/lib/libgmp/SPEED Normal file
View File

@ -0,0 +1,156 @@
==============================================================================
Cycle counts and throughput for low-level routines in GNU MP as currently
implemented.
A range means that the timing is data-dependent. The slower number of such
an interval is usually the best performance estimate.
The throughput value, measured in Gb/s (gigabits per second) has a meaning
only for comparison between CPUs.
A star before a line means that all values on that line are estimates. A
star before a number means that that number is an estimate. A `p' before a
number means that the code is not complete, but the timing is believed to be
accurate.
| mpn_lshift mpn_add_n mpn_mul_1 mpn_addmul_1
| mpn_rshift mpn_sub_n mpn_submul_1
------------+-----------------------------------------------------------------
DEC/Alpha |
EV4 | 4.75 cycles/64b 7.75 cycles/64b 42 cycles/64b 42 cycles/64b
200MHz | 2.7 Gb/s 1.65 Gb/s 20 Gb/s 20 Gb/s
EV5 old code| 4.0 cycles/64b 5.5 cycles/64b 18 cycles/64b 18 cycles/64b
267MHz | 4.27 Gb/s 3.10 Gb/s 61 Gb/s 61 Gb/s
417MHz | 6.67 Gb/s 4.85 Gb/s 95 Gb/s 95 Gb/s
EV5 tuned | 3.25 cycles/64b 4.75 cycles/64b
267MHz | 5.25 Gb/s 3.59 Gb/s as above
417MHz | 8.21 Gb/s 5.61 Gb/s
------------+-----------------------------------------------------------------
Sun/SPARC |
SPARC v7 | 14.0 cycles/32b 8.5 cycles/32b 37-54 cycl/32b 37-54 cycl/32b
SuperSPARC | 3 cycles/32b 2.5 cycles/32b 8.2 cycles/32b 10.8 cycles/32b
50MHz | 0.53 Gb/s 0.64 Gb/s 6.2 Gb/s 4.7 Gb/s
**SuperSPARC| tuned addmul and submul will take: 9.25 cycles/32b
MicroSPARC2 | ? 6.65 cycles/32b 30 cycles/32b 31.5 cycles/32b
110MHz | ? 0.53 Gb/s 3.75 Gb/s 3.58 Gb/s
SuperSPARC2 | ? ? ? ?
Ultra/32 (4)| 2.5 cycles/32b 6.5 cycles/32b 13-27 cyc/32b 16-30 cyc/32b
182MHz | 2.33 Gb/s 0.896 Gb/s 14.3-6.9 Gb/s
Ultra/64 (5)| 2.5 cycles/64b 10 cycles/64b 40-70 cyc/64b 46-76 cyc/64b
182MHz | 4.66 Gb/s 1.16 Gb/s 18.6-11 Gb/s
HalSPARC64 | ? ? ? ?
------------+-----------------------------------------------------------------
SGI/MIPS |
R3000 | 6 cycles/32b 9.25 cycles/32b 16 cycles/32b 16 cycles/32b
40MHz | 0.21 Gb/s 0.14 Gb/s 2.56 Gb/s 2.56 Gb/s
R4400/32 | 8.6 cycles/32b 10 cycles/32b 16-18 19-21
200MHz | 0.74 Gb/s 0.64 Gb/s 13-11 Gb/s 11-9.6 Gb/s
*R4400/64 | 8.6 cycles/64b 10 cycles/64b 22 cycles/64b 22 cycles/64b
*200MHz | 1.48 Gb/s 1.28 Gb/s 37 Gb/s 37 Gb/s
R4600/32 | 6 cycles/64b 9.25 cycles/32b 15 cycles/32b 19 cycles/32b
134MHz | 0.71 Gb/s 0.46 Gb/s 9.1 Gb/s 7.2 Gb/s
R4600/64 | 6 cycles/64b 9.25 cycles/64b ? ?
134MHz | 1.4 Gb/s 0.93 Gb/s ? ?
R8000/64 | 3 cycles/64b 4.6 cycles/64b 8 cycles/64b 8 cycles/64b
75MHz | 1.6 Gb/s 1.0 Gb/s 38 Gb/s 38 Gb/s
*R10000/64 | 2 cycles/64b 3 cycles/64b 11 cycles/64b 11 cycles/64b
*200MHz | 6.4 Gb/s 4.27 Gb/s 74 Gb/s 74 Gb/s
*250MHz | 8.0 Gb/s 5.33 Gb/s 93 Gb/s 93 Gb/s
------------+-----------------------------------------------------------------
Motorola |
MC68020 | ? 24 cycles/32b 62 cycles/32b 70 cycles/32b
MC68040 | ? 6 cycles/32b 24 cycles/32b 25 cycles/32b
MC88100 | >5 cycles/32b 4.6 cycles/32b 16/21 cyc/32b p 18/23 cyc/32b
MC88110 wt | ? 3.75 cycles/32b 6 cycles/32b 8.5 cyc/32b
*MC88110 wb | ? 2.25 cycles/32b 4 cycles/32b 5 cycles/32b
------------+-----------------------------------------------------------------
HP/PA-RISC |
PA7000 | 4 cycles/32b 5 cycles/32b 9 cycles/32b 11 cycles/32b
67MHz | 0.53 Gb/s 0.43 Gb/s 7.6 Gb/s 6.2 Gb/s
PA7100 | 3.25 cycles/32b 4.25 cycles/32b 7 cycles/32b 8 cycles/32b
99MHz | 0.97 Gb/s 0.75 Gb/s 14 Gb/s 12.8 Gb/s
PA7100LC | ? ? ? ?
PA7200 (3) | 3 cycles/32b 4 cycles/32b 7 cycles/32b 6.5 cycles/32b
100MHz | 1.07 Gb/s 0.80 14 Gb/s 15.8 Gb/s
PA7300LC | ? ? ? ?
*PA8000 | 3 cycles/64b 4 cycles/64b 7 cycles/64b 6.5 cycles/64b
180MHz | 3.84 Gb/s 2.88 Gb/s 105 Gb/s 113 Gb/s
------------+-----------------------------------------------------------------
Intel/x86 |
386DX | 20 cycles/32b 17 cycles/32b 41-70 cycl/32b 50-79 cycl/32b
16.7MHz | 0.027 Gb/s 0.031 Gb/s 0.42-0.24 Gb/s 0.34-0.22 Gb/s
486DX | ? ? ? ?
486DX4 | 9.5 cycles/32b 9.25 cycles/32b 17-23 cycl/32b 20-26 cycl/32b
100MHz | 0.34 Gb/s 0.35 Gb/s 6.0-4.5 Gb/s 5.1-3.9 Gb/s
Pentium | 2/6 cycles/32b 2.5 cycles/32b 13 cycles/32b 14 cycles/32b
167MHz | 2.7/0.89 Gb/s 2.1 Gb/s 13.1 Gb/s 12.2 Gb/s
Pentium Pro | 2.5 cycles/32b 3.5 cycles/32b 6 cycles/32b 9 cycles/32b
200MHz | 2.6 Gb/s 1.8 Gb/s 34 Gb/s 23 Gb/s
------------+-----------------------------------------------------------------
IBM/POWER |
RIOS 1 | 3 cycles/32b 4 cycles/32b 11.5-12.5 c/32b 14.5/15.5 c/32b
RIOS 2 | 2 cycles/32b 2 cycles/32b 7 cycles/32b 8.5 cycles/32b
------------+-----------------------------------------------------------------
PowerPC |
PPC601 (1) | 3 cycles/32b 6 cycles/32b 11-16 cycl/32b 14-19 cycl/32b
PPC601 (2) | 5 cycles/32b 6 cycles/32b 13-22 cycl/32b 16-25 cycl/32b
67MHz (2) | 0.43 Gb/s 0.36 Gb/s 5.3-3.0 Gb/s 4.3-2.7 Gb/s
PPC603 | ? ? ? ?
*PPC604 | 2 3 2 3
*167MHz | 57 Gb/s
PPC620 | ? ? ? ?
------------+-----------------------------------------------------------------
Tege |
Model 1 | 2 cycles/64b 3 cycles/64b 2 cycles/64b 3 cycles/64b
250MHz | 8 Gb/s 5.3 Gb/s 500 Gb/s 340 Gb/s
500MHz | 16 Gb/s 11 Gb/s 1000 Gb/s 680 Gb/s
____________|_________________________________________________________________
(1) Using POWER and PowerPC instructions
(2) Using only PowerPC instructions
(3) Actual timing for shift/add/sub depends on code alignment. PA7000 code
is smaller and therefore often faster on this CPU.
(4) Multiplication routines modified for bogus UltraSPARC early-out
optimization. Smaller operand is put in rs1, not rs2 as it should
according to the SPARC architecture manuals.
(5) Preliminary timings, since there is no stable 64-bit environment.
(6) Use mulu.d at least for mpn_lshift. With mak/extu/or, we can only get
to 2 cycles/32b.
=============================================================================
Estimated theoretical asymptotic cycle counts for low-level routines:
| mpn_lshift mpn_add_n mpn_mul_1 mpn_addmul_1
| mpn_rshift mpn_sub_n mpn_submul_1
------------+-----------------------------------------------------------------
DEC/Alpha |
EV4 | 3 cycles/64b 5 cycles/64b 42 cycles/64b 42 cycles/64b
EV5 | 3 cycles/64b 4 cycles/64b 18 cycles/64b 18 cycles/64b
------------+-----------------------------------------------------------------
Sun/SPARC |
SuperSPARC | 2.5 cycles/32b 2 cycles/32b 8 cycles/32b 9 cycles/32b
------------+-----------------------------------------------------------------
SGI/MIPS |
R4400/32 | 5 cycles/64b 8 cycles/64b 16 cycles/64b 16 cycles/64b
R4400/64 | 5 cycles/64b 8 cycles/64b 22 cycles/64b 22 cycles/64b
R4600 |
------------+-----------------------------------------------------------------
HP/PA-RISC |
PA7100 | 3 cycles/32b 4 cycles/32b 6.5 cycles/32b 7.5 cycles/32b
PA7100LC |
------------+-----------------------------------------------------------------
Motorola |
MC88110 | 1.5 cyc/32b (6) 1.5 cycle/32b 1.5 cycles/32b 2.25 cycles/32b
------------+-----------------------------------------------------------------
Intel/x86 |
486DX4 |
Pentium P5x | 5 cycles/32b 2 cycles/32b 11.5 cycles/32b 13 cycles/32b
Pentium Pro | 2 cycles/32b 3 cycles/32b 4 cycles/32b 6 cycles/32b
------------+-----------------------------------------------------------------
IBM/POWER |
RIOS 1 | 3 cycles/32b 4 cycles/32b
RIOS 2 | 1.5 cycles/32b 2 cycles/32b 4.5 cycles/32b 5.5 cycles/32b
------------+-----------------------------------------------------------------
PowerPC |
PPC601 (1) | 3 cycles/32b ?4 cycles/32b
PPC601 (2) | 4 cycles/32b ?4 cycles/32b
____________|_________________________________________________________________

592
gnu/lib/libgmp/config.guess vendored Executable file
View File

@ -0,0 +1,592 @@
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 93, 94, 95, 1996 Free Software Foundation, Inc.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Written by Per Bothner <bothner@cygnus.com>.
# The master version of this file is at the FSF in /home/gd/gnu/lib.
#
# This script attempts to guess a canonical system name similar to
# config.sub. If it succeeds, it prints the system name on stdout, and
# exits with 0. Otherwise, it exits with 1.
#
# The plan is that this can be called by configure scripts if you
# don't specify an explicit system type (host/target name).
#
# Only a few systems have been added to this list; please add others
# (but try to keep the structure clean).
#
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
# (ghazi@noc.rutgers.edu 8/24/94.)
if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
PATH=$PATH:/.attbin ; export PATH
fi
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
trap 'rm -f dummy.c dummy.o dummy; exit 1' 1 2 15
# Note: order is significant - the case branches are not exclusive.
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
alpha:OSF1:[VX]*:*)
# After 1.2, OSF1 uses "V1.3" for uname -r.
# After 4.x, OSF1 uses "X4.x" for uname -r.
echo alpha-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VX]//'`
exit 0 ;;
alpha:OSF1:*:*)
# 1.2 uses "1.2" for uname -r.
echo alpha-dec-osf${UNAME_RELEASE}
exit 0 ;;
21064:Windows_NT:50:3)
echo alpha-dec-winnt3.5
exit 0 ;;
Amiga*:UNIX_System_V:4.0:*)
echo m68k-cbm-sysv4
exit 0;;
amiga:NetBSD:*:*)
echo m68k-cbm-netbsd${UNAME_RELEASE}
exit 0 ;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
exit 0;;
Pyramid*:OSx*:*:*)
if test "`(/bin/universe) 2>/dev/null`" = att ; then
echo pyramid-pyramid-sysv3
else
echo pyramid-pyramid-bsd
fi
exit 0 ;;
sun4*:SunOS:5.*:*)
echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
i86pc:SunOS:5.*:*)
echo i386-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
sun4*:SunOS:6*:*)
# According to config.sub, this is the proper way to canonicalize
# SunOS6. Hard to guess exactly what SunOS6 will be like, but
# it's likely to be more like Solaris than SunOS4.
echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
sun4*:SunOS:*:*)
case "`/usr/bin/arch -k`" in
Series*|S4*)
UNAME_RELEASE=`uname -v`
;;
esac
# Japanese Language versions have a version number like `4.1.3-JL'.
echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
exit 0 ;;
sun3*:SunOS:*:*)
echo m68k-sun-sunos${UNAME_RELEASE}
exit 0 ;;
atari*:NetBSD:*:*)
echo m68k-atari-netbsd${UNAME_RELEASE}
exit 0 ;;
sun3*:NetBSD:*:*)
echo m68k-sun-netbsd${UNAME_RELEASE}
exit 0 ;;
mac68k:NetBSD:*:*)
echo m68k-apple-netbsd${UNAME_RELEASE}
exit 0 ;;
RISC*:ULTRIX:*:*)
echo mips-dec-ultrix${UNAME_RELEASE}
exit 0 ;;
VAX*:ULTRIX*:*:*)
echo vax-dec-ultrix${UNAME_RELEASE}
exit 0 ;;
mips:*:4*:UMIPS)
echo mips-mips-riscos4sysv
exit 0 ;;
mips:*:5*:RISCos)
echo mips-mips-riscos${UNAME_RELEASE}
exit 0 ;;
Night_Hawk:Power_UNIX:*:*)
echo powerpc-harris-powerunix
exit 0 ;;
m88k:CX/UX:7*:*)
echo m88k-harris-cxux7
exit 0 ;;
m88k:*:4*:R4*)
echo m88k-motorola-sysv4
exit 0 ;;
m88k:*:3*:R3*)
echo m88k-motorola-sysv3
exit 0 ;;
AViiON:dgux:*:*)
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`uname -p`
if [ $UNAME_PROCESSOR = mc88100 -o $UNAME_PROCESSOR = mc88100 ] ; then
if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \
-o ${TARGET_BINARY_INTERFACE}x = x ] ; then
echo m88k-dg-dgux${UNAME_RELEASE}
else
echo m88k-dg-dguxbcs${UNAME_RELEASE}
fi
else echo i586-dg-dgux${UNAME_RELEASE}
fi
exit 0 ;;
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
echo m88k-dolphin-sysv3
exit 0 ;;
M88*:*:R3*:*)
# Delta 88k system running SVR3
echo m88k-motorola-sysv3
exit 0 ;;
XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
echo m88k-tektronix-sysv3
exit 0 ;;
Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
echo m68k-tektronix-bsd
exit 0 ;;
*:IRIX*:*:*)
echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
exit 0 ;;
????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX '
i[34]86:AIX:*:*)
echo i386-ibm-aix
exit 0 ;;
*:AIX:2:3)
if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
sed 's/^ //' << EOF >dummy.c
#include <sys/systemcfg.h>
main()
{
if (!__power_pc())
exit(1);
puts("powerpc-ibm-aix3.2.5");
exit(0);
}
EOF
${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
echo rs6000-ibm-aix3.2.5
elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
echo rs6000-ibm-aix3.2.4
else
echo rs6000-ibm-aix3.2
fi
exit 0 ;;
*:AIX:*:4)
if /usr/sbin/lsattr -EHl proc0 | grep POWER >/dev/null 2>&1; then
IBM_ARCH=rs6000
else
IBM_ARCH=powerpc
fi
if [ -x /usr/bin/oslevel ] ; then
IBM_REV=`/usr/bin/oslevel`
else
IBM_REV=4.${UNAME_RELEASE}
fi
echo ${IBM_ARCH}-ibm-aix${IBM_REV}
exit 0 ;;
*:AIX:*:*)
echo rs6000-ibm-aix
exit 0 ;;
ibmrt:4.4BSD:*|romp-ibm:BSD:*)
echo romp-ibm-bsd4.4
exit 0 ;;
ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and
echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to
exit 0 ;; # report: romp-ibm BSD 4.3
*:BOSX:*:*)
echo rs6000-bull-bosx
exit 0 ;;
DPX/2?00:B.O.S.:*:*)
echo m68k-bull-sysv3
exit 0 ;;
9000/[34]??:4.3bsd:1.*:*)
echo m68k-hp-bsd
exit 0 ;;
hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
echo m68k-hp-bsd4.4
exit 0 ;;
9000/[3478]??:HP-UX:*:*)
case "${UNAME_MACHINE}" in
9000/31? ) HP_ARCH=m68000 ;;
9000/[34]?? ) HP_ARCH=m68k ;;
9000/7?? | 9000/8?[679] ) HP_ARCH=hppa1.1 ;;
9000/8?? ) HP_ARCH=hppa1.0 ;;
esac
HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
echo ${HP_ARCH}-hp-hpux${HPUX_REV}
exit 0 ;;
3050*:HI-UX:*:*)
sed 's/^ //' << EOF >dummy.c
#include <unistd.h>
int
main ()
{
long cpu = sysconf (_SC_CPU_VERSION);
/* The order matters, because CPU_IS_HP_MC68K erroneously returns
true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct
results, however. */
if (CPU_IS_PA_RISC (cpu))
{
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
default: puts ("hppa-hitachi-hiuxwe2"); break;
}
}
else if (CPU_IS_HP_MC68K (cpu))
puts ("m68k-hitachi-hiuxwe2");
else puts ("unknown-hitachi-hiuxwe2");
exit (0);
}
EOF
${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
echo unknown-hitachi-hiuxwe2
exit 0 ;;
9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
echo hppa1.1-hp-bsd
exit 0 ;;
9000/8??:4.3bsd:*:*)
echo hppa1.0-hp-bsd
exit 0 ;;
hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
echo hppa1.1-hp-osf
exit 0 ;;
hp8??:OSF1:*:*)
echo hppa1.0-hp-osf
exit 0 ;;
parisc*:Lites*:*:*)
echo hppa1.1-hp-lites
exit 0 ;;
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
echo c1-convex-bsd
exit 0 ;;
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit 0 ;;
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
echo c34-convex-bsd
exit 0 ;;
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
echo c38-convex-bsd
exit 0 ;;
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
echo c4-convex-bsd
exit 0 ;;
CRAY*X-MP:*:*:*)
echo xmp-cray-unicos
exit 0 ;;
CRAY*Y-MP:*:*:*)
echo ymp-cray-unicos${UNAME_RELEASE}
exit 0 ;;
CRAY*C90:*:*:*)
echo c90-cray-unicos${UNAME_RELEASE}
exit 0 ;;
CRAY-2:*:*:*)
echo cray2-cray-unicos
exit 0 ;;
hp3[0-9][05]:NetBSD:*:*)
echo m68k-hp-netbsd${UNAME_RELEASE}
exit 0 ;;
i[34]86:BSD/386:*:* | *:BSD/OS:*:*)
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
exit 0 ;;
*:FreeBSD:*:*)
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
exit 0 ;;
*:NetBSD:*:*)
echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
exit 0 ;;
i*:CYGWIN*:*)
echo i386-unknown-cygwin32
exit 0 ;;
p*:CYGWIN*:*)
echo powerpcle-unknown-cygwin32
exit 0 ;;
*:GNU:*:*)
echo `echo ${UNAME_MACHINE}|sed -e 's,/.*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
exit 0 ;;
*:Linux:*:*)
# The BFD linker knows what the default object file format is, so
# first see if it will tell us.
ld_help_string=`ld --help 2>&1`
if echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: elf_i[345]86"; then
echo "${UNAME_MACHINE}-unknown-linux" ; exit 0
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: i[345]86linux"; then
echo "${UNAME_MACHINE}-unknown-linuxaout" ; exit 0
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: i[345]86coff"; then
echo "${UNAME_MACHINE}-unknown-linuxcoff" ; exit 0
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: m68kelf"; then
echo "${UNAME_MACHINE}-unknown-linux" ; exit 0
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: m68klinux"; then
echo "${UNAME_MACHINE}-unknown-linuxaout" ; exit 0
elif test "${UNAME_MACHINE}" = "alpha" ; then
echo alpha-unknown-linux ; exit 0
else
# Either a pre-BFD a.out linker (linuxoldld) or one that does not give us
# useful --help. Gcc wants to distinguish between linuxoldld and linuxaout.
test ! -d /usr/lib/ldscripts/. \
&& echo "${UNAME_MACHINE}-unknown-linuxoldld" && exit 0
# Determine whether the default compiler is a.out or elf
cat >dummy.c <<EOF
main(argc, argv)
int argc;
char *argv[];
{
#ifdef __ELF__
printf ("%s-unknown-linux\n", argv[1]);
#else
printf ("%s-unknown-linuxaout\n", argv[1]);
#endif
return 0;
}
EOF
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
fi ;;
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions
# are messed up and put the nodename in both sysname and nodename.
i[34]86:DYNIX/ptx:4*:*)
echo i386-sequent-sysv4
exit 0 ;;
i[34]86:*:4.*:* | i[34]86:SYSTEM_V:4.*:*)
if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
echo ${UNAME_MACHINE}-univel-sysv${UNAME_RELEASE}
else
echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}
fi
exit 0 ;;
i[34]86:*:3.2:*)
if test -f /usr/options/cb.name; then
UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
echo ${UNAME_MACHINE}-unknown-isc$UNAME_REL
elif /bin/uname -X 2>/dev/null >/dev/null ; then
UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')`
(/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486
(/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
&& UNAME_MACHINE=i586
echo ${UNAME_MACHINE}-unknown-sco$UNAME_REL
else
echo ${UNAME_MACHINE}-unknown-sysv32
fi
exit 0 ;;
Intel:Mach:3*:*)
echo i386-unknown-mach3
exit 0 ;;
paragon:*:*:*)
echo i860-intel-osf1
exit 0 ;;
i860:*:4.*:*) # i860-SVR4
if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
else # Add other i860-SVR4 vendors below as they are discovered.
echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4
fi
exit 0 ;;
mini*:CTIX:SYS*5:*)
# "miniframe"
echo m68010-convergent-sysv
exit 0 ;;
M680[234]0:*:R3V[567]*:*)
test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0)
uname -p 2>/dev/null | grep 86 >/dev/null \
&& echo i486-ncr-sysv4.3 && exit 0 ;;
3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
uname -p 2>/dev/null | grep 86 >/dev/null \
&& echo i486-ncr-sysv4 && exit 0 ;;
m680[234]0:LynxOS:2.[23]*:*)
echo m68k-lynx-lynxos${UNAME_RELEASE}
exit 0 ;;
mc68030:UNIX_System_V:4.*:*)
echo m68k-atari-sysv4
exit 0 ;;
i[34]86:LynxOS:2.[23]*:*)
echo i386-lynx-lynxos${UNAME_RELEASE}
exit 0 ;;
TSUNAMI:LynxOS:2.[23]*:*)
echo sparc-lynx-lynxos${UNAME_RELEASE}
exit 0 ;;
rs6000:LynxOS:2.[23]*:*)
echo rs6000-lynx-lynxos${UNAME_RELEASE}
exit 0 ;;
RM*:SINIX-*:*:*)
echo mips-sni-sysv4
exit 0 ;;
*:SINIX-*:*:*)
if uname -p 2>/dev/null >/dev/null ; then
UNAME_MACHINE=`(uname -p) 2>/dev/null`
echo ${UNAME_MACHINE}-sni-sysv4
else
echo ns32k-sni-sysv
fi
exit 0 ;;
mc68*:A/UX:*:*)
echo m68k-apple-aux${UNAME_RELEASE}
exit 0 ;;
esac
#echo '(No uname command or uname output not recognized.)' 1>&2
#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
cat >dummy.c <<EOF
#ifdef _SEQUENT_
# include <sys/types.h>
# include <sys/utsname.h>
#endif
main ()
{
#if defined (sony)
#if defined (MIPSEB)
/* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
I don't know.... */
printf ("mips-sony-bsd\n"); exit (0);
#else
#include <sys/param.h>
printf ("m68k-sony-newsos%s\n",
#ifdef NEWSOS4
"4"
#else
""
#endif
); exit (0);
#endif
#endif
#if defined (__arm) && defined (__acorn) && defined (__unix)
printf ("arm-acorn-riscix"); exit (0);
#endif
#if defined (hp300) && !defined (hpux)
printf ("m68k-hp-bsd\n"); exit (0);
#endif
#if defined (NeXT)
#if !defined (__ARCHITECTURE__)
#define __ARCHITECTURE__ "m68k"
#endif
int version;
version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
printf ("%s-next-nextstep%s\n", __ARCHITECTURE__, version==2 ? "2" : "3");
exit (0);
#endif
#if defined (MULTIMAX) || defined (n16)
#if defined (UMAXV)
printf ("ns32k-encore-sysv\n"); exit (0);
#else
#if defined (CMU)
printf ("ns32k-encore-mach\n"); exit (0);
#else
printf ("ns32k-encore-bsd\n"); exit (0);
#endif
#endif
#endif
#if defined (__386BSD__)
printf ("i386-unknown-bsd\n"); exit (0);
#endif
#if defined (sequent)
#if defined (i386)
printf ("i386-sequent-dynix\n"); exit (0);
#endif
#if defined (ns32000)
printf ("ns32k-sequent-dynix\n"); exit (0);
#endif
#endif
#if defined (_SEQUENT_)
struct utsname un;
uname(&un);
if (strncmp(un.version, "V2", 2) == 0) {
printf ("i386-sequent-ptx2\n"); exit (0);
}
if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
printf ("i386-sequent-ptx1\n"); exit (0);
}
printf ("i386-sequent-ptx\n"); exit (0);
#endif
#if defined (vax)
#if !defined (ultrix)
printf ("vax-dec-bsd\n"); exit (0);
#else
printf ("vax-dec-ultrix\n"); exit (0);
#endif
#endif
#if defined (alliant) && defined (i860)
printf ("i860-alliant-bsd\n"); exit (0);
#endif
exit (1);
}
EOF
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
# Apollos put the system type in the environment.
test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
# Convex versions that predate uname can use getsysinfo(1)
if [ -x /usr/convex/getsysinfo ]
then
case `getsysinfo -f cpu_type` in
c1*)
echo c1-convex-bsd
exit 0 ;;
c2*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit 0 ;;
c34*)
echo c34-convex-bsd
exit 0 ;;
c38*)
echo c38-convex-bsd
exit 0 ;;
c4*)
echo c4-convex-bsd
exit 0 ;;
esac
fi
#echo '(Unable to guess system type)' 1>&2
exit 1

1094
gnu/lib/libgmp/config.sub vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
AR_FLAGS = qc

View File

@ -0,0 +1 @@
XCFLAGS = -m88110

View File

@ -0,0 +1 @@
XCFLAGS = -mv8

View File

@ -0,0 +1 @@
XCFLAGS = -mv8 -DSUPERSPARC

1263
gnu/lib/libgmp/configure vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
# This file is a shell script fragment that supplies the information
# necessary for a configure script to process the program in
# this directory. For more information, look at ../configure.
configdirs="mpn mpz mpf mpq mpbsd"
srctrigger=gmp-impl.h
srcname="GNU Multi-Precision library"
# per-host:
# per-target:
case "${target}" in
sparc8* | microsparc*)
if [ x$with_gcc != xno ]
then
target_makefile_frag=config/mt-sprc8-gcc
fi
;;
supersparc*)
if [ x$with_gcc != xno ]
then
target_makefile_frag=config/mt-supspc-gcc
fi
;;
m888110*)
if [ x$with_gcc != xno ]
then
target_makefile_frag=config/mt-m88110
fi
;;
*-*-linux*)
target_makefile_frag=config/mt-linux ;;
esac

View File

@ -1,118 +1,16 @@
/* cre-mparam.c -- Create machine-depedent parameter file.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
The GNU MP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
unsigned int
ulog2 (x)
unsigned long int x;
{
unsigned int i;
for (i = 0; x != 0; i++)
x >>= 1;
return i;
}
main ()
{
int i;
printf ("/* gmp-mparam.h -- Compiler/machine parameter header file.\n\n");
printf (" *** CREATED BY A PROGRAM -- DO NOT EDIT ***\n\n");
printf ("Copyright (C) 1996 Free Software Foundation, Inc. */\n\n");
unsigned long int max_uli;
int bits_uli;
unsigned long int max_ui;
int bits_ui;
unsigned long int max_usi;
int bits_usi;
unsigned long int max_uc;
int bits_uc;
max_uli = 1;
for (i = 0; ; i++)
{
if (max_uli == 0)
break;
max_uli <<= 1;
}
bits_uli = i;
max_ui = 1;
for (i = 0; ; i++)
{
if ((unsigned int) max_ui == 0)
break;
max_ui <<= 1;
}
bits_ui = i;
max_usi = 1;
for (i = 0; ; i++)
{
if ((unsigned short int) max_usi == 0)
break;
max_usi <<= 1;
}
bits_usi = i;
max_uc = 1;
for (i = 0; ; i++)
{
if ((unsigned char) max_uc == 0)
break;
max_uc <<= 1;
}
bits_uc = i;
puts ("/* gmp-mparam.h -- Compiler/machine parameter header file.");
puts ("");
puts (" ***** THIS FILE WAS CREATED BY A PROGRAM. DON'T EDIT IT! *****");
puts ("");
puts ("Copyright (C) 1991 Free Software Foundation, Inc.");
puts ("");
puts ("This file is part of the GNU MP Library.");
puts ("");
puts ("The GNU MP Library is free software; you can redistribute it and/or");
puts ("modify it under the terms of the GNU General Public License as");
puts ("published by the Free Software Foundation; either version 2, or");
puts ("(at your option) any later version.");
puts ("");
puts ("The GNU MP Library is distributed in the hope that it will be");
puts ("useful, but WITHOUT ANY WARRANTY; without even the implied warranty");
puts ("of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the");
puts ("GNU General Public License for more details.");
puts ("");
puts ("You should have received a copy of the GNU General Public License");
puts ("along with the GNU MP Library; see the file COPYING. If not, write");
puts ("to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,");
puts ("USA. */");
puts ("");
printf ("#define BITS_PER_MP_LIMB %d\n", bits_uli);
printf ("#define BYTES_PER_MP_LIMB %d\n", sizeof(mp_limb));
printf ("#define BITS_PER_LONGINT %d\n", bits_uli);
printf ("#define BITS_PER_INT %d\n", bits_ui);
printf ("#define BITS_PER_SHORTINT %d\n", bits_usi);
printf ("#define BITS_PER_CHAR %d\n", bits_uc);
exit (0);
printf ("#define BITS_PER_MP_LIMB %d\n", 8 * sizeof (mp_limb_t));
printf ("#define BYTES_PER_MP_LIMB %d\n", sizeof (mp_limb_t));
printf ("#define BITS_PER_LONGINT %d\n", 8 * sizeof (long));
printf ("#define BITS_PER_INT %d\n", 8 * sizeof (int));
printf ("#define BITS_PER_SHORTINT %d\n", 8 * sizeof (short));
printf ("#define BITS_PER_CHAR 8\n");
exit (0);
}

View File

@ -0,0 +1,233 @@
/* Factoring with Pollard's rho method.
Copyright (C) 1995 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include <stdio.h>
#include "gmp.h"
int flag_mersenne = 0;
static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6};
factor_using_division (t, limit)
mpz_t t;
unsigned int limit;
{
mpz_t q, r;
unsigned long int f;
int i, ai;
unsigned *addv = add;
mpz_init (q);
mpz_init (r);
if (mpz_probab_prime_p (t, 50))
goto ready;
for (;;)
{
mpz_tdiv_qr_ui (q, r, t, 2);
if (mpz_cmp_ui (r, 0) != 0)
break;
mpz_set (t, q);
printf ("2 ");
fflush (stdout);
if (mpz_probab_prime_p (t, 50))
goto ready;
}
for (;;)
{
mpz_tdiv_qr_ui (q, r, t, 3);
if (mpz_cmp_ui (r, 0) != 0)
break;
mpz_set (t, q);
printf ("3 ");
fflush (stdout);
if (mpz_probab_prime_p (t, 50))
goto ready;
}
for (;;)
{
mpz_tdiv_qr_ui (q, r, t, 5);
if (mpz_cmp_ui (r, 0) != 0)
break;
mpz_set (t, q);
printf ("5 ");
fflush (stdout);
if (mpz_probab_prime_p (t, 50))
goto ready;
}
f = 7;
ai = 0;
for (;;)
{
mpz_tdiv_qr_ui (q, r, t, f);
if (mpz_cmp_ui (r, 0) != 0)
{
f += addv[ai];
if (f > limit)
goto ret;
ai = (ai + 1) & 7;
}
else
{
mpz_set (t, q);
printf ("%lu ", f);
fflush (stdout);
if (mpz_probab_prime_p (t, 50))
goto ready;
}
}
ready:
mpz_out_str (stdout, 10, t);
fflush (stdout);
mpz_set_ui (t, 1);
fputc (' ', stdout);
ret:
mpz_clear (q);
mpz_clear (r);
}
void
factor_using_pollard_rho (m, a_int, x0, p)
mpz_t m;
long a_int;
long x0;
unsigned long p;
{
mpz_t x, y, q;
mpz_t a;
mpz_t d;
mpz_t tmp;
mpz_t n;
int i = 1;
int j = 1;
mpz_init_set (n, m);
mpz_init (d);
mpz_init_set_ui (q, 1);
mpz_init (tmp);
mpz_init_set_si (a, a_int);
mpz_init_set_si (x, x0);
mpz_init_set_si (y, x0);
while (mpz_cmp_ui (n, 1) != 0)
{
if (flag_mersenne)
{
mpz_powm_ui (x, x, p, n); mpz_add (x, x, a);
mpz_powm_ui (y, y, p, n); mpz_add (y, y, a);
mpz_powm_ui (y, y, p, n); mpz_add (y, y, a);
}
else
{
mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n);
mpz_mul (y, y, y); mpz_add (y, y, a); mpz_mod (y, y, n);
mpz_mul (y, y, y); mpz_add (y, y, a); mpz_mod (y, y, n);
}
if (mpz_cmp (x, y) > 0)
mpz_sub (tmp, x, y);
else
mpz_sub (tmp, y, x);
mpz_mul (q, q, tmp);
mpz_mod (q, q, n);
if (++i % j == 0)
{
j += 1;
mpz_gcd (d, q, n);
if (mpz_cmp_ui (d, 1) != 0)
{
if (!mpz_probab_prime_p (d, 50))
factor_using_pollard_rho (d, (random () & 31) - 16,
(random () & 31), p);
else
{
mpz_out_str (stdout, 10, d);
fflush (stdout);
fputc (' ', stdout);
}
mpz_div (n, n, d);
if (mpz_probab_prime_p (n, 50))
{
mpz_out_str (stdout, 10, n);
fflush (stdout);
fputc (' ', stdout);
break;
}
}
}
}
mpz_clear (n);
mpz_clear (d);
mpz_clear (q);
mpz_clear (tmp);
mpz_clear (a);
mpz_clear (x);
mpz_clear (y);
}
factor (t, a, x0, p)
mpz_t t;
long a;
long x0;
unsigned long p;
{
factor_using_division (t, 1000000);
factor_using_pollard_rho (t, a, x0, p);
}
main (argc, argv)
int argc;
char *argv[];
{
mpz_t t;
long x0, a;
unsigned long p;
int i;
for (i = 1; i < argc; i++)
{
if (!strncmp (argv[i], "-Mp", 3))
{
p = atoi (argv[i] + 3);
mpz_init_set_ui (t, 1);
mpz_mul_2exp (t, t, p);
mpz_sub_ui (t, t, 1);
flag_mersenne = 1;
}
else
{
p = 0;
mpz_init_set_str (t, argv[i], 0);
}
a = -1;
x0 = 3;
factor (t, a, x0, p);
puts ("");
}
}

View File

@ -0,0 +1,160 @@
/* __gmp_extract_double -- convert from double to array of mp_limb_t.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#ifdef XDEBUG
#undef _GMP_IEEE_FLOATS
#endif
#ifndef _GMP_IEEE_FLOATS
#define _GMP_IEEE_FLOATS 0
#endif
#define MP_BASE_AS_DOUBLE (2.0 * ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1)))
/* Extract a non-negative double in d. */
int
#if __STDC__
__gmp_extract_double (mp_ptr rp, double d)
#else
__gmp_extract_double (rp, d)
mp_ptr rp;
double d;
#endif
{
long exp;
unsigned sc;
mp_limb_t manh, manl;
/* BUGS
1. Should handle Inf and NaN in IEEE specific code.
2. Handle Inf and NaN also in default code, to avoid hangs.
3. Generalize to handle all BITS_PER_MP_LIMB >= 32.
4. This lits is incomplete and misspelled.
*/
if (d == 0.0)
{
rp[0] = 0;
rp[1] = 0;
#if BITS_PER_MP_LIMB == 32
rp[2] = 0;
#endif
return 0;
}
#if _GMP_IEEE_FLOATS
{
union ieee_double_extract x;
x.d = d;
exp = x.s.exp;
sc = (unsigned) (exp + 2) % BITS_PER_MP_LIMB;
#if BITS_PER_MP_LIMB == 64
manl = (((mp_limb_t) 1 << 63)
| ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11));
#else
manh = ((mp_limb_t) 1 << 31) | (x.s.manh << 11) | (x.s.manl >> 21);
manl = x.s.manl << 11;
#endif
}
#else
{
/* Unknown (or known to be non-IEEE) double format. */
exp = 0;
if (d >= 1.0)
{
if (d * 0.5 == d)
abort ();
while (d >= 32768.0)
{
d *= (1.0 / 65536.0);
exp += 16;
}
while (d >= 1.0)
{
d *= 0.5;
exp += 1;
}
}
else if (d < 0.5)
{
while (d < (1.0 / 65536.0))
{
d *= 65536.0;
exp -= 16;
}
while (d < 0.5)
{
d *= 2.0;
exp -= 1;
}
}
sc = (unsigned) exp % BITS_PER_MP_LIMB;
d *= MP_BASE_AS_DOUBLE;
#if BITS_PER_MP_LIMB == 64
manl = d;
#else
manh = d;
manl = (d - manh) * MP_BASE_AS_DOUBLE;
#endif
exp += 1022;
}
#endif
exp = (unsigned) (exp + 1) / BITS_PER_MP_LIMB - 1024 / BITS_PER_MP_LIMB + 1;
#if BITS_PER_MP_LIMB == 64
if (sc != 0)
{
rp[1] = manl >> (BITS_PER_MP_LIMB - sc);
rp[0] = manl << sc;
}
else
{
rp[1] = manl;
rp[0] = 0;
}
#else
if (sc != 0)
{
rp[2] = manh >> (BITS_PER_MP_LIMB - sc);
rp[1] = (manl >> (BITS_PER_MP_LIMB - sc)) | (manh << sc);
rp[0] = manl << sc;
}
else
{
rp[2] = manh;
rp[1] = manl;
rp[0] = 0;
}
#endif
return exp;
}

View File

@ -1,43 +1,86 @@
/* Include file for internal GNU MP types and definitions.
Copyright (C) 1991 Free Software Foundation, Inc.
Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 General Public License for more details.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#if defined (__GNUC__) || defined (__sparc__) || defined (sparc)
/* When using gcc, make sure to use its builtin alloca. */
#if ! defined (alloca) && defined (__GNUC__)
#define alloca __builtin_alloca
#define HAVE_ALLOCA
#endif
/* When using cc, do whatever necessary to allow use of alloca. For many
machines, this means including alloca.h. IBM's compilers need a #pragma
in "each module that needs to use alloca". */
#if ! defined (alloca)
/* We need lots of variants for MIPS, to cover all versions and perversions
of OSes for MIPS. */
#if defined (__mips) || defined (MIPSEL) || defined (MIPSEB) \
|| defined (_MIPSEL) || defined (_MIPSEB) || defined (__sgi) \
|| defined (__alpha) || defined (__sparc) || defined (sparc) \
|| defined (__ksr__)
#include <alloca.h>
#define HAVE_ALLOCA
#endif
#if defined (_IBMR2)
#pragma alloca
#define HAVE_ALLOCA
#endif
#if defined (__DECC)
#define alloca(x) __ALLOCA(x)
#define HAVE_ALLOCA
#endif
#endif
#if ! defined (HAVE_ALLOCA) || USE_STACK_ALLOC
#include "stack-alloc.h"
#else
#define TMP_DECL(m)
#define TMP_ALLOC(x) alloca(x)
#define TMP_MARK(m)
#define TMP_FREE(m)
#endif
#ifndef NULL
#define NULL 0L
#define NULL ((void *) 0)
#endif
#if defined (__GNUC__)
volatile void abort (void);
#else
#if ! defined (__GNUC__)
#define inline /* Empty */
void *alloca();
#endif
#define ABS(x) (x >= 0 ? x : -x)
#define MIN(l,o) ((l) < (o) ? (l) : (o))
#define MAX(h,i) ((h) > (i) ? (h) : (i))
/* Field access macros. */
#define SIZ(x) ((x)->_mp_size)
#define ABSIZ(x) ABS (SIZ (x))
#define PTR(x) ((x)->_mp_d)
#define EXP(x) ((x)->_mp_exp)
#define PREC(x) ((x)->_mp_prec)
#define ALLOC(x) ((x)->_mp_alloc)
#include "gmp-mparam.h"
/* #include "longlong.h" */
#ifdef __STDC__
#if defined (__STDC__) || defined (__cplusplus)
void *malloc (size_t);
void *realloc (void *, size_t);
void free (void *);
@ -50,10 +93,8 @@ void *_mp_default_allocate (size_t);
void *_mp_default_reallocate (void *, size_t, size_t);
void _mp_default_free (void *, size_t);
char *_mpz_get_str (char *, int, const MP_INT *);
int _mpz_set_str (MP_INT *, const char *, int);
void _mpz_impl_sqrt (MP_INT *, MP_INT *, const MP_INT *);
#else
#define const /* Empty */
#define signed /* Empty */
@ -68,59 +109,259 @@ extern void (*_mp_free_func) ();
void *_mp_default_allocate ();
void *_mp_default_reallocate ();
void _mp_default_free ();
char *_mpz_get_str ();
int _mpz_set_str ();
void _mpz_impl_sqrt ();
#endif
/* Copy NLIMBS *limbs* from SRC to DST. */
#define MPN_COPY(DST, SRC, NLIMBS) \
#define MPN_COPY_INCR(DST, SRC, NLIMBS) \
do { \
mp_size i; \
for (i = 0; i < (NLIMBS); i++) \
(DST)[i] = (SRC)[i]; \
mp_size_t __i; \
for (__i = 0; __i < (NLIMBS); __i++) \
(DST)[__i] = (SRC)[__i]; \
} while (0)
#define MPN_COPY_DECR(DST, SRC, NLIMBS) \
do { \
mp_size_t __i; \
for (__i = (NLIMBS) - 1; __i >= 0; __i--) \
(DST)[__i] = (SRC)[__i]; \
} while (0)
#define MPN_COPY MPN_COPY_INCR
/* Zero NLIMBS *limbs* AT DST. */
#define MPN_ZERO(DST, NLIMBS) \
do { \
mp_size i; \
for (i = 0; i < (NLIMBS); i++) \
(DST)[i] = 0; \
mp_size_t __i; \
for (__i = 0; __i < (NLIMBS); __i++) \
(DST)[__i] = 0; \
} while (0)
#define MPN_NORMALIZE(DST, NLIMBS) \
do { \
while (NLIMBS > 0) \
{ \
if ((DST)[(NLIMBS) - 1] != 0) \
break; \
NLIMBS--; \
} \
} while (0)
#define MPN_NORMALIZE_NOT_ZERO(DST, NLIMBS) \
do { \
while (1) \
{ \
if ((DST)[(NLIMBS) - 1] != 0) \
break; \
NLIMBS--; \
} \
} while (0)
/* Initialize the MP_INT X with space for NLIMBS limbs.
X should be a temporary variable, and it will be automatically
cleared out when the running function returns. */
cleared out when the running function returns.
We use __x here to make it possible to accept both mpz_ptr and mpz_t
arguments. */
#define MPZ_TMP_INIT(X, NLIMBS) \
do { \
(X)->alloc = (NLIMBS); \
(X)->d = (mp_ptr) alloca ((NLIMBS) * BYTES_PER_MP_LIMB); \
mpz_ptr __x = (X); \
__x->_mp_alloc = (NLIMBS); \
__x->_mp_d = (mp_ptr) TMP_ALLOC ((NLIMBS) * BYTES_PER_MP_LIMB); \
} while (0)
#define MPN_MUL_N_RECURSE(prodp, up, vp, size, tspace) \
do { \
if ((size) < KARATSUBA_THRESHOLD) \
impn_mul_n_basecase (prodp, up, vp, size); \
else \
impn_mul_n (prodp, up, vp, size, tspace); \
} while (0);
#define MPN_SQR_N_RECURSE(prodp, up, size, tspace) \
do { \
if ((size) < KARATSUBA_THRESHOLD) \
impn_sqr_n_basecase (prodp, up, size); \
else \
impn_sqr_n (prodp, up, size, tspace); \
} while (0);
/* Structure for conversion between internal binary format and
strings in base 2..36. */
struct bases
{
/* Number of digits in the conversion base that always fits in
an mp_limb. For example, for base 10 this is 10, since
2**32 = 4294967296 has ten digits. */
/* Number of digits in the conversion base that always fits in an mp_limb_t.
For example, for base 10 on a machine where a mp_limb_t has 32 bits this
is 9, since 10**9 is the largest number that fits into a mp_limb_t. */
int chars_per_limb;
/* big_base is conversion_base**chars_per_limb, i.e. the biggest
number that fits a word, built by factors of conversion_base.
Exception: For 2, 4, 8, etc, big_base is log2(base), i.e. the
number of bits used to represent each digit in the base. */
mp_limb big_base;
/* big_base_inverted is a BITS_PER_MP_LIMB bit approximation to
1/big_base, represented as a fixed-point number. Instead of
dividing by big_base an application can choose to multiply
by big_base_inverted. */
mp_limb big_base_inverted;
/* log(2)/log(conversion_base) */
float chars_per_bit_exactly;
/* base**chars_per_limb, i.e. the biggest number that fits a word, built by
factors of base. Exception: For 2, 4, 8, etc, big_base is log2(base),
i.e. the number of bits used to represent each digit in the base. */
mp_limb_t big_base;
/* A BITS_PER_MP_LIMB bit approximation to 1/big_base, represented as a
fixed-point number. Instead of dividing by big_base an application can
choose to multiply by big_base_inverted. */
mp_limb_t big_base_inverted;
};
extern const struct bases __mp_bases[37];
extern const struct bases __mp_bases[];
extern mp_size_t __gmp_default_fp_limb_precision;
/* Divide the two-limb number in (NH,,NL) by D, with DI being the largest
limb not larger than (2**(2*BITS_PER_MP_LIMB))/D - (2**BITS_PER_MP_LIMB).
If this would yield overflow, DI should be the largest possible number
(i.e., only ones). For correct operation, the most significant bit of D
has to be set. Put the quotient in Q and the remainder in R. */
#define udiv_qrnnd_preinv(q, r, nh, nl, d, di) \
do { \
mp_limb_t _q, _ql, _r; \
mp_limb_t _xh, _xl; \
umul_ppmm (_q, _ql, (nh), (di)); \
_q += (nh); /* DI is 2**BITS_PER_MP_LIMB too small */\
umul_ppmm (_xh, _xl, _q, (d)); \
sub_ddmmss (_xh, _r, (nh), (nl), _xh, _xl); \
if (_xh != 0) \
{ \
sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
_q += 1; \
if (_xh != 0) \
{ \
sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
_q += 1; \
} \
} \
if (_r >= (d)) \
{ \
_r -= (d); \
_q += 1; \
} \
(r) = _r; \
(q) = _q; \
} while (0)
/* Like udiv_qrnnd_preinv, but for for any value D. DNORM is D shifted left
so that its most significant bit is set. LGUP is ceil(log2(D)). */
#define udiv_qrnnd_preinv2gen(q, r, nh, nl, d, di, dnorm, lgup) \
do { \
mp_limb_t n2, n10, n1, nadj, q1; \
mp_limb_t _xh, _xl; \
n2 = ((nh) << (BITS_PER_MP_LIMB - (lgup))) + ((nl) >> 1 >> (l - 1));\
n10 = (nl) << (BITS_PER_MP_LIMB - (lgup)); \
n1 = ((mp_limb_signed_t) n10 >> (BITS_PER_MP_LIMB - 1)); \
nadj = n10 + (n1 & (dnorm)); \
umul_ppmm (_xh, _xl, di, n2 - n1); \
add_ssaaaa (_xh, _xl, _xh, _xl, 0, nadj); \
q1 = ~(n2 + _xh); \
umul_ppmm (_xh, _xl, q1, d); \
add_ssaaaa (_xh, _xl, _xh, _xl, nh, nl); \
_xh -= (d); \
(r) = _xl + ((d) & _xh); \
(q) = _xh - q1; \
} while (0)
/* Exactly like udiv_qrnnd_preinv, but branch-free. It is not clear which
version to use. */
#define udiv_qrnnd_preinv2norm(q, r, nh, nl, d, di) \
do { \
mp_limb_t n2, n10, n1, nadj, q1; \
mp_limb_t _xh, _xl; \
n2 = (nh); \
n10 = (nl); \
n1 = ((mp_limb_signed_t) n10 >> (BITS_PER_MP_LIMB - 1)); \
nadj = n10 + (n1 & (d)); \
umul_ppmm (_xh, _xl, di, n2 - n1); \
add_ssaaaa (_xh, _xl, _xh, _xl, 0, nadj); \
q1 = ~(n2 + _xh); \
umul_ppmm (_xh, _xl, q1, d); \
add_ssaaaa (_xh, _xl, _xh, _xl, nh, nl); \
_xh -= (d); \
(r) = _xl + ((d) & _xh); \
(q) = _xh - q1; \
} while (0)
#if defined (__GNUC__)
/* Define stuff for longlong.h. */
typedef unsigned int UQItype __attribute__ ((mode (QI)));
typedef int SItype __attribute__ ((mode (SI)));
typedef unsigned int USItype __attribute__ ((mode (SI)));
typedef int DItype __attribute__ ((mode (DI)));
typedef unsigned int UDItype __attribute__ ((mode (DI)));
#else
typedef unsigned char UQItype;
typedef long SItype;
typedef unsigned long USItype;
#endif
typedef mp_limb_t UWtype;
typedef unsigned int UHWtype;
#define W_TYPE_SIZE BITS_PER_MP_LIMB
/* Internal mpn calls */
#define impn_mul_n_basecase __MPN(impn_mul_n_basecase)
#define impn_mul_n __MPN(impn_mul_n)
#define impn_sqr_n_basecase __MPN(impn_sqr_n_basecase)
#define impn_sqr_n __MPN(impn_sqr_n)
/* Define ieee_double_extract and _GMP_IEEE_FLOATS. */
#if defined (_LITTLE_ENDIAN) || defined (__LITTLE_ENDIAN__) \
|| defined (__alpha) \
|| (defined (__arm__) && defined (__ARMWEL__)) \
|| defined (__clipper__) \
|| defined (__cris) \
|| defined (__i386__) \
|| defined (__i860__) \
|| defined (__i960__) \
|| defined (MIPSEL) || defined (_MIPSEL) \
|| defined (__ns32000__) \
|| defined (__WINNT) || defined (_WIN32)
#define _GMP_IEEE_FLOATS 1
union ieee_double_extract
{
struct
{
unsigned int manl:32;
unsigned int manh:20;
unsigned int exp:11;
unsigned int sig:1;
} s;
double d;
};
#else /* Need this as an #else since the tests aren't made exclusive. */
#if defined (_BIG_ENDIAN) \
|| defined (__a29k__) || defined (_AM29K) \
|| defined (__arm__) \
|| (defined (__convex__) && defined (_IEEE_FLOAT_)) \
|| defined (__i370__) || defined (__mvs__) \
|| defined (__mc68000__) || defined (__mc68020__) || defined (__NeXT__)\
|| defined(mc68020) \
|| defined (__m88000__) \
|| defined (MIPSEB) || defined (_MIPSEB) \
|| defined (__hppa) \
|| defined (__pyr__) \
|| defined (__ibm032__) \
|| defined (_IBMR2) || defined (_ARCH_PPC) \
|| defined (__sh__) \
|| defined (__sparc) || defined (sparc) \
|| defined (__we32k__)
#define _GMP_IEEE_FLOATS 1
union ieee_double_extract
{
struct
{
unsigned int sig:1;
unsigned int exp:11;
unsigned int manh:20;
unsigned int manl:32;
} s;
double d;
};
#endif
#endif
#define MP_BASE_AS_DOUBLE (2.0 * ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1)))
#if BITS_PER_MP_LIMB == 64
#define LIMBS_PER_DOUBLE 2
#else
#define LIMBS_PER_DOUBLE 3
#endif
double __gmp_scale2 _PROTO ((double, int));
int __gmp_extract_double _PROTO((mp_ptr, double));

View File

@ -1,302 +1,632 @@
/* gmp.h -- Definitions for GNU multiple precision functions.
Copyright (C) 1991, 1993 Free Software Foundation, Inc.
Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 General Public License for more details.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#ifndef __GMP_H__
#define __GMP_H__
#define __GNU_MP__
#ifndef __MP_H__
#ifndef __GNU_MP__
#define __GNU_MP__ 2
#define __need_size_t
#include <stddef.h>
#undef __need_size_t
#if defined (__STDC__) || defined (__cplusplus)
#define __gmp_const const
#else
#define __gmp_const
#endif
#ifndef MINT
#if defined (__GNUC__)
#define __gmp_inline __inline__
#else
#define __gmp_inline
#endif
#ifndef _EXTERN_INLINE
#ifdef __GNUC__
#define _EXTERN_INLINE extern __inline__
#else
#define _EXTERN_INLINE static
#endif
#endif
#ifdef _SHORT_LIMB
typedef unsigned int mp_limb_t;
typedef int mp_limb_signed_t;
#else
#ifdef _LONG_LONG_LIMB
typedef unsigned long long int mp_limb_t;
typedef long long int mp_limb_signed_t;
#else
typedef unsigned long int mp_limb_t;
typedef long int mp_limb_signed_t;
#endif
#endif
typedef mp_limb_t * mp_ptr;
typedef __gmp_const mp_limb_t * mp_srcptr;
typedef long int mp_size_t;
typedef long int mp_exp_t;
#ifndef __MP_SMALL__
typedef struct
{
long int alloc; /* Number of *limbs* allocated and pointed
int _mp_alloc; /* Number of *limbs* allocated and pointed
to by the D field. */
long int size; /* abs(SIZE) is the number of limbs
int _mp_size; /* abs(SIZE) is the number of limbs
the last field points to. If SIZE
is negative this is a negative
number. */
unsigned long int *d; /* Pointer to the limbs. */
} __MP_INT;
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpz_struct;
#else
typedef struct
{
short int alloc; /* Number of *limbs* allocated and pointed
short int _mp_alloc; /* Number of *limbs* allocated and pointed
to by the D field. */
short int size; /* abs(SIZE) is the number of limbs
short int _mp_size; /* abs(SIZE) is the number of limbs
the last field points to. If SIZE
is negative this is a negative
number. */
unsigned long int *d; /* Pointer to the limbs. */
} __MP_INT;
#endif
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpz_struct;
#endif
#endif /* __GNU_MP__ */
#define MP_INT __MP_INT
typedef unsigned long int mp_limb;
typedef long int mp_limb_signed;
typedef mp_limb * mp_ptr;
#ifdef __STDC__
typedef const mp_limb * mp_srcptr;
#else
typedef mp_limb * mp_srcptr;
#endif
typedef long int mp_size;
/* User-visible types. */
typedef __mpz_struct MP_INT;
typedef __mpz_struct mpz_t[1];
/* Structure for rational numbers. Zero is represented as 0/any, i.e.
the denominator is ignored. Negative numbers have the sign in
the numerator. */
typedef struct
{
MP_INT num;
MP_INT den;
__mpz_struct _mp_num;
__mpz_struct _mp_den;
#if 0
long int num_alloc; /* Number of limbs allocated
int _mp_num_alloc; /* Number of limbs allocated
for the numerator. */
long int num_size; /* The absolute value of this field is the
int _mp_num_size; /* The absolute value of this field is the
length of the numerator; the sign is the
sign of the entire rational number. */
mp_ptr num; /* Pointer to the numerator limbs. */
long int den_alloc; /* Number of limbs allocated
mp_ptr _mp_num; /* Pointer to the numerator limbs. */
int _mp_den_alloc; /* Number of limbs allocated
for the denominator. */
long int den_size; /* Length of the denominator. (This field
int _mp_den_size; /* Length of the denominator. (This field
should always be positive.) */
mp_ptr den; /* Pointer to the denominator limbs. */
mp_ptr _mp_den; /* Pointer to the denominator limbs. */
#endif
} MP_RAT;
} __mpq_struct;
#ifdef __STDC__
void mp_set_memory_functions (void *(*) (size_t),
void *(*) (void *, size_t, size_t),
void (*) (void *, size_t));
typedef __mpq_struct MP_RAT;
typedef __mpq_struct mpq_t[1];
typedef struct
{
int _mp_prec; /* Max precision, in number of `mp_limb_t's.
Set by mpf_init and modified by
mpf_set_prec. The area pointed to
by the `d' field contains `prec' + 1
limbs. */
int _mp_size; /* abs(SIZE) is the number of limbs
the last field points to. If SIZE
is negative this is a negative
number. */
mp_exp_t _mp_exp; /* Exponent, in the base of `mp_limb_t'. */
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpf_struct;
/* typedef __mpf_struct MP_FLOAT; */
typedef __mpf_struct mpf_t[1];
/* Types for function declarations in gmp files. */
/* ??? Should not pollute user name space with these ??? */
typedef __gmp_const __mpz_struct *mpz_srcptr;
typedef __mpz_struct *mpz_ptr;
typedef __gmp_const __mpf_struct *mpf_srcptr;
typedef __mpf_struct *mpf_ptr;
typedef __gmp_const __mpq_struct *mpq_srcptr;
typedef __mpq_struct *mpq_ptr;
#ifndef _PROTO
#if defined (__STDC__) || defined (__cplusplus)
#define _PROTO(x) x
#else
#define _PROTO(x) ()
#endif
#endif
#ifndef __MPN
#if defined (__STDC__) || defined (__cplusplus)
#define __MPN(x) __mpn_##x
#else
#define __MPN(x) __mpn_/**/x
#endif
#endif
#if defined (FILE) || defined (H_STDIO) || defined (_H_STDIO) \
|| defined (_STDIO_H) || defined (_STDIO_H_) || defined (__STDIO_H__) \
|| defined (_STDIO_INCLUDED)
#define _GMP_H_HAVE_FILE 1
#endif
void mp_set_memory_functions _PROTO ((void *(*) (size_t),
void *(*) (void *, size_t, size_t),
void (*) (void *, size_t)));
extern __gmp_const int mp_bits_per_limb;
/**************** Integer (i.e. Z) routines. ****************/
void mpz_init (MP_INT *);
void mpz_set (MP_INT *, const MP_INT *);
void mpz_set_ui (MP_INT *, unsigned long int);
void mpz_set_si (MP_INT *, signed long int);
int mpz_set_str (MP_INT *, const char *, int);
void mpz_init_set (MP_INT *, const MP_INT *);
void mpz_init_set_ui (MP_INT *, unsigned long int);
void mpz_init_set_si (MP_INT *, signed long int);
int mpz_init_set_str (MP_INT *, const char *, int);
unsigned long int mpz_get_ui (const MP_INT *);
signed long int mpz_get_si (const MP_INT *);
char * mpz_get_str (char *, int, const MP_INT *);
void mpz_clear (MP_INT *);
void * _mpz_realloc (MP_INT *, mp_size);
void mpz_add (MP_INT *, const MP_INT *, const MP_INT *);
void mpz_add_ui (MP_INT *, const MP_INT *, unsigned long int);
void mpz_sub (MP_INT *, const MP_INT *, const MP_INT *);
void mpz_sub_ui (MP_INT *, const MP_INT *, unsigned long int);
void mpz_mul (MP_INT *, const MP_INT *, const MP_INT *);
void mpz_mul_ui (MP_INT *, const MP_INT *, unsigned long int);
void mpz_div (MP_INT *, const MP_INT *, const MP_INT *);
void mpz_div_ui (MP_INT *, const MP_INT *, unsigned long int);
void mpz_mod (MP_INT *, const MP_INT *, const MP_INT *);
void mpz_mod_ui (MP_INT *, const MP_INT *, unsigned long int);
void mpz_divmod (MP_INT *, MP_INT *, const MP_INT *, const MP_INT *);
void mpz_divmod_ui (MP_INT *, MP_INT *, const MP_INT *, unsigned long int);
void mpz_mdiv (MP_INT *, const MP_INT *, const MP_INT *);
void mpz_mdiv_ui (MP_INT *, const MP_INT *, unsigned long int);
void mpz_mmod (MP_INT *, const MP_INT *, const MP_INT *);
unsigned long int mpz_mmod_ui (MP_INT *, const MP_INT *, unsigned long int);
void mpz_mdivmod (MP_INT *, MP_INT *, const MP_INT *, const MP_INT *);
unsigned long int mpz_mdivmod_ui (MP_INT *, MP_INT *, const MP_INT *,
unsigned long int);
void mpz_sqrt (MP_INT *, const MP_INT *);
void mpz_sqrtrem (MP_INT *, MP_INT *, const MP_INT *);
int mpz_perfect_square_p (const MP_INT *);
int mpz_probab_prime_p (const MP_INT *, int);
void mpz_powm (MP_INT *, const MP_INT *, const MP_INT *, const MP_INT *);
void mpz_powm_ui (MP_INT *, const MP_INT *, unsigned long int, const MP_INT *);
void mpz_pow_ui (MP_INT *, const MP_INT *, unsigned long int);
void mpz_fac_ui (MP_INT *, unsigned long int);
void mpz_gcd (MP_INT *, const MP_INT *, const MP_INT *);
void mpz_gcdext (MP_INT *, MP_INT *, MP_INT *, const MP_INT *, const MP_INT *);
void mpz_neg (MP_INT *, const MP_INT *);
void mpz_com (MP_INT *, const MP_INT *);
void mpz_abs (MP_INT *, const MP_INT *);
int mpz_cmp (const MP_INT *, const MP_INT *);
int mpz_cmp_ui (const MP_INT *, unsigned long int);
int mpz_cmp_si (const MP_INT *, signed long int);
void mpz_mul_2exp (MP_INT *, const MP_INT *, unsigned long int);
void mpz_div_2exp (MP_INT *, const MP_INT *, unsigned long int);
void mpz_mod_2exp (MP_INT *, const MP_INT *, unsigned long int);
void mpz_and (MP_INT *, const MP_INT *, const MP_INT *);
void mpz_ior (MP_INT *, const MP_INT *, const MP_INT *);
void mpz_xor (MP_INT *, const MP_INT *, const MP_INT *);
#if defined (__cplusplus)
extern "C" {
#endif
void *_mpz_realloc _PROTO ((mpz_ptr, mp_size_t));
#if defined (FILE) || defined (_STDIO_H) || defined (__STDIO_H__)
void mpz_inp_raw (MP_INT *, FILE *);
void mpz_inp_str (MP_INT *, FILE *, int);
void mpz_out_raw (FILE *, const MP_INT *);
void mpz_out_str (FILE *, int, const MP_INT *);
void mpz_abs _PROTO ((mpz_ptr, mpz_srcptr));
void mpz_add _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_add_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_and _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_array_init _PROTO ((mpz_ptr, mp_size_t, mp_size_t));
void mpz_cdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
unsigned long int mpz_cdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_cdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
unsigned long int mpz_cdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_cdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
unsigned long int mpz_cdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
unsigned long int mpz_cdiv_ui _PROTO ((mpz_srcptr, unsigned long int));
void mpz_clear _PROTO ((mpz_ptr));
void mpz_clrbit _PROTO ((mpz_ptr, unsigned long int));
int mpz_cmp _PROTO ((mpz_srcptr, mpz_srcptr));
int mpz_cmp_si _PROTO ((mpz_srcptr, signed long int));
int mpz_cmp_ui _PROTO ((mpz_srcptr, unsigned long int));
void mpz_com _PROTO ((mpz_ptr, mpz_srcptr));
void mpz_divexact _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_fac_ui _PROTO ((mpz_ptr, unsigned long int));
void mpz_fdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_fdiv_q_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
unsigned long int mpz_fdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_fdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
unsigned long int mpz_fdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_fdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_fdiv_r_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
unsigned long int mpz_fdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
unsigned long int mpz_fdiv_ui _PROTO ((mpz_srcptr, unsigned long int));
void mpz_gcd _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
unsigned long int mpz_gcd_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_gcdext _PROTO ((mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
double mpz_get_d _PROTO ((mpz_srcptr));
/* signed */ long int mpz_get_si _PROTO ((mpz_srcptr));
char *mpz_get_str _PROTO ((char *, int, mpz_srcptr));
unsigned long int mpz_get_ui _PROTO ((mpz_srcptr));
mp_limb_t mpz_getlimbn _PROTO ((mpz_srcptr, mp_size_t));
unsigned long int mpz_hamdist _PROTO ((mpz_srcptr, mpz_srcptr));
void mpz_init _PROTO ((mpz_ptr));
#ifdef _GMP_H_HAVE_FILE
size_t mpz_inp_binary _PROTO ((mpz_ptr, FILE *));
size_t mpz_inp_raw _PROTO ((mpz_ptr, FILE *));
size_t mpz_inp_str _PROTO ((mpz_ptr, FILE *, int));
#endif
void mpz_init_set _PROTO ((mpz_ptr, mpz_srcptr));
void mpz_init_set_d _PROTO ((mpz_ptr, double));
void mpz_init_set_si _PROTO ((mpz_ptr, signed long int));
int mpz_init_set_str _PROTO ((mpz_ptr, const char *, int));
void mpz_init_set_ui _PROTO ((mpz_ptr, unsigned long int));
int mpz_invert _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_ior _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
int mpz_jacobi _PROTO ((mpz_srcptr, mpz_srcptr));
int mpz_legendre _PROTO ((mpz_srcptr, mpz_srcptr));
void mpz_mod _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_mul _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_mul_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_mul_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_neg _PROTO ((mpz_ptr, mpz_srcptr));
#ifdef _GMP_H_HAVE_FILE
size_t mpz_out_binary _PROTO ((FILE *, mpz_srcptr));
size_t mpz_out_raw _PROTO ((FILE *, mpz_srcptr));
size_t mpz_out_str _PROTO ((FILE *, int, mpz_srcptr));
#endif
int mpz_perfect_square_p _PROTO ((mpz_srcptr));
unsigned long int mpz_popcount _PROTO ((mpz_srcptr));
void mpz_pow_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_powm _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr));
void mpz_powm_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int, mpz_srcptr));
int mpz_probab_prime_p _PROTO ((mpz_srcptr, int));
void mpz_random _PROTO ((mpz_ptr, mp_size_t));
void mpz_random2 _PROTO ((mpz_ptr, mp_size_t));
unsigned long int mpz_scan0 _PROTO ((mpz_srcptr, unsigned long int));
unsigned long int mpz_scan1 _PROTO ((mpz_srcptr, unsigned long int));
void mpz_set _PROTO ((mpz_ptr, mpz_srcptr));
void mpz_set_d _PROTO ((mpz_ptr, double));
void mpz_set_f _PROTO ((mpz_ptr, mpf_srcptr));
void mpz_set_q _PROTO ((mpz_ptr, mpq_srcptr));
void mpz_set_si _PROTO ((mpz_ptr, signed long int));
int mpz_set_str _PROTO ((mpz_ptr, const char *, int));
void mpz_set_ui _PROTO ((mpz_ptr, unsigned long int));
void mpz_setbit _PROTO ((mpz_ptr, unsigned long int));
size_t mpz_size _PROTO ((mpz_srcptr));
size_t mpz_sizeinbase _PROTO ((mpz_srcptr, int));
void mpz_sqrt _PROTO ((mpz_ptr, mpz_srcptr));
void mpz_sqrtrem _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr));
void mpz_sub _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_sub_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_tdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_tdiv_q_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_tdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_tdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_tdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_tdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_tdiv_r_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_tdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_ui_pow_ui _PROTO ((mpz_ptr, unsigned long int, unsigned long int));
/**************** Rational (i.e. Q) routines. ****************/
void mpq_init _PROTO ((mpq_ptr));
void mpq_clear _PROTO ((mpq_ptr));
void mpq_set _PROTO ((mpq_ptr, mpq_srcptr));
void mpq_set_ui _PROTO ((mpq_ptr, unsigned long int, unsigned long int));
void mpq_set_si _PROTO ((mpq_ptr, signed long int, unsigned long int));
void mpq_set_z _PROTO ((mpq_ptr, mpz_srcptr));
void mpq_add _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
void mpq_sub _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
void mpq_mul _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
void mpq_div _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
void mpq_neg _PROTO ((mpq_ptr, mpq_srcptr));
int mpq_cmp _PROTO ((mpq_srcptr, mpq_srcptr));
int mpq_cmp_ui _PROTO ((mpq_srcptr, unsigned long int, unsigned long int));
int mpq_equal _PROTO ((mpq_srcptr, mpq_srcptr));
void mpq_inv _PROTO ((mpq_ptr, mpq_srcptr));
void mpq_set_num _PROTO ((mpq_ptr, mpz_srcptr));
void mpq_set_den _PROTO ((mpq_ptr, mpz_srcptr));
void mpq_get_num _PROTO ((mpz_ptr, mpq_srcptr));
void mpq_get_den _PROTO ((mpz_ptr, mpq_srcptr));
double mpq_get_d _PROTO ((mpq_srcptr));
void mpq_canonicalize _PROTO ((mpq_ptr));
/**************** Float (i.e. F) routines. ****************/
void mpf_abs _PROTO ((mpf_ptr, mpf_srcptr));
void mpf_add _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
void mpf_add_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_clear _PROTO ((mpf_ptr));
int mpf_cmp _PROTO ((mpf_srcptr, mpf_srcptr));
int mpf_cmp_si _PROTO ((mpf_srcptr, signed long int));
int mpf_cmp_ui _PROTO ((mpf_srcptr, unsigned long int));
void mpf_div _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
void mpf_div_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_div_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_dump _PROTO ((mpf_srcptr));
int mpf_eq _PROTO ((mpf_srcptr, mpf_srcptr, unsigned long int));
double mpf_get_d _PROTO ((mpf_srcptr));
unsigned long int mpf_get_prec _PROTO ((mpf_srcptr));
char *mpf_get_str _PROTO ((char *, mp_exp_t *, int, size_t, mpf_srcptr));
void mpf_init _PROTO ((mpf_ptr));
void mpf_init2 _PROTO ((mpf_ptr, unsigned long int));
#ifdef _GMP_H_HAVE_FILE
size_t mpf_inp_str _PROTO ((mpf_ptr, FILE *, int));
#endif
void mpf_init_set _PROTO ((mpf_ptr, mpf_srcptr));
void mpf_init_set_d _PROTO ((mpf_ptr, double));
void mpf_init_set_si _PROTO ((mpf_ptr, signed long int));
int mpf_init_set_str _PROTO ((mpf_ptr, const char *, int));
void mpf_init_set_ui _PROTO ((mpf_ptr, unsigned long int));
void mpf_mul _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
void mpf_mul_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_mul_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_neg _PROTO ((mpf_ptr, mpf_srcptr));
#ifdef _GMP_H_HAVE_FILE
size_t mpf_out_str _PROTO ((FILE *, int, size_t, mpf_srcptr));
#endif
void mpf_random2 _PROTO ((mpf_ptr, mp_size_t, mp_exp_t));
void mpf_reldiff _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
void mpf_set _PROTO ((mpf_ptr, mpf_srcptr));
void mpf_set_d _PROTO ((mpf_ptr, double));
void mpf_set_default_prec _PROTO ((unsigned long int));
void mpf_set_prec _PROTO ((mpf_ptr, unsigned long int));
void mpf_set_prec_raw _PROTO ((mpf_ptr, unsigned long int));
void mpf_set_q _PROTO ((mpf_ptr, mpq_srcptr));
void mpf_set_si _PROTO ((mpf_ptr, signed long int));
int mpf_set_str _PROTO ((mpf_ptr, const char *, int));
void mpf_set_ui _PROTO ((mpf_ptr, unsigned long int));
void mpf_set_z _PROTO ((mpf_ptr, mpz_srcptr));
size_t mpf_size _PROTO ((mpf_srcptr));
void mpf_sqrt _PROTO ((mpf_ptr, mpf_srcptr));
void mpf_sqrt_ui _PROTO ((mpf_ptr, unsigned long int));
void mpf_sub _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
void mpf_sub_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_ui_div _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
void mpf_ui_sub _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
#if defined (__cplusplus)
}
#endif
/************ Low level positive-integer (i.e. N) routines. ************/
/* This is ugly, but we need to make usr calls reach the prefixed function. */
#define mpn_add __MPN(add)
#define mpn_add_1 __MPN(add_1)
#define mpn_add_n __MPN(add_n)
#define mpn_addmul_1 __MPN(addmul_1)
#define mpn_bdivmod __MPN(bdivmod)
#define mpn_cmp __MPN(cmp)
#define mpn_divmod_1 __MPN(divmod_1)
#define mpn_divrem __MPN(divrem)
#define mpn_divrem_1 __MPN(divrem_1)
#define mpn_dump __MPN(dump)
#define mpn_gcd __MPN(gcd)
#define mpn_gcd_1 __MPN(gcd_1)
#define mpn_gcdext __MPN(gcdext)
#define mpn_get_str __MPN(get_str)
#define mpn_hamdist __MPN(hamdist)
#define mpn_lshift __MPN(lshift)
#define mpn_mod_1 __MPN(mod_1)
#define mpn_mul __MPN(mul)
#define mpn_mul_1 __MPN(mul_1)
#define mpn_mul_n __MPN(mul_n)
#define mpn_perfect_square_p __MPN(perfect_square_p)
#define mpn_popcount __MPN(popcount)
#define mpn_preinv_mod_1 __MPN(preinv_mod_1)
#define mpn_random2 __MPN(random2)
#define mpn_rshift __MPN(rshift)
#define mpn_scan0 __MPN(scan0)
#define mpn_scan1 __MPN(scan1)
#define mpn_set_str __MPN(set_str)
#define mpn_sqrtrem __MPN(sqrtrem)
#define mpn_sub __MPN(sub)
#define mpn_sub_1 __MPN(sub_1)
#define mpn_sub_n __MPN(sub_n)
#define mpn_submul_1 __MPN(submul_1)
#define mpn_udiv_w_sdiv __MPN(udiv_w_sdiv)
#if defined (__cplusplus)
extern "C" {
#endif
mp_limb_t mpn_add _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
mp_limb_t mpn_add_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
mp_limb_t mpn_add_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
mp_limb_t mpn_addmul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
mp_limb_t mpn_bdivmod _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int));
int mpn_cmp _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
mp_limb_t mpn_divmod_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
mp_limb_t mpn_divrem _PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t));
mp_limb_t mpn_divrem_1 _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t));
void mpn_dump _PROTO ((mp_srcptr, mp_size_t));
mp_size_t mpn_gcd _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
mp_limb_t mpn_gcd_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
mp_size_t mpn_gcdext _PROTO ((mp_ptr, mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
size_t mpn_get_str _PROTO ((unsigned char *, int, mp_ptr, mp_size_t));
unsigned long int mpn_hamdist _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
mp_limb_t mpn_lshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
mp_limb_t mpn_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
mp_limb_t mpn_mul _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t));
mp_limb_t mpn_mul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
void mpn_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
int mpn_perfect_square_p _PROTO ((mp_srcptr, mp_size_t));
unsigned long int mpn_popcount _PROTO ((mp_srcptr, mp_size_t));
mp_limb_t mpn_preinv_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t));
void mpn_random2 _PROTO ((mp_ptr, mp_size_t));
mp_limb_t mpn_rshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
unsigned long int mpn_scan0 _PROTO ((mp_srcptr, unsigned long int));
unsigned long int mpn_scan1 _PROTO ((mp_srcptr, unsigned long int));
mp_size_t mpn_set_str _PROTO ((mp_ptr, const unsigned char *, size_t, int));
mp_size_t mpn_sqrtrem _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t));
mp_limb_t mpn_sub _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
mp_limb_t mpn_sub_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
mp_limb_t mpn_sub_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
mp_limb_t mpn_submul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
#if defined (__cplusplus)
}
#endif
void mpz_array_init (MP_INT [], size_t, mp_size);
void mpz_random (MP_INT *, mp_size);
void mpz_random2 (MP_INT *, mp_size);
size_t mpz_size (const MP_INT *);
size_t mpz_sizeinbase (const MP_INT *, int);
#if defined (__GNUC__) || defined (_FORCE_INLINES)
_EXTERN_INLINE mp_limb_t
#if defined (__STDC__) || defined (__cplusplus)
mpn_add_1 (register mp_ptr res_ptr,
register mp_srcptr s1_ptr,
register mp_size_t s1_size,
register mp_limb_t s2_limb)
#else
mpn_add_1 (res_ptr, s1_ptr, s1_size, s2_limb)
register mp_ptr res_ptr;
register mp_srcptr s1_ptr;
register mp_size_t s1_size;
register mp_limb_t s2_limb;
#endif
{
register mp_limb_t x;
/**************** Rational (i.e. Q) routines. ****************/
x = *s1_ptr++;
s2_limb = x + s2_limb;
*res_ptr++ = s2_limb;
if (s2_limb < x)
{
while (--s1_size != 0)
{
x = *s1_ptr++ + 1;
*res_ptr++ = x;
if (x != 0)
goto fin;
}
void mpq_init (MP_RAT *);
void mpq_clear (MP_RAT *);
void mpq_set (MP_RAT *, const MP_RAT *);
void mpq_set_ui (MP_RAT *, unsigned long int, unsigned long int);
void mpq_set_si (MP_RAT *, signed long int, unsigned long int);
void mpq_add (MP_RAT *, const MP_RAT *, const MP_RAT *);
void mpq_sub (MP_RAT *, const MP_RAT *, const MP_RAT *);
void mpq_mul (MP_RAT *, const MP_RAT *, const MP_RAT *);
void mpq_div (MP_RAT *, const MP_RAT *, const MP_RAT *);
void mpq_neg (MP_RAT *, const MP_RAT *);
int mpq_cmp (const MP_RAT *, const MP_RAT *);
void mpq_inv (MP_RAT *, const MP_RAT *);
void mpq_set_num (MP_RAT *, const MP_INT *);
void mpq_set_den (MP_RAT *, const MP_INT *);
void mpq_get_num (MP_INT *, const MP_RAT *);
void mpq_get_den (MP_INT *, const MP_RAT *);
return 1;
}
/************ Low level positive-integer (i.e. N) routines. ************/
fin:
if (res_ptr != s1_ptr)
{
mp_size_t i;
for (i = 0; i < s1_size - 1; i++)
res_ptr[i] = s1_ptr[i];
}
return 0;
}
mp_limb mpn_add (mp_ptr, mp_srcptr, mp_size, mp_srcptr, mp_size);
mp_size mpn_sub (mp_ptr, mp_srcptr, mp_size, mp_srcptr, mp_size);
mp_size mpn_mul (mp_ptr, mp_srcptr, mp_size, mp_srcptr, mp_size);
mp_size mpn_div (mp_ptr, mp_ptr, mp_size, mp_srcptr, mp_size);
mp_limb mpn_divmod_1 (mp_ptr, mp_srcptr, mp_size, mp_limb);
mp_limb mpn_mod_1 (mp_srcptr, mp_size, mp_limb);
mp_limb mpn_lshift (mp_ptr, mp_srcptr, mp_size, unsigned int);
mp_size mpn_rshift (mp_ptr, mp_srcptr, mp_size, unsigned int);
mp_size mpn_rshiftci (mp_ptr, mp_srcptr, mp_size, unsigned int, mp_limb);
mp_size mpn_sqrt (mp_ptr, mp_ptr, mp_srcptr, mp_size);
int mpn_cmp (mp_srcptr, mp_srcptr, mp_size);
_EXTERN_INLINE mp_limb_t
#if defined (__STDC__) || defined (__cplusplus)
mpn_add (register mp_ptr res_ptr,
register mp_srcptr s1_ptr,
register mp_size_t s1_size,
register mp_srcptr s2_ptr,
register mp_size_t s2_size)
#else
mpn_add (res_ptr, s1_ptr, s1_size, s2_ptr, s2_size)
register mp_ptr res_ptr;
register mp_srcptr s1_ptr;
register mp_size_t s1_size;
register mp_srcptr s2_ptr;
register mp_size_t s2_size;
#endif
{
mp_limb_t cy_limb = 0;
#else /* ! __STDC__ */
void mp_set_memory_functions ();
if (s2_size != 0)
cy_limb = mpn_add_n (res_ptr, s1_ptr, s2_ptr, s2_size);
/**************** Integer (i.e. Z) routines. ****************/
if (s1_size - s2_size != 0)
cy_limb = mpn_add_1 (res_ptr + s2_size,
s1_ptr + s2_size,
s1_size - s2_size,
cy_limb);
return cy_limb;
}
void mpz_init ();
void mpz_set ();
void mpz_set_ui ();
void mpz_set_si ();
int mpz_set_str ();
void mpz_init_set ();
void mpz_init_set_ui ();
void mpz_init_set_si ();
int mpz_init_set_str ();
unsigned long int mpz_get_ui ();
long int mpz_get_si ();
char * mpz_get_str ();
void mpz_clear ();
void * _mpz_realloc ();
void mpz_add ();
void mpz_add_ui ();
void mpz_sub ();
void mpz_sub_ui ();
void mpz_mul ();
void mpz_mul_ui ();
void mpz_div ();
void mpz_div_ui ();
void mpz_mod ();
void mpz_mod_ui ();
void mpz_divmod ();
void mpz_divmod_ui ();
void mpz_mdiv ();
void mpz_mdiv_ui ();
void mpz_mmod ();
unsigned long int mpz_mmod_ui ();
void mpz_mdivmod ();
unsigned long int mpz_mdivmod_ui ();
void mpz_sqrt ();
void mpz_sqrtrem ();
int mpz_perfect_square_p ();
int mpz_probab_prime_p ();
void mpz_powm ();
void mpz_powm_ui ();
void mpz_pow_ui ();
void mpz_fac_ui ();
void mpz_gcd ();
void mpz_gcdext ();
void mpz_neg ();
void mpz_com ();
void mpz_abs ();
int mpz_cmp ();
int mpz_cmp_ui ();
int mpz_cmp_si ();
void mpz_mul_2exp ();
void mpz_div_2exp ();
void mpz_mod_2exp ();
void mpz_and ();
void mpz_ior ();
void mpz_xor ();
_EXTERN_INLINE mp_limb_t
#if defined (__STDC__) || defined (__cplusplus)
mpn_sub_1 (register mp_ptr res_ptr,
register mp_srcptr s1_ptr,
register mp_size_t s1_size,
register mp_limb_t s2_limb)
#else
mpn_sub_1 (res_ptr, s1_ptr, s1_size, s2_limb)
register mp_ptr res_ptr;
register mp_srcptr s1_ptr;
register mp_size_t s1_size;
register mp_limb_t s2_limb;
#endif
{
register mp_limb_t x;
void mpz_inp_raw ();
void mpz_inp_str ();
void mpz_out_raw ();
void mpz_out_str ();
x = *s1_ptr++;
s2_limb = x - s2_limb;
*res_ptr++ = s2_limb;
if (s2_limb > x)
{
while (--s1_size != 0)
{
x = *s1_ptr++;
*res_ptr++ = x - 1;
if (x != 0)
goto fin;
}
void mpz_array_init ();
void mpz_random ();
void mpz_random2 ();
size_t mpz_size ();
size_t mpz_sizeinbase ();
return 1;
}
/**************** Rational (i.e. Q) routines. ****************/
fin:
if (res_ptr != s1_ptr)
{
mp_size_t i;
for (i = 0; i < s1_size - 1; i++)
res_ptr[i] = s1_ptr[i];
}
return 0;
}
void mpq_init ();
void mpq_clear ();
void mpq_set ();
void mpq_set_ui ();
void mpq_set_si ();
void mpq_add ();
void mpq_sub ();
void mpq_mul ();
void mpq_div ();
void mpq_neg ();
int mpq_cmp ();
void mpq_inv ();
void mpq_set_num ();
void mpq_set_den ();
void mpq_get_num ();
void mpq_get_den ();
_EXTERN_INLINE mp_limb_t
#if defined (__STDC__) || defined (__cplusplus)
mpn_sub (register mp_ptr res_ptr,
register mp_srcptr s1_ptr,
register mp_size_t s1_size,
register mp_srcptr s2_ptr,
register mp_size_t s2_size)
#else
mpn_sub (res_ptr, s1_ptr, s1_size, s2_ptr, s2_size)
register mp_ptr res_ptr;
register mp_srcptr s1_ptr;
register mp_size_t s1_size;
register mp_srcptr s2_ptr;
register mp_size_t s2_size;
#endif
{
mp_limb_t cy_limb = 0;
/************ Low level positive-integer (i.e. N) routines. ************/
if (s2_size != 0)
cy_limb = mpn_sub_n (res_ptr, s1_ptr, s2_ptr, s2_size);
mp_limb mpn_add ();
mp_size mpn_sub ();
mp_size mpn_mul ();
mp_size mpn_div ();
mp_limb mpn_lshift ();
mp_size mpn_rshift ();
mp_size mpn_rshiftci ();
int mpn_cmp ();
#endif /* __STDC__ */
if (s1_size - s2_size != 0)
cy_limb = mpn_sub_1 (res_ptr + s2_size,
s1_ptr + s2_size,
s1_size - s2_size,
cy_limb);
return cy_limb;
}
#endif /* __GNUC__ */
/* Allow faster testing for negative, zero, and positive. */
#define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0)
#define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0)
#define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0)
/* Allow direct user access to numerator and denominator of a mpq_t object. */
#define mpq_numref(Q) (&((Q)->_mp_num))
#define mpq_denref(Q) (&((Q)->_mp_den))
/* When using GCC, optimize certain common comparisons. */
#if defined (__GNUC__)
#define mpz_cmp_ui(Z,UI) \
(__builtin_constant_p (UI) && (UI) == 0 \
? mpz_sgn (Z) : mpz_cmp_ui (Z,UI))
#define mpz_cmp_si(Z,UI) \
(__builtin_constant_p (UI) && (UI) == 0 ? mpz_sgn (Z) \
: __builtin_constant_p (UI) && (UI) > 0 ? mpz_cmp_ui (Z,UI) \
: mpz_cmp_si (Z,UI))
#define mpq_cmp_ui(Q,NUI,DUI) \
(__builtin_constant_p (NUI) && (NUI) == 0 \
? mpq_sgn (Q) : mpq_cmp_ui (Q,NUI,DUI))
#endif
#define mpn_divmod(qp,np,nsize,dp,dsize) mpn_divrem (qp,0,np,nsize,dp,dsize)
#if 0
#define mpn_divmod_1(qp,np,nsize,dlimb) mpn_divrem_1 (qp,0,np,nsize,dlimb)
#endif
/* Compatibility with GMP 1. */
#define mpz_mdiv mpz_fdiv_q
#define mpz_mdivmod mpz_fdiv_qr
#define mpz_mmod mpz_fdiv_r
#define mpz_mdiv_ui mpz_fdiv_q_ui
#define mpz_mdivmod_ui(q,r,n,d) \
((r == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d))
#define mpz_mmod_ui(r,n,d) \
((r == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d))
/* Useful synonyms, but not quite compatible with GMP 1. */
#define mpz_div mpz_fdiv_q
#define mpz_divmod mpz_fdiv_qr
#define mpz_div_ui mpz_fdiv_q_ui
#define mpz_divmod_ui mpz_fdiv_qr_ui
#define mpz_mod_ui mpz_fdiv_r_ui
#define mpz_div_2exp mpz_fdiv_q_2exp
#define mpz_mod_2exp mpz_fdiv_r_2exp
#define __GNU_MP_VERSION 2
#define __GNU_MP_VERSION_MINOR 0
#define __GMP_H__
#endif /* __GMP_H__ */

1283
gnu/lib/libgmp/gmp.info-1 Normal file

File diff suppressed because it is too large Load Diff

1035
gnu/lib/libgmp/gmp.info-2 Normal file

File diff suppressed because it is too large Load Diff

259
gnu/lib/libgmp/gmp.info-3 Normal file
View File

@ -0,0 +1,259 @@
This is Info file gmp.info, produced by Makeinfo-1.64 from the input
file gmp.texi.
START-INFO-DIR-ENTRY
* gmp: (gmp.info). GNU Multiple Precision Arithmetic Library.
END-INFO-DIR-ENTRY
This file documents GNU MP, a library for arbitrary-precision
arithmetic.
Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation,
Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that this permission notice may be stated in a
translation approved by the Foundation.

File: gmp.info, Node: Function Index, Up: Top
Function and Type Index
***********************
* Menu:
* mp_limb_t: MP Basics.
* mpf_t: MP Basics.
* mpq_t: MP Basics.
* mpz_t: MP Basics.
* __GNU_MP_VERSION: MP Basics.
* __GNU_MP_VERSION_MINOR: MP Basics.
* _mpz_realloc: Initializing Integers.
* allocate_function: Custom Allocation.
* deallocate_function: Custom Allocation.
* gcd: BSD Compatible Functions.
* itom: BSD Compatible Functions.
* madd: BSD Compatible Functions.
* mcmp: BSD Compatible Functions.
* mdiv: BSD Compatible Functions.
* mfree: BSD Compatible Functions.
* min: BSD Compatible Functions.
* mout: BSD Compatible Functions.
* move: BSD Compatible Functions.
* mp_set_memory_functions: Custom Allocation.
* mpf_abs: Float Arithmetic.
* mpf_add: Float Arithmetic.
* mpf_add_ui: Float Arithmetic.
* mpf_clear: Initializing Floats.
* mpf_cmp: Float Comparison.
* mpf_cmp_si: Float Comparison.
* mpf_cmp_ui: Float Comparison.
* mpf_div: Float Arithmetic.
* mpf_div_2exp: Float Arithmetic.
* mpf_div_ui: Float Arithmetic.
* mpf_eq: Float Comparison.
* mpf_get_d: Converting Floats.
* mpf_get_prec: Initializing Floats.
* mpf_get_str: Converting Floats.
* mpf_init: Initializing Floats.
* mpf_init2: Initializing Floats.
* mpf_init_set: Simultaneous Float Init & Assign.
* mpf_init_set_d: Simultaneous Float Init & Assign.
* mpf_init_set_si: Simultaneous Float Init & Assign.
* mpf_init_set_str: Simultaneous Float Init & Assign.
* mpf_init_set_ui: Simultaneous Float Init & Assign.
* mpf_inp_str: I/O of Floats.
* mpf_mul: Float Arithmetic.
* mpf_mul_2exp: Float Arithmetic.
* mpf_mul_ui: Float Arithmetic.
* mpf_neg: Float Arithmetic.
* mpf_out_str: I/O of Floats.
* mpf_random2: Miscellaneous Float Functions.
* mpf_reldiff: Float Comparison.
* mpf_set: Assigning Floats.
* mpf_set_d: Assigning Floats.
* mpf_set_default_prec: Initializing Floats.
* mpf_set_prec: Initializing Floats.
* mpf_set_prec_raw: Initializing Floats.
* mpf_set_q: Assigning Floats.
* mpf_set_si: Assigning Floats.
* mpf_set_str: Assigning Floats.
* mpf_set_ui: Assigning Floats.
* mpf_set_z: Assigning Floats.
* mpf_sgn: Float Comparison.
* mpf_sqrt: Float Arithmetic.
* mpf_sqrt_ui: Float Arithmetic.
* mpf_sub: Float Arithmetic.
* mpf_sub_ui: Float Arithmetic.
* mpf_ui_div: Float Arithmetic.
* mpf_ui_sub: Float Arithmetic.
* mpn_add: Low-level Functions.
* mpn_add_1: Low-level Functions.
* mpn_add_n: Low-level Functions.
* mpn_addmul_1: Low-level Functions.
* mpn_bdivmod: Low-level Functions.
* mpn_cmp: Low-level Functions.
* mpn_divmod: Low-level Functions.
* mpn_divmod_1: Low-level Functions.
* mpn_divrem: Low-level Functions.
* mpn_divrem_1: Low-level Functions.
* mpn_gcd: Low-level Functions.
* mpn_gcd_1: Low-level Functions.
* mpn_gcdext: Low-level Functions.
* mpn_get_str: Low-level Functions.
* mpn_hamdist: Low-level Functions.
* mpn_lshift: Low-level Functions.
* mpn_mod_1: Low-level Functions.
* mpn_mul: Low-level Functions.
* mpn_mul_1: Low-level Functions.
* mpn_mul_n: Low-level Functions.
* mpn_perfect_square_p: Low-level Functions.
* mpn_popcount: Low-level Functions.
* mpn_preinv_mod_1: Low-level Functions.
* mpn_random2: Low-level Functions.
* mpn_rshift: Low-level Functions.
* mpn_scan0: Low-level Functions.
* mpn_scan1: Low-level Functions.
* mpn_set_str: Low-level Functions.
* mpn_sqrtrem: Low-level Functions.
* mpn_sub: Low-level Functions.
* mpn_sub_1: Low-level Functions.
* mpn_sub_n: Low-level Functions.
* mpn_submul_1: Low-level Functions.
* mpq_add: Assigning Rationals.
* mpq_canonicalize: Rational Number Functions.
* mpq_clear: Initializing Rationals.
* mpq_cmp: Comparing Rationals.
* mpq_cmp_ui: Comparing Rationals.
* mpq_denref: Applying Integer Functions.
* mpq_div: Assigning Rationals.
* mpq_equal: Comparing Rationals.
* mpq_get_d: Miscellaneous Rational Functions.
* mpq_get_den: Miscellaneous Rational Functions.
* mpq_get_num: Miscellaneous Rational Functions.
* mpq_init: Initializing Rationals.
* mpq_inv: Assigning Rationals.
* mpq_mul: Assigning Rationals.
* mpq_neg: Assigning Rationals.
* mpq_numref: Applying Integer Functions.
* mpq_set: Initializing Rationals.
* mpq_set_den: Miscellaneous Rational Functions.
* mpq_set_num: Miscellaneous Rational Functions.
* mpq_set_si: Initializing Rationals.
* mpq_set_ui: Initializing Rationals.
* mpq_set_z: Initializing Rationals.
* mpq_sgn: Comparing Rationals.
* mpq_sub: Assigning Rationals.
* mpz_abs: Integer Arithmetic.
* mpz_add: Integer Arithmetic.
* mpz_add_ui: Integer Arithmetic.
* mpz_and: Integer Logic and Bit Fiddling.
* mpz_array_init: Initializing Integers.
* mpz_cdiv_q: Integer Arithmetic.
* mpz_cdiv_q_ui: Integer Arithmetic.
* mpz_cdiv_qr: Integer Arithmetic.
* mpz_cdiv_qr_ui: Integer Arithmetic.
* mpz_cdiv_r: Integer Arithmetic.
* mpz_cdiv_r_ui: Integer Arithmetic.
* mpz_cdiv_ui: Integer Arithmetic.
* mpz_clear: Initializing Integers.
* mpz_clrbit: Integer Logic and Bit Fiddling.
* mpz_cmp: Comparison Functions.
* mpz_cmp_si: Comparison Functions.
* mpz_cmp_ui: Comparison Functions.
* mpz_com: Integer Logic and Bit Fiddling.
* mpz_divexact: Integer Arithmetic.
* mpz_fac_ui: Integer Arithmetic.
* mpz_fdiv_q: Integer Arithmetic.
* mpz_fdiv_q_2exp: Integer Arithmetic.
* mpz_fdiv_q_ui: Integer Arithmetic.
* mpz_fdiv_qr: Integer Arithmetic.
* mpz_fdiv_qr_ui: Integer Arithmetic.
* mpz_fdiv_r: Integer Arithmetic.
* mpz_fdiv_r_2exp: Integer Arithmetic.
* mpz_fdiv_r_ui: Integer Arithmetic.
* mpz_fdiv_ui: Integer Arithmetic.
* mpz_gcd: Integer Arithmetic.
* mpz_gcd_ui: Integer Arithmetic.
* mpz_gcdext: Integer Arithmetic.
* mpz_get_d: Converting Integers.
* mpz_get_si: Converting Integers.
* mpz_get_str: Converting Integers.
* mpz_get_ui: Converting Integers.
* mpz_hamdist: Integer Logic and Bit Fiddling.
* mpz_init: Initializing Integers.
* mpz_init_set: Simultaneous Integer Init & Assign.
* mpz_init_set_d: Simultaneous Integer Init & Assign.
* mpz_init_set_si: Simultaneous Integer Init & Assign.
* mpz_init_set_str: Simultaneous Integer Init & Assign.
* mpz_init_set_ui: Simultaneous Integer Init & Assign.
* mpz_inp_raw: I/O of Integers.
* mpz_inp_str: I/O of Integers.
* mpz_invert: Integer Arithmetic.
* mpz_ior: Integer Logic and Bit Fiddling.
* mpz_jacobi: Integer Arithmetic.
* mpz_legendre: Integer Arithmetic.
* mpz_mod: Integer Arithmetic.
* mpz_mod_ui: Integer Arithmetic.
* mpz_mul: Integer Arithmetic.
* mpz_mul_2exp: Integer Arithmetic.
* mpz_mul_ui: Integer Arithmetic.
* mpz_neg: Integer Arithmetic.
* mpz_out_raw: I/O of Integers.
* mpz_out_str: I/O of Integers.
* mpz_perfect_square_p: Integer Arithmetic.
* mpz_popcount: Integer Logic and Bit Fiddling.
* mpz_pow_ui: Integer Arithmetic.
* mpz_powm: Integer Arithmetic.
* mpz_powm_ui: Integer Arithmetic.
* mpz_probab_prime_p: Integer Arithmetic.
* mpz_random: Miscellaneous Integer Functions.
* mpz_random2: Miscellaneous Integer Functions.
* mpz_scan0: Integer Logic and Bit Fiddling.
* mpz_scan1: Integer Logic and Bit Fiddling.
* mpz_set: Assigning Integers.
* mpz_set_d: Assigning Integers.
* mpz_set_f: Assigning Integers.
* mpz_set_q: Assigning Integers.
* mpz_set_si: Assigning Integers.
* mpz_set_str: Assigning Integers.
* mpz_set_ui: Assigning Integers.
* mpz_setbit: Integer Logic and Bit Fiddling.
* mpz_sgn: Comparison Functions.
* mpz_size: Miscellaneous Integer Functions.
* mpz_sizeinbase: Miscellaneous Integer Functions.
* mpz_sqrt: Integer Arithmetic.
* mpz_sqrtrem: Integer Arithmetic.
* mpz_sub: Integer Arithmetic.
* mpz_sub_ui: Integer Arithmetic.
* mpz_tdiv_q: Integer Arithmetic.
* mpz_tdiv_q_2exp: Integer Arithmetic.
* mpz_tdiv_q_ui: Integer Arithmetic.
* mpz_tdiv_qr: Integer Arithmetic.
* mpz_tdiv_qr_ui: Integer Arithmetic.
* mpz_tdiv_r: Integer Arithmetic.
* mpz_tdiv_r_2exp: Integer Arithmetic.
* mpz_tdiv_r_ui: Integer Arithmetic.
* mpz_ui_pow_ui: Integer Arithmetic.
* msqrt: BSD Compatible Functions.
* msub: BSD Compatible Functions.
* mtox: BSD Compatible Functions.
* mult: BSD Compatible Functions.
* pow: BSD Compatible Functions.
* reallocate_function: Custom Allocation.
* rpow: BSD Compatible Functions.
* sdiv: BSD Compatible Functions.
* xtom: BSD Compatible Functions.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,70 @@
/* __gmp_insert_double -- convert from array of mp_limb_t to double.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#ifdef XDEBUG
#undef _GMP_IEEE_FLOATS
#endif
#ifndef _GMP_IEEE_FLOATS
#define _GMP_IEEE_FLOATS 0
#endif
double
#if __STDC__
__gmp_scale2 (double d, int exp)
#else
__gmp_scale2 (d, exp)
double d;
int exp;
#endif
{
#if _GMP_IEEE_FLOATS
{
union ieee_double_extract x;
x.d = d;
x.s.exp += exp;
return x.d;
}
#else
{
double factor, r;
factor = 2.0;
if (exp < 0)
{
factor = 0.5;
exp = -exp;
}
r = d;
while (exp != 0)
{
if ((exp & 1) != 0)
r *= factor;
factor *= factor;
exp >>= 1;
}
return r;
}
#endif
}

238
gnu/lib/libgmp/install.sh Executable file
View File

@ -0,0 +1,238 @@
#! /bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch.
#
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

File diff suppressed because it is too large Load Diff

315
gnu/lib/libgmp/make.bat Executable file
View File

@ -0,0 +1,315 @@
cd mpn
copy msdos\asm-synt.h asm-synt.h
copy bsd.h sysdep.h
copy generic\inlines.c inlines.c
copy x86\pentium\add_n.S add_n.S
copy x86\pentium\addmul_1.S addmul_1.S
copy generic\cmp.c cmp.c
copy generic\divmod_1.c divmod_1.c
copy generic\divrem.c divrem.c
copy generic\divrem_1.c divrem_1.c
copy generic\dump.c dump.c
copy x86\pentium\lshift.S lshift.S
copy generic\mod_1.c mod_1.c
copy generic\mul.c mul.c
copy x86\pentium\mul_1.S mul_1.S
copy generic\mul_n.c mul_n.c
copy generic\random2.c random2.c
copy x86\pentium\rshift.S rshift.S
copy generic\sqrtrem.c sqrtrem.c
copy x86\pentium\sub_n.S sub_n.S
copy x86\pentium\submul_1.S submul_1.S
copy generic\get_str.c get_str.c
copy generic\set_str.c set_str.c
copy generic\scan0.c scan0.c
copy generic\scan1.c scan1.c
copy generic\popcount.c popcount.c
copy generic\hamdist.c hamdist.c
copy generic\gcd_1.c gcd_1.c
copy generic\pre_mod_1.c pre_mod_1.c
copy generic\perfsqr.c perfsqr.c
copy generic\bdivmod.c bdivmod.c
copy generic\gcd.c gcd.c
copy generic\gcdext.c gcdext.c
copy x86\gmp-mpar.h gmp-mpar.h
cd ..
cd mpbsd
copy ..\mpz\add.c add.c
copy ..\mpz\cmp.c cmp.c
copy ..\mpz\gcd.c gcd.c
copy ..\mpz\mul.c mul.c
copy ..\mpz\pow_ui.c pow_ui.c
copy ..\mpz\powm.c powm.c
copy ..\mpz\sqrtrem.c sqrtrem.c
copy ..\mpz\sub.c sub.c
cd ..
cd mpn
gcc -c -I. -I.. -g -O mp_bases.c
gcc -c -I. -I.. -g -O inlines.c
gcc -E -I. -I.. -g -O add_n.S | grep -v '^#' >tmp-add_n.s
gcc -c tmp-add_n.s -o add_n.o
del tmp-add_n.s
gcc -E -I. -I.. -g -O addmul_1.S | grep -v '^#' >tmp-addmul_1.s
gcc -c tmp-addmul_1.s -o addmul_1.o
del tmp-addmul_1.s
gcc -c -I. -I.. -g -O cmp.c
gcc -c -I. -I.. -g -O divmod_1.c
gcc -c -I. -I.. -g -O divrem.c
gcc -c -I. -I.. -g -O divrem_1.c
gcc -c -I. -I.. -g -O dump.c
gcc -E -I. -I.. -g -O lshift.S | grep -v '^#' >tmp-lshift.s
gcc -c tmp-lshift.s -o lshift.o
del tmp-lshift.s
gcc -c -I. -I.. -g -O mod_1.c
gcc -c -I. -I.. -g -O mul.c
gcc -E -I. -I.. -g -O mul_1.S | grep -v '^#' >tmp-mul_1.s
gcc -c tmp-mul_1.s -o mul_1.o
del tmp-mul_1.s
gcc -c -I. -I.. -g -O mul_n.c
gcc -c -I. -I.. -g -O random2.c
gcc -E -I. -I.. -g -O rshift.S | grep -v '^#' >tmp-rshift.s
gcc -c tmp-rshift.s -o rshift.o
del tmp-rshift.s
gcc -c -I. -I.. -g -O sqrtrem.c
gcc -E -I. -I.. -g -O sub_n.S | grep -v '^#' >tmp-sub_n.s
gcc -c tmp-sub_n.s -o sub_n.o
del tmp-sub_n.s
gcc -E -I. -I.. -g -O submul_1.S | grep -v '^#' >tmp-submul_1.s
gcc -c tmp-submul_1.s -o submul_1.o
del tmp-submul_1.s
gcc -c -I. -I.. -g -O get_str.c
gcc -c -I. -I.. -g -O set_str.c
gcc -c -I. -I.. -g -O scan0.c
gcc -c -I. -I.. -g -O scan1.c
gcc -c -I. -I.. -g -O popcount.c
gcc -c -I. -I.. -g -O hamdist.c
gcc -c -I. -I.. -g -O gcd_1.c
gcc -c -I. -I.. -g -O pre_mod_1.c
gcc -c -I. -I.. -g -O perfsqr.c
gcc -c -I. -I.. -g -O bdivmod.c
gcc -c -I. -I.. -g -O gcd.c
gcc -c -I. -I.. -g -O gcdext.c
del libmpn.a
ar rc libmpn.a *.o
cd ..
cd mpz
gcc -c -I. -I.. -I../mpn -g -O abs.c
gcc -c -I. -I.. -I../mpn -g -O add.c
gcc -c -I. -I.. -I../mpn -g -O add_ui.c
gcc -c -I. -I.. -I../mpn -g -O and.c
gcc -c -I. -I.. -I../mpn -g -O array_init.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_q.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_q_ui.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_qr.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_qr_ui.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_r.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_r_ui.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_ui.c
gcc -c -I. -I.. -I../mpn -g -O clear.c
gcc -c -I. -I.. -I../mpn -g -O clrbit.c
gcc -c -I. -I.. -I../mpn -g -O cmp.c
gcc -c -I. -I.. -I../mpn -g -O cmp_si.c
gcc -c -I. -I.. -I../mpn -g -O cmp_ui.c
gcc -c -I. -I.. -I../mpn -g -O com.c
gcc -c -I. -I.. -I../mpn -g -O divexact.c
gcc -c -I. -I.. -I../mpn -g -O fac_ui.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_q.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_q_2exp.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_q_ui.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_qr.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_qr_ui.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_r.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_r_2exp.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_r_ui.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_ui.c
gcc -c -I. -I.. -I../mpn -g -O gcd.c
gcc -c -I. -I.. -I../mpn -g -O gcd_ui.c
gcc -c -I. -I.. -I../mpn -g -O gcdext.c
gcc -c -I. -I.. -I../mpn -g -O get_d.c
gcc -c -I. -I.. -I../mpn -g -O get_si.c
gcc -c -I. -I.. -I../mpn -g -O get_str.c
gcc -c -I. -I.. -I../mpn -g -O get_ui.c
gcc -c -I. -I.. -I../mpn -g -O getlimbn.c
gcc -c -I. -I.. -I../mpn -g -O hamdist.c
gcc -c -I. -I.. -I../mpn -g -O init.c
gcc -c -I. -I.. -I../mpn -g -O inp_raw.c
gcc -c -I. -I.. -I../mpn -g -O inp_str.c
gcc -c -I. -I.. -I../mpn -g -O invert.c
gcc -c -I. -I.. -I../mpn -g -O ior.c
gcc -c -I. -I.. -I../mpn -g -O iset.c
gcc -c -I. -I.. -I../mpn -g -O iset_d.c
gcc -c -I. -I.. -I../mpn -g -O iset_si.c
gcc -c -I. -I.. -I../mpn -g -O iset_str.c
gcc -c -I. -I.. -I../mpn -g -O iset_ui.c
gcc -c -I. -I.. -I../mpn -g -O jacobi.c
gcc -c -I. -I.. -I../mpn -g -O legendre.c
gcc -c -I. -I.. -I../mpn -g -O mod.c
gcc -c -I. -I.. -I../mpn -g -O mul.c
gcc -c -I. -I.. -I../mpn -g -O mul_2exp.c
gcc -c -I. -I.. -I../mpn -g -O mul_ui.c
gcc -c -I. -I.. -I../mpn -g -O neg.c
gcc -c -I. -I.. -I../mpn -g -O out_raw.c
gcc -c -I. -I.. -I../mpn -g -O out_str.c
gcc -c -I. -I.. -I../mpn -g -O perfsqr.c
gcc -c -I. -I.. -I../mpn -g -O popcount.c
gcc -c -I. -I.. -I../mpn -g -O pow_ui.c
gcc -c -I. -I.. -I../mpn -g -O powm.c
gcc -c -I. -I.. -I../mpn -g -O powm_ui.c
gcc -c -I. -I.. -I../mpn -g -O pprime_p.c
gcc -c -I. -I.. -I../mpn -g -O random.c
gcc -c -I. -I.. -I../mpn -g -O random2.c
gcc -c -I. -I.. -I../mpn -g -O realloc.c
gcc -c -I. -I.. -I../mpn -g -O scan0.c
gcc -c -I. -I.. -I../mpn -g -O scan1.c
gcc -c -I. -I.. -I../mpn -g -O set.c
gcc -c -I. -I.. -I../mpn -g -O set_d.c
gcc -c -I. -I.. -I../mpn -g -O set_f.c
gcc -c -I. -I.. -I../mpn -g -O set_q.c
gcc -c -I. -I.. -I../mpn -g -O set_si.c
gcc -c -I. -I.. -I../mpn -g -O set_str.c
gcc -c -I. -I.. -I../mpn -g -O set_ui.c
gcc -c -I. -I.. -I../mpn -g -O setbit.c
gcc -c -I. -I.. -I../mpn -g -O size.c
gcc -c -I. -I.. -I../mpn -g -O sizeinbase.c
gcc -c -I. -I.. -I../mpn -g -O sqrt.c
gcc -c -I. -I.. -I../mpn -g -O sqrtrem.c
gcc -c -I. -I.. -I../mpn -g -O sub.c
gcc -c -I. -I.. -I../mpn -g -O sub_ui.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_q.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_q_2exp.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_q_ui.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_qr.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_qr_ui.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_r.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_r_2exp.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_r_ui.c
gcc -c -I. -I.. -I../mpn -g -O ui_pow_ui.c
del libmpz.a
ar rc libmpz.a *.o
cd ..
cd mpf
gcc -c -I. -I.. -I../mpn -g -O abs.c
gcc -c -I. -I.. -I../mpn -g -O add.c
gcc -c -I. -I.. -I../mpn -g -O add_ui.c
gcc -c -I. -I.. -I../mpn -g -O clear.c
gcc -c -I. -I.. -I../mpn -g -O cmp.c
gcc -c -I. -I.. -I../mpn -g -O cmp_si.c
gcc -c -I. -I.. -I../mpn -g -O cmp_ui.c
gcc -c -I. -I.. -I../mpn -g -O div.c
gcc -c -I. -I.. -I../mpn -g -O div_2exp.c
gcc -c -I. -I.. -I../mpn -g -O div_ui.c
gcc -c -I. -I.. -I../mpn -g -O dump.c
gcc -c -I. -I.. -I../mpn -g -O eq.c
gcc -c -I. -I.. -I../mpn -g -O get_d.c
gcc -c -I. -I.. -I../mpn -g -O get_prc.c
gcc -c -I. -I.. -I../mpn -g -O get_str.c
gcc -c -I. -I.. -I../mpn -g -O init.c
gcc -c -I. -I.. -I../mpn -g -O init2.c
gcc -c -I. -I.. -I../mpn -g -O inp_str.c
gcc -c -I. -I.. -I../mpn -g -O iset.c
gcc -c -I. -I.. -I../mpn -g -O iset_d.c
gcc -c -I. -I.. -I../mpn -g -O iset_si.c
gcc -c -I. -I.. -I../mpn -g -O iset_str.c
gcc -c -I. -I.. -I../mpn -g -O iset_ui.c
gcc -c -I. -I.. -I../mpn -g -O mul.c
gcc -c -I. -I.. -I../mpn -g -O mul_2exp.c
gcc -c -I. -I.. -I../mpn -g -O mul_ui.c
gcc -c -I. -I.. -I../mpn -g -O neg.c
gcc -c -I. -I.. -I../mpn -g -O out_str.c
gcc -c -I. -I.. -I../mpn -g -O random2.c
gcc -c -I. -I.. -I../mpn -g -O reldiff.c
gcc -c -I. -I.. -I../mpn -g -O set.c
gcc -c -I. -I.. -I../mpn -g -O set_d.c
gcc -c -I. -I.. -I../mpn -g -O set_dfl_prc.c
gcc -c -I. -I.. -I../mpn -g -O set_prc.c
gcc -c -I. -I.. -I../mpn -g -O set_prc_raw.c
gcc -c -I. -I.. -I../mpn -g -O set_q.c
gcc -c -I. -I.. -I../mpn -g -O set_si.c
gcc -c -I. -I.. -I../mpn -g -O set_str.c
gcc -c -I. -I.. -I../mpn -g -O set_ui.c
gcc -c -I. -I.. -I../mpn -g -O set_z.c
gcc -c -I. -I.. -I../mpn -g -O size.c
gcc -c -I. -I.. -I../mpn -g -O sqrt.c
gcc -c -I. -I.. -I../mpn -g -O sqrt_ui.c
gcc -c -I. -I.. -I../mpn -g -O sub.c
gcc -c -I. -I.. -I../mpn -g -O sub_ui.c
gcc -c -I. -I.. -I../mpn -g -O ui_div.c
gcc -c -I. -I.. -I../mpn -g -O ui_sub.c
del libmpf.a
ar cr libmpf.a *.o
cd ..
cd mpq
gcc -c -I. -I.. -I../mpn -g -O add.c
gcc -c -I. -I.. -I../mpn -g -O canonicalize.c
gcc -c -I. -I.. -I../mpn -g -O clear.c
gcc -c -I. -I.. -I../mpn -g -O cmp.c
gcc -c -I. -I.. -I../mpn -g -O cmp_ui.c
gcc -c -I. -I.. -I../mpn -g -O div.c
gcc -c -I. -I.. -I../mpn -g -O equal.c
gcc -c -I. -I.. -I../mpn -g -O get_d.c
gcc -c -I. -I.. -I../mpn -g -O get_den.c
gcc -c -I. -I.. -I../mpn -g -O get_num.c
gcc -c -I. -I.. -I../mpn -g -O init.c
gcc -c -I. -I.. -I../mpn -g -O inv.c
gcc -c -I. -I.. -I../mpn -g -O mul.c
gcc -c -I. -I.. -I../mpn -g -O neg.c
gcc -c -I. -I.. -I../mpn -g -O set.c
gcc -c -I. -I.. -I../mpn -g -O set_den.c
gcc -c -I. -I.. -I../mpn -g -O set_num.c
gcc -c -I. -I.. -I../mpn -g -O set_si.c
gcc -c -I. -I.. -I../mpn -g -O set_ui.c
gcc -c -I. -I.. -I../mpn -g -O set_z.c
gcc -c -I. -I.. -I../mpn -g -O sub.c
del libmpq.a
ar cr libmpq.a *.o
cd ..
gcc -c -I. -Impn -I.. -g -O extract-double.c
gcc -c -I. -Impn -I.. -g -O insert-double.c
gcc -c -I. -Impn -I.. -g -O memory.c
gcc -c -I. -Impn -I.. -g -O mp_clz_tab.c
gcc -c -I. -Impn -I.. -g -O mp_set_fns.c
gcc -c -I. -Impn -I.. -g -O stack-alloc.c
gcc -c -I. -Impn -I.. -g -O version.c
deltree/y tmpdir
md tmpdir
md tmpdir\mpn
cd tmpdir\mpn
ar x ../../mpn/libmpn.a
cd ..\..
md tmpdir\mpz
cd tmpdir\mpz
ar x ../../mpz/libmpz.a
cd ..\..
md tmpdir\mpq
cd tmpdir\mpq
ar x ../../mpq/libmpq.a
cd ..\..
md tmpdir\mpf
cd tmpdir\mpf
ar x ../../mpf/libmpf.a
cd ..\..
copy memory.o tmpdir
copy mp_set_fns.o tmpdir
copy mp_clz_tab.o tmpdir
copy version.o tmpdir
copy stack-alloc.o tmpdir
cd tmpdir
ar rc libgmp.a *.o */*.o
ranlib libgmp.a
cd ..
move/y tmpdir\libgmp.a libgmp.a
deltree/y tmpdir

View File

@ -1,22 +1,23 @@
/* Memory allocation routines.
Copyright (C) 1991 Free Software Foundation, Inc.
Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 General Public License for more details.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
@ -27,7 +28,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#define static
#endif
#ifdef __STDC__
#if __STDC__
void * (*_mp_allocate_func) (size_t) = _mp_default_allocate;
void * (*_mp_reallocate_func) (void *, size_t, size_t)
= _mp_default_reallocate;
@ -42,7 +43,7 @@ void (*_mp_free_func) () = _mp_default_free;
an error message is written to stderr and the program aborts. */
void *
#ifdef __STDC__
#if __STDC__
_mp_default_allocate (size_t size)
#else
_mp_default_allocate (size)
@ -54,7 +55,7 @@ _mp_default_allocate (size)
ret = malloc (size);
if (ret == 0)
{
perror ("cannot allocate in libmp");
perror ("cannot allocate in gmp");
abort ();
}
@ -62,7 +63,7 @@ _mp_default_allocate (size)
}
void *
#ifdef __STDC__
#if __STDC__
_mp_default_reallocate (void *oldptr, size_t old_size, size_t new_size)
#else
_mp_default_reallocate (oldptr, old_size, new_size)
@ -76,7 +77,7 @@ _mp_default_reallocate (oldptr, old_size, new_size)
ret = realloc (oldptr, new_size);
if (ret == 0)
{
perror ("cannot allocate in libmp");
perror ("cannot allocate in gmp");
abort ();
}
@ -84,7 +85,7 @@ _mp_default_reallocate (oldptr, old_size, new_size)
}
void
#ifdef __STDC__
#if __STDC__
_mp_default_free (void *blk_ptr, size_t blk_size)
#else
_mp_default_free (blk_ptr, blk_size)

32
gnu/lib/libgmp/mkinstalldirs Executable file
View File

@ -0,0 +1,32 @@
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Public domain
errstatus=0
for file
do
set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
shift
pathcomp=
for d in ${1+"$@"} ; do
pathcomp="$pathcomp$d"
case "$pathcomp" in
-* ) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp" 1>&2
mkdir "$pathcomp" || errstatus=$?
fi
pathcomp="$pathcomp/"
done
done
exit $errstatus
# mkinstalldirs ends here

15
gnu/lib/libgmp/move-if-change Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
if
test -r $2
then
if
cmp $1 $2 > /dev/null
then
echo $2 is unchanged
rm -f $1
else
mv -f $1 $2
fi
else
mv -f $1 $2
fi

View File

@ -1,60 +1,97 @@
/* mp.h -- Definitions for Berkeley compatible multiple precision functions.
Copyright (C) 1991, 1993 Free Software Foundation, Inc.
Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 General Public License for more details.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#ifndef __MP_H__
#define __MP_H__
#define __GNU_MP__
#ifndef __GMP_H__
#ifndef __GNU_MP__
#define __GNU_MP__ 2
#define __need_size_t
#include <stddef.h>
#undef __need_size_t
#if defined (__STDC__) || defined (__cplusplus)
#define __gmp_const const
#else
#define __gmp_const
#endif
#ifndef MP_INT
#if defined (__GNUC__)
#define __gmp_inline __inline__
#else
#define __gmp_inline
#endif
#ifndef _EXTERN_INLINE
#ifdef __GNUC__
#define _EXTERN_INLINE extern __inline__
#else
#define _EXTERN_INLINE static
#endif
#endif
#ifdef _SHORT_LIMB
typedef unsigned int mp_limb_t;
typedef int mp_limb_signed_t;
#else
#ifdef _LONG_LONG_LIMB
typedef unsigned long long int mp_limb_t;
typedef long long int mp_limb_signed_t;
#else
typedef unsigned long int mp_limb_t;
typedef long int mp_limb_signed_t;
#endif
#endif
typedef mp_limb_t * mp_ptr;
typedef __gmp_const mp_limb_t * mp_srcptr;
typedef int mp_size_t;
typedef long int mp_exp_t;
#ifndef __MP_SMALL__
typedef struct
{
long int alloc; /* Number of *limbs* allocated and pointed
mp_size_t _mp_alloc; /* Number of *limbs* allocated and pointed
to by the D field. */
long int size; /* abs(SIZE) is the number of limbs
mp_size_t _mp_size; /* abs(SIZE) is the number of limbs
the last field points to. If SIZE
is negative this is a negative
number. */
unsigned long int *d; /* Pointer to the limbs. */
} __MP_INT;
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpz_struct;
#else
typedef struct
{
short int alloc; /* Number of *limbs* allocated and pointed
short int _mp_alloc; /* Number of *limbs* allocated and pointed
to by the D field. */
short int size; /* abs(SIZE) is the number of limbs
short int _mp_size; /* abs(SIZE) is the number of limbs
the last field points to. If SIZE
is negative this is a negative
number. */
unsigned long int *d; /* Pointer to the limbs. */
} __MP_INT;
#endif
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpz_struct;
#endif
#endif /* __GNU_MP__ */
#define MINT __MP_INT
/* User-visible types. */
typedef __mpz_struct MINT;
#ifdef __STDC__
void mp_set_memory_functions (void *(*) (size_t),
@ -100,4 +137,5 @@ char *mtox ();
void mfree ();
#endif
#define __MP_H__
#endif /* __MP_H__ */

4
gnu/lib/libgmp/mp_bpl.c Normal file
View File

@ -0,0 +1,4 @@
#include "gmp.h"
#include "gmp-impl.h"
const int mp_bits_per_limb = BITS_PER_MP_LIMB;

View File

@ -1,29 +1,33 @@
/* __clz_tab -- support for longlong.h
Copyright (C) 1991 Free Software Foundation, Inc.
Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 General Public License for more details.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#if 0
#include "gmp.h"
#include "gmp-impl.h"
#endif
/* BOTCH: This ought to be made machine-independent. */
const unsigned char __clz_tab[] =
#if 0
const
#endif
unsigned char __clz_tab[] =
{
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,

View File

@ -1,29 +1,30 @@
/* mp_set_memory_functions -- Set the allocate, reallocate, and free functions
for use by the mp package.
Copyright (C) 1991 Free Software Foundation, Inc.
Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 General Public License for more details.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
#if __STDC__
mp_set_memory_functions (void *(*alloc_func) (size_t),
void *(*realloc_func) (void *, size_t, size_t),
void (*free_func) (void *, size_t))

View File

@ -0,0 +1,84 @@
# Makefile for GNU MP/mpbsd functions
# Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc.
# This file is part of the GNU MP Library.
# The GNU MP Library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
# The GNU MP 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 Library General Public
# License for more details.
# You should have received a copy of the GNU Library General Public License
# along with the GNU MP Library; see the file COPYING.LIB. If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.
srcdir = .
CC = gcc
# If you cross compile on a machine with the same sizes of the integral
# types ("int", "long int", "short int", and "char") define this as the
# local compiler. Otherwise, you need to look for the uses of LOCAL_CC below,
# and handle those cases manually.
LOCAL_CC = $(CC)
CFLAGS = -g -O
AR = ar
SHELL = /bin/sh
#### host and target specific makefile fragments come in here.
###
MPBSD_LINKS = add.c cmp.c gcd.c mul.c pow_ui.c powm.c sqrtrem.c sub.c
MPBSD_SRCS = itom.c mdiv.c mfree.c min.c mout.c move.c mtox.c sdiv.c xtom.c \
realloc.c $(MPBSD_LINKS)
MPBSD_OBJS = itom.o mdiv.o mfree.o min.o mout.o move.o mtox.o sdiv.o xtom.o \
realloc.o add.o cmp.o gcd.o mul.o pow_ui.o powm.o sqrtrem.o sub.o
INCLUDES = -I. -I.. -I$(srcdir)/../mpz -I../mpn -I$(srcdir)/..
libmpbsd.a: Makefile.in $(MPBSD_OBJS)
rm -f $@
$(AR) cr $@ $(MPBSD_OBJS)
.c.o:
$(CC) -c $(INCLUDES) -DBERKELEY_MP $(CFLAGS) $(XCFLAGS) $<
check:
true
clean mostlyclean:
rm -f *.o libmpbsd.a
distclean maintainer-clean: clean
rm -f Makefile config.status $(MPBSD_LINKS)
Makefile: $(srcdir)/Makefile.in
$(SHELL) ./config.status
H = $(srcdir)/../gmp.h $(srcdir)/../gmp-impl.h ../mpn/gmp-mparam.h
L = $(srcdir)/../longlong.h
itom.o: $(srcdir)/itom.c ../mp.h $(H)
mdiv.o: $(srcdir)/mdiv.c ../mp.h $(H) $(L) $(srcdir)/../mpz/dmincl.c
mfree.o: $(srcdir)/mfree.c ../mp.h $(H)
min.o: $(srcdir)/min.c ../mp.h $(H)
mout.o: $(srcdir)/mout.c ../mp.h $(H)
move.o: $(srcdir)/move.c ../mp.h $(H)
mtox.o: $(srcdir)/mtox.c ../mp.h $(H)
sdiv.o: $(srcdir)/sdiv.c ../mp.h $(H) $(L)
xtom.o: $(srcdir)/xtom.c ../mp.h $(H)
add.o: $(srcdir)/../mpz/add.c $(H)
cmp.o: $(srcdir)/../mpz/cmp.c $(H)
gcd.o: $(srcdir)/../mpz/gcd.c $(H) $(L)
mul.o: $(srcdir)/../mpz/mul.c $(H)
pow_ui.o: $(srcdir)/../mpz/pow_ui.c $(H) $(L)
powm.o: $(srcdir)/../mpz/powm.c $(H) $(L)
realloc.o: $(srcdir)/realloc.c $(H)
sqrtrem.o: $(srcdir)/../mpz/sqrtrem.c $(H)
sub.o: $(srcdir)/../mpz/sub.c $(H)

View File

@ -0,0 +1,20 @@
# This file is a shell script fragment that supplies the information
# necessary for a configure script to process the program in
# this directory. For more information, look at ../configure.
configdirs=
srctrigger=itom.c
srcname="GNU Multi-Precision library/mpbsd"
# per-host:
# per-target:
mpzfiles="add.c cmp.c gcd.c mul.c pow_ui.c powm.c sqrtrem.c sub.c"
for fn in $mpzfiles
do
rm -f $fn
files="$files ../mpz/$fn"
links="$links $fn"
done

View File

@ -0,0 +1,54 @@
/* itom -- BSD compatible allocate and initiate a MINT.
Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
MINT *
#if __STDC__
itom (signed short int n)
#else
itom (n)
short int n;
#endif
{
MINT *x;
mp_ptr xp;
x = (MINT *) (*_mp_allocate_func) (sizeof (MINT));
x->_mp_alloc = 1;
x->_mp_d = xp = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB);
if (n > 0)
{
x->_mp_size = 1;
xp[0] = n;
}
else if (n < 0)
{
x->_mp_size = -1;
xp[0] = -n;
}
else
x->_mp_size = 0;
return x;
}

View File

@ -0,0 +1,39 @@
/* mdiv -- BSD compatible divide producing both remainder and quotient.
Copyright (C) 1991, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
void
#if __STDC__
mdiv (const MINT *num, const MINT *den, MINT *quot, MINT *rem)
#else
mdiv (num, den, quot, rem)
const MINT *num;
const MINT *den;
MINT *quot;
MINT *rem;
#endif
#define COMPUTE_QUOTIENT
#include "dmincl.c"

View File

@ -0,0 +1,36 @@
/* mfree -- BSD compatible mfree.
Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mfree (MINT *m)
#else
mfree (m)
MINT *m;
#endif
{
(*_mp_free_func) (m->_mp_d, m->_mp_alloc * BYTES_PER_MP_LIMB);
(*_mp_free_func) (m, sizeof (MINT));
}

View File

@ -0,0 +1,89 @@
/* min(MINT) -- Do decimal input from standard input and store result in
MINT.
Copyright (C) 1991, 1994 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
#include <ctype.h>
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
min (MINT *dest)
#else
min (dest)
MINT *dest;
#endif
{
char *str;
size_t alloc_size, str_size;
int c;
int negative;
mp_size_t dest_size;
alloc_size = 100;
str = (char *) (*_mp_allocate_func) (alloc_size);
str_size = 0;
/* Skip whitespace. */
do
c = getc (stdin);
while (isspace (c));
negative = 0;
if (c == '-')
{
negative = 1;
c = getc (stdin);
}
if (digit_value_in_base (c, 10) < 0)
return; /* error if no digits */
for (;;)
{
int dig;
if (str_size >= alloc_size)
{
size_t old_alloc_size = alloc_size;
alloc_size = alloc_size * 3 / 2;
str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size);
}
dig = digit_value_in_base (c, 10);
if (dig < 0)
break;
str[str_size++] = dig;
c = getc (stdin);
}
ungetc (c, stdin);
dest_size = str_size / __mp_bases[10].chars_per_limb + 1;
if (dest->_mp_alloc < dest_size)
_mp_realloc (dest, dest_size);
dest_size = mpn_set_str (dest->_mp_d, (unsigned char *) str, str_size, 10);
dest->_mp_size = negative ? -dest_size : dest_size;
(*_mp_free_func) (str, alloc_size);
return;
}

View File

@ -0,0 +1,96 @@
/* mout(MINT) -- Do decimal output of MINT to standard output.
Copyright (C) 1991, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mout (const MINT *x)
#else
mout (x)
const MINT *x;
#endif
{
mp_ptr xp;
mp_size_t x_size = x->_mp_size;
unsigned char *str;
size_t str_size;
char *num_to_text;
int i;
TMP_DECL (marker);
if (x_size == 0)
{
fputc ('0', stdout);
return;
}
if (x_size < 0)
{
fputc ('-', stdout);
x_size = -x_size;
}
TMP_MARK (marker);
str_size = ((size_t) (x_size * BITS_PER_MP_LIMB
* __mp_bases[10].chars_per_bit_exactly)) + 3;
str = (unsigned char *) TMP_ALLOC (str_size);
/* Move the number to convert into temporary space, since mpn_get_str
clobbers its argument + needs one extra high limb.... */
xp = (mp_ptr) TMP_ALLOC ((x_size + 1) * BYTES_PER_MP_LIMB);
MPN_COPY (xp, x->_mp_d, x_size);
str_size = mpn_get_str (str, 10, xp, x_size);
/* mpn_get_str might make some leading zeros. Skip them. */
while (*str == 0)
{
str_size--;
str++;
}
/* Translate to printable chars. */
for (i = 0; i < str_size; i++)
str[i] = "0123456789"[str[i]];
str[str_size] = 0;
str_size = strlen (str);
if (str_size % 10 != 0)
{
fwrite (str, 1, str_size % 10, stdout);
str += str_size % 10;
str_size -= str_size % 10;
if (str_size != 0)
fputc (' ', stdout);
}
for (i = 0; i < str_size; i += 10)
{
fwrite (str, 1, 10, stdout);
str += 10;
if (i + 10 < str_size)
fputc (' ', stdout);
}
fputc ('\n', stdout);
TMP_FREE (marker);
}

View File

@ -0,0 +1,46 @@
/* move -- BSD compatible assignment.
Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
move (const MINT *u, MINT *w)
#else
move (u, w)
const MINT *u;
MINT *w;
#endif
{
mp_size_t usize;
mp_size_t abs_usize;
usize = u->_mp_size;
abs_usize = ABS (usize);
if (w->_mp_alloc < abs_usize)
_mp_realloc (w, abs_usize);
w->_mp_size = usize;
MPN_COPY (w->_mp_d, u->_mp_d, abs_usize);
}

View File

@ -0,0 +1,81 @@
/* mtox -- Convert OPERAND to hexadecimal and return a malloc'ed string
with the result of the conversion.
Copyright (C) 1991, 1994 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
char *
#if __STDC__
mtox (const MINT *x)
#else
mtox (x)
const MINT *x;
#endif
{
mp_ptr xp;
mp_size_t xsize = x->_mp_size;
mp_size_t xsign;
unsigned char *str, *s;
size_t str_size, i;
int zeros;
char *num_to_text;
TMP_DECL (marker);
if (xsize == 0)
{
str = (unsigned char *) (*_mp_allocate_func) (2);
str[0] = '0';
str[1] = 0;
return str;
}
xsign = xsize;
if (xsize < 0)
xsize = -xsize;
TMP_MARK (marker);
str_size = ((size_t) (xsize * BITS_PER_MP_LIMB
* __mp_bases[16].chars_per_bit_exactly)) + 3;
str = (unsigned char *) (*_mp_allocate_func) (str_size);
s = str;
if (xsign < 0)
*s++ = '-';
/* Move the number to convert into temporary space, since mpn_get_str
clobbers its argument + needs one extra high limb.... */
xp = (mp_ptr) TMP_ALLOC ((xsize + 1) * BYTES_PER_MP_LIMB);
MPN_COPY (xp, x->_mp_d, xsize);
str_size = mpn_get_str (s, 16, xp, xsize);
/* mpn_get_str might make some leading zeros. Skip them. */
for (zeros = 0; s[zeros] == 0; zeros++)
str_size--;
/* Translate to printable chars and move string down. */
for (i = 0; i < str_size; i++)
s[i] = "0123456789abcdef"[s[zeros + i]];
s[str_size] = 0;
return str;
}

View File

@ -0,0 +1,44 @@
/* _mp_realloc -- make the MINT* have NEW_SIZE digits allocated.
Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void *
#if __STDC__
_mp_realloc (MINT *m, mp_size_t new_size)
#else
_mp_realloc (m, new_size)
MINT *m;
mp_size_t new_size;
#endif
{
/* Never allocate zero space. */
if (new_size == 0)
new_size = 1;
m->_mp_d = (mp_ptr) (*_mp_reallocate_func) (m->_mp_d,
m->_mp_alloc * BYTES_PER_MP_LIMB,
new_size * BYTES_PER_MP_LIMB);
m->_mp_alloc = new_size;
return (void *) m->_mp_d;
}

View File

@ -0,0 +1,77 @@
/* sdiv -- Divide a MINT by a short integer. Produce a MINT quotient
and a short remainder.
Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
void
#if __STDC__
sdiv (const MINT *dividend, signed short int divisor_short, MINT *quot, short *rem_ptr)
#else
sdiv (dividend, divisor_short, quot, rem_ptr)
const MINT *dividend;
short int divisor_short;
MINT *quot;
short *rem_ptr;
#endif
{
mp_size_t sign_dividend;
signed long int sign_divisor;
mp_size_t dividend_size, quot_size;
mp_ptr dividend_ptr, quot_ptr;
mp_limb_t divisor_limb;
mp_limb_t remainder_limb;
sign_dividend = dividend->_mp_size;
dividend_size = ABS (dividend->_mp_size);
if (dividend_size == 0)
{
quot->_mp_size = 0;
*rem_ptr = 0;
return;
}
sign_divisor = divisor_short;
divisor_limb = ABS (divisor_short);
/* No need for temporary allocation and copying even if QUOT == DIVIDEND
as the divisor is just one limb, and thus no intermediate remainders
need to be stored. */
if (quot->_mp_alloc < dividend_size)
_mp_realloc (quot, dividend_size);
quot_ptr = quot->_mp_d;
dividend_ptr = dividend->_mp_d;
remainder_limb = mpn_divmod_1 (quot_ptr,
dividend_ptr, dividend_size, divisor_limb);
*rem_ptr = sign_dividend >= 0 ? remainder_limb : -remainder_limb;
/* The quotient is DIVIDEND_SIZE limbs, but the most significant
might be zero. Set QUOT_SIZE properly. */
quot_size = dividend_size - (quot_ptr[dividend_size - 1] == 0);
quot->_mp_size = (sign_divisor ^ sign_dividend) >= 0 ? quot_size : -quot_size;
}

110
gnu/lib/libgmp/mpbsd/xtom.c Normal file
View File

@ -0,0 +1,110 @@
/* xtom -- convert a hexadecimal string to a MINT, and return a pointer to
the MINT.
Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
static int
digit_value_in_base (c, base)
int c;
int base;
{
int digit;
if (isdigit (c))
digit = c - '0';
else if (islower (c))
digit = c - 'a' + 10;
else if (isupper (c))
digit = c - 'A' + 10;
else
return -1;
if (digit < base)
return digit;
return -1;
}
MINT *
#if __STDC__
xtom (const char *str)
#else
xtom (str)
const char *str;
#endif
{
size_t str_size;
char *s, *begs;
size_t i;
mp_size_t xsize;
int c;
int negative;
MINT *x = (MINT *) (*_mp_allocate_func) (sizeof (MINT));
TMP_DECL (marker);
/* Skip whitespace. */
do
c = *str++;
while (isspace (c));
negative = 0;
if (c == '-')
{
negative = 1;
c = *str++;
}
if (digit_value_in_base (c, 16) < 0)
return 0; /* error if no digits */
TMP_MARK (marker);
str_size = strlen (str - 1);
s = begs = (char *) TMP_ALLOC (str_size + 1);
for (i = 0; i < str_size; i++)
{
if (!isspace (c))
{
int dig = digit_value_in_base (c, 16);
if (dig < 0)
{
TMP_FREE (marker);
return 0;
}
*s++ = dig;
}
c = *str++;
}
str_size = s - begs;
xsize = str_size / __mp_bases[16].chars_per_limb + 1;
x->_mp_alloc = xsize;
x->_mp_d = (mp_ptr) (*_mp_allocate_func) (xsize * BYTES_PER_MP_LIMB);
xsize = mpn_set_str (x->_mp_d, (unsigned char *) begs, str_size, 16);
x->_mp_size = negative ? -xsize : xsize;
TMP_FREE (marker);
return x;
}

View File

@ -0,0 +1,115 @@
# Makefile for GNU MP/mpf functions
# Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc.
# This file is part of the GNU MP Library.
# The GNU MP Library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
# The GNU MP 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 Library General Public
# License for more details.
# You should have received a copy of the GNU Library General Public License
# along with the GNU MP Library; see the file COPYING.LIB. If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.
srcdir = .
CC = gcc
CFLAGS = -g -O
AR = ar
AR_FLAGS = rc
SHELL = /bin/sh
#### host and target specific makefile fragments come in here.
###
MPF_SRCS = init.c init2.c set.c set_ui.c set_si.c set_str.c set_d.c set_z.c \
iset.c iset_ui.c iset_si.c iset_str.c iset_d.c clear.c get_str.c \
dump.c size.c eq.c reldiff.c sqrt.c random2.c inp_str.c out_str.c \
add.c add_ui.c sub.c sub_ui.c ui_sub.c mul.c mul_ui.c div.c div_ui.c \
cmp.c cmp_ui.c cmp_si.c mul_2exp.c div_2exp.c abs.c neg.c set_q.c get_d.c \
set_dfl_prec.c set_prc.c set_prc_raw.c get_prc.c ui_div.c sqrt_ui.c
MPF_OBJS = init.o init2.o set.o set_ui.o set_si.o set_str.o set_d.o set_z.o \
iset.o iset_ui.o iset_si.o iset_str.o iset_d.o clear.o get_str.o \
dump.o size.o eq.o reldiff.o sqrt.o random2.o inp_str.o out_str.o \
add.o add_ui.o sub.o sub_ui.o ui_sub.o mul.o mul_ui.o div.o div_ui.o \
cmp.o cmp_ui.o cmp_si.o mul_2exp.o div_2exp.o abs.o neg.o set_q.o get_d.o \
set_dfl_prec.o set_prc.o set_prc_raw.o get_prc.o ui_div.o sqrt_ui.o
LATER_OBJS = inp_raw.o out_raw.o random.o pow_ui.o fac_ui.o
INCLUDES = -I. -I.. -I../mpn -I$(srcdir)/..
libmpf.a: Makefile $(MPF_OBJS)
rm -f $@
$(AR) $(AR_FLAGS) $@ $(MPF_OBJS)
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $(XCFLAGS) $<
clean mostlyclean:
rm -f *.o libmpf.a
-cd tests; $(MAKE) $@
distclean maintainer-clean: clean
rm -f Makefile config.status
-cd tests; $(MAKE) $@
Makefile: $(srcdir)/Makefile.in
$(SHELL) ./config.status
H = $(srcdir)/../gmp.h $(srcdir)/../gmp-impl.h ../mpn/gmp-mparam.h
abs.o: $(srcdir)/abs.c $(H)
add.o: $(srcdir)/add.c $(H)
add_ui.o: $(srcdir)/add_ui.c $(H)
clear.o: $(srcdir)/clear.c $(H)
cmp.o: $(srcdir)/cmp.c $(H)
cmp_si.o: $(srcdir)/cmp_si.c $(H)
cmp_ui.o: $(srcdir)/cmp_ui.c $(H)
eq.o: $(srcdir)/eq.c $(H)
div.o: $(srcdir)/div.c $(H) $(srcdir)/../longlong.h
div_2exp.o: $(srcdir)/div_2exp.c $(H)
div_ui.o: $(srcdir)/div_ui.c $(H) $(srcdir)/../longlong.h
dump.o: $(srcdir)/dump.c $(H)
get_d.o: $(srcdir)/get_d.c $(H)
get_prc.o: $(srcdir)/get_prc.c $(H)
get_str.o: $(srcdir)/get_str.c $(H) $(srcdir)/../longlong.h
init.o: $(srcdir)/init.c $(H)
init2.o: $(srcdir)/init2.c $(H)
inp_str.o: $(srcdir)/inp_str.c $(H)
iset.o: $(srcdir)/iset.c $(H)
iset_d.o: $(srcdir)/iset_d.c $(H)
iset_si.o: $(srcdir)/iset_si.c $(H)
iset_str.o: $(srcdir)/iset_str.c $(H)
iset_ui.o: $(srcdir)/iset_ui.c $(H)
mul.o: $(srcdir)/mul.c $(H)
mul_2exp.o: $(srcdir)/mul_2exp.c $(H)
mul_ui.o: $(srcdir)/mul_ui.c $(H)
neg.o: $(srcdir)/neg.c $(H)
out_str.o: $(srcdir)/out_str.c $(H)
random2.o: $(srcdir)/random2.c $(H)
reldiff.o: $(srcdir)/reldiff.c $(H)
set.o: $(srcdir)/set.c $(H)
set_d.o: $(srcdir)/set_d.c $(H)
set_dfl_prec.o: $(srcdir)/set_dfl_prec.c $(H)
set_prc.o: $(srcdir)/set_prc.c $(H)
set_prc_raw.o: $(srcdir)/set_prc_raw.c $(H)
set_q.o: $(srcdir)/set_q.c $(H)
set_si.o: $(srcdir)/set_si.c $(H)
set_str.o: $(srcdir)/set_str.c $(H) $(srcdir)/../longlong.h
set_ui.o: $(srcdir)/set_ui.c $(H)
set_z.o: $(srcdir)/set_z.c $(H)
size.o: $(srcdir)/size.c $(H)
sqrt.o: $(srcdir)/sqrt.c $(H)
sqrt_ui.o: $(srcdir)/sqrt_ui.c $(H)
sub.o: $(srcdir)/sub.c $(H)
sub_ui.o: $(srcdir)/sub_ui.c $(H)
ui_div.o: $(srcdir)/ui_div.c $(H) $(srcdir)/../longlong.h
ui_sub.o: $(srcdir)/ui_sub.c $(H)

56
gnu/lib/libgmp/mpf/abs.c Normal file
View File

@ -0,0 +1,56 @@
/* mpf_abs -- Compute the absolute value of a float.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_abs (mpf_ptr r, mpf_srcptr u)
#else
mpf_abs (r, u)
mpf_ptr r;
mpf_srcptr u;
#endif
{
mp_size_t size;
size = ABS (u->_mp_size);
if (r != u)
{
mp_size_t prec;
mp_ptr rp, up;
prec = r->_mp_prec + 1; /* lie not to lose precision in assignment */
rp = r->_mp_d;
up = u->_mp_d;
if (size > prec)
{
up += size - prec;
size = prec;
}
MPN_COPY (rp, up, size);
r->_mp_exp = u->_mp_exp;
}
r->_mp_size = size;
}

180
gnu/lib/libgmp/mpf/add.c Normal file
View File

@ -0,0 +1,180 @@
/* mpf_add -- Add two floats.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_add (mpf_ptr r, mpf_srcptr u, mpf_srcptr v)
#else
mpf_add (r, u, v)
mpf_ptr r;
mpf_srcptr u;
mpf_srcptr v;
#endif
{
mp_srcptr up, vp;
mp_ptr rp, tp;
mp_size_t usize, vsize, rsize;
mp_size_t prec;
mp_exp_t uexp;
mp_size_t ediff;
mp_limb_t cy;
int negate;
TMP_DECL (marker);
usize = u->_mp_size;
vsize = v->_mp_size;
/* Handle special cases that don't work in generic code below. */
if (usize == 0)
{
mpf_set (r, v);
return;
}
if (vsize == 0)
{
mpf_set (r, u);
return;
}
/* If signs of U and V are different, perform subtraction. */
if ((usize ^ vsize) < 0)
{
__mpf_struct v_negated;
v_negated._mp_size = -vsize;
v_negated._mp_exp = v->_mp_exp;
v_negated._mp_d = v->_mp_d;
mpf_sub (r, u, &v_negated);
return;
}
TMP_MARK (marker);
/* Signs are now known to be the same. */
negate = usize < 0;
/* Make U be the operand with the largest exponent. */
if (u->_mp_exp < v->_mp_exp)
{
mpf_srcptr t;
t = u; u = v; v = t;
usize = u->_mp_size;
vsize = v->_mp_size;
}
usize = ABS (usize);
vsize = ABS (vsize);
up = u->_mp_d;
vp = v->_mp_d;
rp = r->_mp_d;
prec = r->_mp_prec;
uexp = u->_mp_exp;
ediff = u->_mp_exp - v->_mp_exp;
/* If U extends beyond PREC, ignore the part that does. */
if (usize > prec)
{
up += usize - prec;
usize = prec;
}
/* If V extends beyond PREC, ignore the part that does.
Note that this may make vsize negative. */
if (vsize + ediff > prec)
{
vp += vsize + ediff - prec;
vsize = prec - ediff;
}
#if 0
/* Locate the least significant non-zero limb in (the needed parts
of) U and V, to simplify the code below. */
while (up[0] == 0)
up++, usize--;
while (vp[0] == 0)
vp++, vsize--;
#endif
/* Allocate temp space for the result. Allocate
just vsize + ediff later??? */
tp = (mp_ptr) TMP_ALLOC (prec * BYTES_PER_MP_LIMB);
if (ediff >= prec)
{
/* V completely cancelled. */
if (tp != up)
MPN_COPY (rp, up, usize);
rsize = usize;
}
else
{
/* uuuu | uuuu | uuuu | uuuu | uuuu */
/* vvvvvvv | vv | vvvvv | v | vv */
if (usize > ediff)
{
/* U and V partially overlaps. */
if (vsize + ediff <= usize)
{
/* uuuu */
/* v */
mp_size_t size;
size = usize - ediff - vsize;
MPN_COPY (tp, up, size);
cy = mpn_add (tp + size, up + size, usize - size, vp, vsize);
rsize = usize;
}
else
{
/* uuuu */
/* vvvvv */
mp_size_t size;
size = vsize + ediff - usize;
MPN_COPY (tp, vp, size);
cy = mpn_add (tp + size, up, usize, vp + size, usize - ediff);
rsize = vsize + ediff;
}
}
else
{
/* uuuu */
/* vv */
mp_size_t size;
size = vsize + ediff - usize;
MPN_COPY (tp, vp, vsize);
MPN_ZERO (tp + vsize, ediff - usize);
MPN_COPY (tp + size, up, usize);
cy = 0;
rsize = size + usize;
}
MPN_COPY (rp, tp, rsize);
rp[rsize] = cy;
rsize += cy;
uexp += cy;
}
r->_mp_size = negate ? -rsize : rsize;
r->_mp_exp = uexp;
TMP_FREE (marker);
}

151
gnu/lib/libgmp/mpf/add_ui.c Normal file
View File

@ -0,0 +1,151 @@
/* mpf_add_ui -- Add a float and an unsigned integer.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_add_ui (mpf_ptr sum, mpf_srcptr u, unsigned long int v)
#else
mpf_add_ui (sum, u, v)
mpf_ptr sum;
mpf_srcptr u;
unsigned long int v;
#endif
{
mp_srcptr up = u->_mp_d;
mp_ptr sump = sum->_mp_d;
mp_size_t usize, sumsize;
mp_size_t prec = sum->_mp_prec;
mp_exp_t uexp = u->_mp_exp;
usize = u->_mp_size;
if (usize <= 0)
{
if (usize == 0)
{
mpf_set_ui (sum, v);
return;
}
else
{
__mpf_struct u_negated;
u_negated._mp_size = -usize;
u_negated._mp_exp = u->_mp_exp;
u_negated._mp_d = u->_mp_d;
mpf_sub_ui (sum, &u_negated, v);
sum->_mp_size = -(sum->_mp_size);
return;
}
}
if (v == 0)
{
sum_is_u:
if (u != sum)
{
sumsize = MIN (usize, prec + 1);
MPN_COPY (sum->_mp_d, up + usize - sumsize, sumsize);
sum->_mp_size = sumsize;
sum->_mp_exp = u->_mp_exp;
}
return;
}
if (uexp > 0)
{
/* U >= 1. */
if (uexp > prec)
{
/* U >> V, V is not part of final result. */
goto sum_is_u;
}
else
{
/* U's "limb point" is somewhere between the first limb
and the PREC:th limb.
Both U and V are part of the final result. */
if (uexp > usize)
{
/* uuuuuu0000. */
/* + v. */
/* We begin with moving U to the top of SUM, to handle
samevar(U,SUM). */
MPN_COPY_DECR (sump + uexp - usize, up, usize);
sump[0] = v;
MPN_ZERO (sump + 1, uexp - usize - 1);
#if 0 /* What is this??? */
if (sum == u)
MPN_COPY (sum->_mp_d, sump, uexp);
#endif
sum->_mp_size = uexp;
sum->_mp_exp = uexp;
}
else
{
/* uuuuuu.uuuu */
/* + v. */
mp_limb_t cy_limb;
if (usize > prec)
{
/* Ignore excess limbs in U. */
up += usize - prec;
usize -= usize - prec; /* Eq. usize = prec */
}
if (sump != up)
MPN_COPY (sump, up, usize - uexp);
cy_limb = mpn_add_1 (sump + usize - uexp, up + usize - uexp,
uexp, (mp_limb_t) v);
sump[usize] = cy_limb;
sum->_mp_size = usize + cy_limb;
sum->_mp_exp = uexp + cy_limb;
}
}
}
else
{
/* U < 1, so V > U for sure. */
/* v. */
/* .0000uuuu */
if ((-uexp) >= prec)
{
sump[0] = v;
sum->_mp_size = 1;
sum->_mp_exp = 1;
}
else
{
if (usize + (-uexp) + 1 > prec)
{
/* Ignore excess limbs in U. */
up += usize + (-uexp) + 1 - prec;
usize -= usize + (-uexp) + 1 - prec;
}
if (sump != up)
MPN_COPY (sump, up, usize);
MPN_ZERO (sump + usize, -uexp);
sump[usize + (-uexp)] = v;
sum->_mp_size = usize + (-uexp) + 1;
sum->_mp_exp = 1;
}
}
}

View File

@ -0,0 +1,35 @@
/* mpf_clear -- de-allocate the space occupied by the dynamic digit space of
an integer.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_clear (mpf_ptr m)
#else
mpf_clear (m)
mpf_ptr m;
#endif
{
(*_mp_free_func) (m->_mp_d, (m->_mp_prec + 1) * BYTES_PER_MP_LIMB);
}

114
gnu/lib/libgmp/mpf/cmp.c Normal file
View File

@ -0,0 +1,114 @@
/* mpf_cmp -- Compare two floats.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
int
#if __STDC__
mpf_cmp (mpf_srcptr u, mpf_srcptr v)
#else
mpf_cmp (u, v)
mpf_srcptr u;
mpf_srcptr v;
#endif
{
mp_srcptr up, vp;
mp_size_t usize, vsize;
mp_exp_t uexp, vexp;
int cmp;
int usign;
uexp = u->_mp_exp;
vexp = v->_mp_exp;
usize = u->_mp_size;
vsize = v->_mp_size;
/* 1. Are the signs different? */
if ((usize ^ vsize) >= 0)
{
/* U and V are both non-negative or both negative. */
if (usize == 0)
/* vsize >= 0 */
return -(vsize != 0);
if (vsize == 0)
/* usize >= 0 */
return usize != 0;
/* Fall out. */
}
else
{
/* Either U or V is negative, but not both. */
return usize >= 0 ? 1 : -1;
}
/* U and V have the same sign and are both non-zero. */
usign = usize >= 0 ? 1 : -1;
/* 2. Are the exponents different? */
if (uexp > vexp)
return usign;
if (uexp < vexp)
return -usign;
usize = ABS (usize);
vsize = ABS (vsize);
up = u->_mp_d;
vp = v->_mp_d;
#define STRICT_MPF_NORMALIZATION 0
#if ! STRICT_MPF_NORMALIZATION
/* Ignore zeroes at the low end of U and V. */
while (up[0] == 0)
{
up++;
usize--;
}
while (vp[0] == 0)
{
vp++;
vsize--;
}
#endif
if (usize > vsize)
{
cmp = mpn_cmp (up + usize - vsize, vp, vsize);
if (cmp == 0)
return usign;
}
else if (vsize > usize)
{
cmp = mpn_cmp (up, vp + vsize - usize, usize);
if (cmp == 0)
return -usign;
}
else
{
cmp = mpn_cmp (up, vp, usize);
if (cmp == 0)
return 0;
}
return cmp > 0 ? usign : -usign;
}

View File

@ -0,0 +1,98 @@
/* mpf_cmp_si -- Compare a float with a signed integer.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
int
#if __STDC__
mpf_cmp_si (mpf_srcptr u, long int vslimb)
#else
mpf_cmp_si (u, vslimb)
mpf_srcptr u;
long int vslimb;
#endif
{
mp_srcptr up;
mp_size_t usize;
mp_exp_t uexp;
int usign;
uexp = u->_mp_exp;
usize = u->_mp_size;
/* 1. Are the signs different? */
if ((usize < 0) == (vslimb < 0)) /* don't use xor, type size may differ */
{
/* U and V are both non-negative or both negative. */
if (usize == 0)
/* vslimb >= 0 */
return -(vslimb != 0);
if (vslimb == 0)
/* usize >= 0 */
return usize != 0;
/* Fall out. */
}
else
{
/* Either U or V is negative, but not both. */
return usize >= 0 ? 1 : -1;
}
/* U and V have the same sign and are both non-zero. */
usign = usize >= 0 ? 1 : -1;
/* 2. Are the exponents different (V's exponent == 1)? */
if (uexp > 1)
return usign;
if (uexp < 1)
return -usign;
usize = ABS (usize);
vslimb = ABS (vslimb);
up = u->_mp_d;
#define STRICT_MPF_NORMALIZATION 0
#if ! STRICT_MPF_NORMALIZATION
/* Ignore zeroes at the low end of U and V. */
while (*up == 0)
{
up++;
usize--;
}
#endif
/* 3. Now, if the number of limbs are different, we have a difference
since we have made sure the trailing limbs are not zero. */
if (usize > 1)
return usign;
/* 4. Compare the mantissas. */
if (*up > vslimb)
return usign;
else if (*up < vslimb)
return -usign;
/* Wow, we got zero even if we tried hard to avoid it. */
return 0;
}

View File

@ -0,0 +1,80 @@
/* mpf_cmp_ui -- Compare a float with an unsigned integer.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
int
#if __STDC__
mpf_cmp_ui (mpf_srcptr u, unsigned long int vlimb)
#else
mpf_cmp_ui (u, vlimb)
mpf_srcptr u;
unsigned long int vlimb;
#endif
{
mp_srcptr up;
mp_size_t usize;
mp_exp_t uexp;
uexp = u->_mp_exp;
usize = u->_mp_size;
/* 1. Is U negative? */
if (usize < 0)
return -1;
/* We rely on usize being non-negative in the code that follows. */
if (vlimb == 0)
return usize != 0;
/* 2. Are the exponents different (V's exponent == 1)? */
if (uexp > 1)
return 1;
if (uexp < 1)
return -1;
up = u->_mp_d;
#define STRICT_MPF_NORMALIZATION 0
#if ! STRICT_MPF_NORMALIZATION
/* Ignore zeroes at the low end of U. */
while (*up == 0)
{
up++;
usize--;
}
#endif
/* 3. Now, if the number of limbs are different, we have a difference
since we have made sure the trailing limbs are not zero. */
if (usize > 1)
return 1;
/* 4. Compare the mantissas. */
if (*up > vlimb)
return 1;
else if (*up < vlimb)
return -1;
/* Wow, we got zero even if we tried hard to avoid it. */
return 0;
}

View File

@ -0,0 +1,12 @@
# This file is a shell script fragment that supplies the information
# necessary for a configure script to process the program in
# this directory. For more information, look at ../configure.
configdirs=tests
srctrigger=add_ui.c
srcname="GNU Multi-Precision library/mpf"
# per-host:
# per-target:

144
gnu/lib/libgmp/mpf/div.c Normal file
View File

@ -0,0 +1,144 @@
/* mpf_div -- Divide two floats.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
void
#if __STDC__
mpf_div (mpf_ptr r, mpf_srcptr u, mpf_srcptr v)
#else
mpf_div (r, u, v)
mpf_ptr r;
mpf_srcptr u;
mpf_srcptr v;
#endif
{
mp_srcptr up, vp;
mp_ptr rp, tp, rtp;
mp_size_t usize, vsize;
mp_size_t rsize, tsize;
mp_size_t sign_quotient;
mp_size_t prec;
unsigned normalization_steps;
mp_limb_t q_limb;
mp_exp_t rexp;
TMP_DECL (marker);
usize = u->_mp_size;
vsize = v->_mp_size;
sign_quotient = usize ^ vsize;
usize = ABS (usize);
vsize = ABS (vsize);
prec = r->_mp_prec;
if (vsize == 0)
vsize = 1 / vsize; /* divide by zero as directed */
if (usize == 0)
{
r->_mp_size = 0;
r->_mp_exp = 0;
return;
}
TMP_MARK (marker);
rexp = u->_mp_exp - v->_mp_exp;
rp = r->_mp_d;
up = u->_mp_d;
vp = v->_mp_d;
if (vsize > prec)
{
vp += vsize - prec;
vsize = prec;
}
tsize = vsize + prec;
tp = (mp_ptr) TMP_ALLOC ((tsize + 1) * BYTES_PER_MP_LIMB);
if (usize > tsize)
{
up += usize - tsize;
usize = tsize;
rtp = tp;
}
else
{
MPN_ZERO (tp, tsize - usize);
rtp = tp + (tsize - usize);
}
count_leading_zeros (normalization_steps, vp[vsize - 1]);
/* Normalize the divisor and the dividend. */
if (normalization_steps != 0)
{
mp_ptr tmp;
mp_limb_t nlimb;
/* Shift up the divisor setting the most significant bit of
the most significant limb. Use temporary storage not to clobber
the original contents of the divisor. */
tmp = (mp_ptr) TMP_ALLOC (vsize * BYTES_PER_MP_LIMB);
mpn_lshift (tmp, vp, vsize, normalization_steps);
vp = tmp;
/* Shift up the dividend, possibly introducing a new most
significant word. Move the shifted dividend in the remainder
at the same time. */
nlimb = mpn_lshift (rtp, up, usize, normalization_steps);
if (nlimb != 0)
{
rtp[usize] = nlimb;
tsize++;
rexp++;
}
}
else
{
/* The divisor is already normalized, as required.
Copy it to temporary space if it overlaps with the quotient. */
if (vp - rp <= tsize - vsize)
{
mp_ptr tmp = (mp_ptr) TMP_ALLOC (vsize * BYTES_PER_MP_LIMB);
MPN_COPY (tmp, vp, vsize);
vp = (mp_srcptr) tmp;
}
/* Move the dividend to the remainder. */
MPN_COPY (rtp, up, usize);
}
q_limb = mpn_divmod (rp, tp, tsize, vp, vsize);
rsize = tsize - vsize;
if (q_limb)
{
rp[rsize] = q_limb;
rsize++;
rexp++;
}
r->_mp_size = sign_quotient >= 0 ? rsize : -rsize;
r->_mp_exp = rexp;
TMP_FREE (marker);
}

View File

@ -0,0 +1,79 @@
/* mpf_div_2exp -- Divide a float by 2^n.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_div_2exp (mpf_ptr r, mpf_srcptr u, unsigned long int exp)
#else
mpf_div_2exp (r, u, exp)
mpf_ptr r;
mpf_srcptr u;
unsigned long int exp;
#endif
{
mp_srcptr up;
mp_ptr rp = r->_mp_d;
mp_size_t usize;
mp_size_t abs_usize;
mp_size_t prec = r->_mp_prec;
mp_exp_t uexp = u->_mp_exp;
usize = u->_mp_size;
if (usize == 0)
{
r->_mp_size = 0;
r->_mp_exp = 0;
return;
}
abs_usize = ABS (usize);
up = u->_mp_d;
if (abs_usize > prec)
{
up += abs_usize - prec;
abs_usize = prec;
}
if (exp % BITS_PER_MP_LIMB == 0)
{
if (rp != up)
MPN_COPY (rp, up, abs_usize);
r->_mp_exp = uexp - exp / BITS_PER_MP_LIMB;
}
else
{
/* Use mpn_lshift since mpn_rshift operates upwards, and we therefore
would clobber part of U before using that part, when R == U. */
mp_limb_t cy_limb;
cy_limb = mpn_lshift (rp, up, abs_usize, -exp % BITS_PER_MP_LIMB);
rp[abs_usize] = cy_limb;
cy_limb = cy_limb != 0;
abs_usize += cy_limb;
r->_mp_exp = uexp - exp / BITS_PER_MP_LIMB - 1 + cy_limb;
}
r->_mp_size = usize >= 0 ? abs_usize : -abs_usize;
}

View File

@ -0,0 +1,91 @@
/* mpf_div_ui -- Divide a float with an unsigned integer.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
void
#if __STDC__
mpf_div_ui (mpf_ptr r, mpf_srcptr u, unsigned long int v)
#else
mpf_div_ui (r, u, v)
mpf_ptr r;
mpf_srcptr u;
unsigned long int v;
#endif
{
mp_srcptr up;
mp_ptr rp, tp, rtp;
mp_size_t usize;
mp_size_t rsize, tsize;
mp_size_t sign_quotient;
mp_size_t prec;
mp_limb_t q_limb;
mp_exp_t rexp;
TMP_DECL (marker);
usize = u->_mp_size;
sign_quotient = usize;
usize = ABS (usize);
prec = r->_mp_prec;
if (v == 0)
v = 1 / v; /* divide by zero as directed */
if (usize == 0)
{
r->_mp_size = 0;
r->_mp_exp = 0;
return;
}
TMP_MARK (marker);
rp = r->_mp_d;
up = u->_mp_d;
tsize = 1 + prec;
tp = (mp_ptr) TMP_ALLOC ((tsize + 1) * BYTES_PER_MP_LIMB);
if (usize > tsize)
{
up += usize - tsize;
usize = tsize;
rtp = tp;
}
else
{
MPN_ZERO (tp, tsize - usize);
rtp = tp + (tsize - usize);
}
/* Move the dividend to the remainder. */
MPN_COPY (rtp, up, usize);
mpn_divmod_1 (rp, tp, tsize, (mp_limb_t) v);
q_limb = rp[tsize - 1];
rsize = tsize - (q_limb == 0);
rexp = u->_mp_exp - (q_limb == 0);
r->_mp_size = sign_quotient >= 0 ? rsize : -rsize;
r->_mp_exp = rexp;
TMP_FREE (marker);
}

43
gnu/lib/libgmp/mpf/dump.c Normal file
View File

@ -0,0 +1,43 @@
/* mpf_dump -- Dump a float to stdout.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_dump (mpf_srcptr u)
#else
mpf_dump (u)
mpf_srcptr u;
#endif
{
mp_exp_t exp;
char *str;
str = mpf_get_str (0, &exp, 10, 0, u);
if (str[0] == '-')
printf ("-0.%se%ld\n", str + 1, exp);
else
printf ("0.%se%ld\n", str, exp);
(*_mp_free_func) (str, 0);/* ??? broken alloc interface, pass what size ??? */
}

121
gnu/lib/libgmp/mpf/eq.c Normal file
View File

@ -0,0 +1,121 @@
/* mpf_eq -- Compare two floats up to a specified bit #.
Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
int
#if __STDC__
mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits)
#else
mpf_eq (u, v, n_bits)
mpf_srcptr u;
mpf_srcptr v;
unsigned long int n_bits;
#endif
{
mp_srcptr up, vp;
mp_size_t usize, vsize, size, i;
mp_exp_t uexp, vexp;
int usign;
uexp = u->_mp_exp;
vexp = v->_mp_exp;
usize = u->_mp_size;
vsize = v->_mp_size;
/* 1. Are the signs different? */
if ((usize ^ vsize) >= 0)
{
/* U and V are both non-negative or both negative. */
if (usize == 0)
return vsize == 0;
if (vsize == 0)
return 0;
/* Fall out. */
}
else
{
/* Either U or V is negative, but not both. */
return 0;
}
/* U and V have the same sign and are both non-zero. */
usign = usize >= 0 ? 1 : -1;
/* 2. Are the exponents different? */
if (uexp > vexp)
return 0; /* ??? handle (uexp = vexp + 1) */
if (vexp > uexp)
return 0; /* ??? handle (vexp = uexp + 1) */
usize = ABS (usize);
vsize = ABS (vsize);
up = u->_mp_d;
vp = v->_mp_d;
/* Ignore zeroes at the low end of U and V. */
while (up[0] == 0)
{
up++;
usize--;
}
while (vp[0] == 0)
{
vp++;
vsize--;
}
if (usize > vsize)
{
if (vsize * BITS_PER_MP_LIMB < n_bits)
return 0; /* surely too different */
size = vsize;
}
else if (vsize > usize)
{
if (usize * BITS_PER_MP_LIMB < n_bits)
return 0; /* surely too different */
size = usize;
}
else
{
size = usize;
}
if (size > (n_bits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB)
size = (n_bits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB;
up += usize - size;
vp += vsize - size;
for (i = size - 1; i >= 0; i--)
{
if (up[i] != vp[i])
return 0;
}
return 1;
}

View File

@ -0,0 +1,54 @@
/* double mpf_get_d (mpf_t src) -- Return the double approximation to SRC.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
double
#if __STDC__
mpf_get_d (mpf_srcptr src)
#else
mpf_get_d (src)
mpf_srcptr src;
#endif
{
double res;
mp_size_t size, i, n_limbs_to_use;
int negative;
mp_ptr qp;
size = SIZ(src);
if (size == 0)
return 0.0;
negative = size < 0;
size = ABS (size);
qp = PTR(src);
res = qp[size - 1];
n_limbs_to_use = MIN (LIMBS_PER_DOUBLE, size);
for (i = 2; i <= n_limbs_to_use; i++)
res = res * MP_BASE_AS_DOUBLE + qp[size - i];
res = __gmp_scale2 (res, (EXP(src) - n_limbs_to_use) * BITS_PER_MP_LIMB);
return negative ? -res : res;
}

View File

@ -0,0 +1,34 @@
/* mpf_get_prec(x) -- Return the precision in bits of x.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
unsigned long int
#if __STDC__
mpf_get_prec (mpf_srcptr x)
#else
mpf_get_prec (x)
mpf_srcptr x;
#endif
{
return (unsigned long int) x->_mp_prec * BITS_PER_MP_LIMB - BITS_PER_MP_LIMB;
}

View File

@ -0,0 +1,500 @@
/* mpf_get_str (digit_ptr, exp, base, n_digits, a) -- Convert the floating
point number A to a base BASE number and store N_DIGITS raw digits at
DIGIT_PTR, and the base BASE exponent in the word pointed to by EXP. For
example, the number 3.1416 would be returned as "31416" in DIGIT_PTR and
1 in EXP.
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
/*
New algorithm for converting fractions (951019):
0. Call the fraction to convert F.
1. Compute [exp * log(2^BITS_PER_MP_LIMB)/log(B)], i.e.,
[exp * BITS_PER_MP_LIMB * __mp_bases[B].chars_per_bit_exactly]. Exp is
the number of limbs between the limb point and the most significant
non-zero limb. Call this result n.
2. Compute B^n.
3. F*B^n will now be just below 1, which can be converted easily. (Just
multiply by B repeatedly, and see the digits fall out as integers.)
We should interrupt the conversion process of F*B^n as soon as the number
of digits requested have been generated.
New algorithm for converting integers (951019):
0. Call the integer to convert I.
1. Compute [exp * log(2^BITS_PER_MP_LIMB)/log(B)], i.e.,
[exp BITS_PER_MP_LIMB * __mp_bases[B].chars_per_bit_exactly]. Exp is
the number of limbs between the limb point and the least significant
non-zero limb. Call this result n.
2. Compute B^n.
3. I/B^n can be converted easily. (Just divide by B repeatedly. In GMP,
this is best done by calling mpn_get_str.)
Note that converting I/B^n could yield more digits than requested. For
efficiency, the variable n above should be set larger in such cases, to
kill all undesired digits in the division in step 3.
*/
char *
#if __STDC__
mpf_get_str (char *digit_ptr, mp_exp_t *exp, int base, size_t n_digits, mpf_srcptr u)
#else
mpf_get_str (digit_ptr, exp, base, n_digits, u)
char *digit_ptr;
mp_exp_t *exp;
int base;
size_t n_digits;
mpf_srcptr u;
#endif
{
mp_size_t usize;
mp_exp_t uexp;
unsigned char *str;
size_t str_size;
char *num_to_text;
long i; /* should be size_t */
mp_ptr rp;
mp_limb_t big_base;
size_t digits_computed_so_far;
int dig_per_u;
mp_srcptr up;
unsigned char *tstr;
mp_exp_t exp_in_base;
TMP_DECL (marker);
TMP_MARK (marker);
usize = u->_mp_size;
uexp = u->_mp_exp;
if (base >= 0)
{
if (base == 0)
base = 10;
num_to_text = "0123456789abcdefghijklmnopqrstuvwxyz";
}
else
{
base = -base;
num_to_text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
/* Don't compute more digits than U can accurately represent.
Also, if 0 digits were requested, give *exactly* as many digits
as can be accurately represented. */
{
size_t max_digits = (((u->_mp_prec - 1) * BITS_PER_MP_LIMB)
* __mp_bases[base].chars_per_bit_exactly);
if (n_digits == 0 || n_digits > max_digits)
n_digits = max_digits;
}
if (digit_ptr == 0)
{
/* We didn't get a string from the user. Allocate one (and return
a pointer to it) with space for `-' and terminating null. */
digit_ptr = (char *) (*_mp_allocate_func) (n_digits + 2);
}
if (usize == 0)
{
*exp = 0;
*digit_ptr = 0;
return digit_ptr;
}
str = (unsigned char *) digit_ptr;
/* Allocate temporary digit space. We can't put digits directly in the user
area, since we almost always generate more digits than requested. */
tstr = (unsigned char *) TMP_ALLOC (n_digits + 3 * BITS_PER_MP_LIMB);
if (usize < 0)
{
*digit_ptr = '-';
str++;
usize = -usize;
}
digits_computed_so_far = 0;
if (uexp > usize)
{
/* The number has just an integral part. */
mp_size_t rsize;
mp_size_t exp_in_limbs;
mp_size_t msize;
mp_ptr tp, xp, mp;
int cnt;
mp_limb_t cy;
mp_size_t start_str;
mp_size_t n_limbs;
n_limbs = 2 + ((mp_size_t) (n_digits / __mp_bases[base].chars_per_bit_exactly)
/ BITS_PER_MP_LIMB);
/* Compute n such that [u/B^n] contains (somewhat) more than n_digits
digits. (We compute less than that only if that is an exact number,
i.e., exp is small enough.) */
exp_in_limbs = uexp;
if (n_limbs >= exp_in_limbs)
{
/* The number is so small that we convert the entire number. */
exp_in_base = 0;
rp = (mp_ptr) TMP_ALLOC (exp_in_limbs * BYTES_PER_MP_LIMB);
MPN_ZERO (rp, exp_in_limbs - usize);
MPN_COPY (rp + (exp_in_limbs - usize), u->_mp_d, usize);
rsize = exp_in_limbs;
}
else
{
exp_in_limbs -= n_limbs;
exp_in_base = (((exp_in_limbs * BITS_PER_MP_LIMB - 1))
* __mp_bases[base].chars_per_bit_exactly);
rsize = exp_in_limbs + 1;
rp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB);
tp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB);
rp[0] = base;
rsize = 1;
count_leading_zeros (cnt, exp_in_base);
for (i = BITS_PER_MP_LIMB - cnt - 2; i >= 0; i--)
{
mpn_mul_n (tp, rp, rp, rsize);
rsize = 2 * rsize;
rsize -= tp[rsize - 1] == 0;
xp = tp; tp = rp; rp = xp;
if (((exp_in_base >> i) & 1) != 0)
{
cy = mpn_mul_1 (rp, rp, rsize, (mp_limb_t) base);
rp[rsize] = cy;
rsize += cy != 0;
}
}
mp = u->_mp_d;
msize = usize;
{
mp_ptr qp;
mp_limb_t qflag;
mp_size_t xtra;
if (msize < rsize)
{
mp_ptr tmp = (mp_ptr) TMP_ALLOC ((rsize+1)* BYTES_PER_MP_LIMB);
MPN_ZERO (tmp, rsize - msize);
MPN_COPY (tmp + rsize - msize, mp, msize);
mp = tmp;
msize = rsize;
}
else
{
mp_ptr tmp = (mp_ptr) TMP_ALLOC ((msize+1)* BYTES_PER_MP_LIMB);
MPN_COPY (tmp, mp, msize);
mp = tmp;
}
count_leading_zeros (cnt, rp[rsize - 1]);
cy = 0;
if (cnt != 0)
{
mpn_lshift (rp, rp, rsize, cnt);
cy = mpn_lshift (mp, mp, msize, cnt);
if (cy)
mp[msize++] = cy;
}
{
mp_size_t qsize = n_limbs + (cy != 0);
qp = (mp_ptr) TMP_ALLOC ((qsize + 1) * BYTES_PER_MP_LIMB);
xtra = qsize - (msize - rsize);
qflag = mpn_divrem (qp, xtra, mp, msize, rp, rsize);
qp[qsize] = qflag;
rsize = qsize + qflag;
rp = qp;
}
}
}
str_size = mpn_get_str (tstr, base, rp, rsize);
if (str_size > n_digits + 3 * BITS_PER_MP_LIMB)
abort ();
start_str = 0;
while (tstr[start_str] == 0)
start_str++;
for (i = start_str; i < str_size; i++)
{
tstr[digits_computed_so_far++] = tstr[i];
if (digits_computed_so_far > n_digits)
break;
}
exp_in_base = exp_in_base + str_size - start_str;
goto finish_up;
}
exp_in_base = 0;
if (uexp > 0)
{
/* The number has an integral part, convert that first.
If there is a fractional part too, it will be handled later. */
mp_size_t start_str;
rp = (mp_ptr) TMP_ALLOC (uexp * BYTES_PER_MP_LIMB);
up = u->_mp_d + usize - uexp;
MPN_COPY (rp, up, uexp);
str_size = mpn_get_str (tstr, base, rp, uexp);
start_str = 0;
while (tstr[start_str] == 0)
start_str++;
for (i = start_str; i < str_size; i++)
{
tstr[digits_computed_so_far++] = tstr[i];
if (digits_computed_so_far > n_digits)
{
exp_in_base = str_size - start_str;
goto finish_up;
}
}
exp_in_base = str_size - start_str;
/* Modify somewhat and fall out to convert fraction... */
usize -= uexp;
uexp = 0;
}
if (usize <= 0)
goto finish_up;
/* Convert the fraction. */
{
mp_size_t rsize, msize;
mp_ptr rp, tp, xp, mp;
int cnt;
mp_limb_t cy;
mp_exp_t nexp;
big_base = __mp_bases[base].big_base;
dig_per_u = __mp_bases[base].chars_per_limb;
/* Hack for correctly (although not efficiently) converting to bases that
are powers of 2. If we deem it important, we could handle powers of 2
by shifting and masking (just like mpn_get_str). */
if (big_base < 10) /* logarithm of base when power of two */
{
int logbase = big_base;
if (dig_per_u * logbase == BITS_PER_MP_LIMB)
dig_per_u--;
big_base = (mp_limb_t) 1 << (dig_per_u * logbase);
/* fall out to general code... */
}
#if 0
if (0 && uexp == 0)
{
rp = (mp_ptr) TMP_ALLOC (usize * BYTES_PER_MP_LIMB);
up = u->_mp_d;
MPN_COPY (rp, up, usize);
rsize = usize;
nexp = 0;
}
else
{}
#endif
uexp = -uexp;
if (u->_mp_d[usize - 1] == 0)
cnt = 0;
else
count_leading_zeros (cnt, u->_mp_d[usize - 1]);
nexp = ((uexp * BITS_PER_MP_LIMB) + cnt)
* __mp_bases[base].chars_per_bit_exactly;
if (nexp == 0)
{
rp = (mp_ptr) TMP_ALLOC (usize * BYTES_PER_MP_LIMB);
up = u->_mp_d;
MPN_COPY (rp, up, usize);
rsize = usize;
}
else
{
rsize = uexp + 2;
rp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB);
tp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB);
rp[0] = base;
rsize = 1;
count_leading_zeros (cnt, nexp);
for (i = BITS_PER_MP_LIMB - cnt - 2; i >= 0; i--)
{
mpn_mul_n (tp, rp, rp, rsize);
rsize = 2 * rsize;
rsize -= tp[rsize - 1] == 0;
xp = tp; tp = rp; rp = xp;
if (((nexp >> i) & 1) != 0)
{
cy = mpn_mul_1 (rp, rp, rsize, (mp_limb_t) base);
rp[rsize] = cy;
rsize += cy != 0;
}
}
/* Did our multiplier (base^nexp) cancel with uexp? */
#if 0
if (uexp != rsize)
{
do
{
cy = mpn_mul_1 (rp, rp, rsize, big_base);
nexp += dig_per_u;
}
while (cy == 0);
rp[rsize++] = cy;
}
#endif
mp = u->_mp_d;
msize = usize;
tp = (mp_ptr) TMP_ALLOC ((rsize + msize) * BYTES_PER_MP_LIMB);
if (rsize > msize)
cy = mpn_mul (tp, rp, rsize, mp, msize);
else
cy = mpn_mul (tp, mp, msize, rp, rsize);
rsize += msize;
rsize -= cy == 0;
rp = tp;
/* If we already output digits (for an integral part) pad
leading zeros. */
if (digits_computed_so_far != 0)
for (i = 0; i < nexp; i++)
tstr[digits_computed_so_far++] = 0;
}
while (digits_computed_so_far <= n_digits)
{
/* For speed: skip trailing zeroes. */
if (rp[0] == 0)
{
rp++;
rsize--;
if (rsize == 0)
{
n_digits = digits_computed_so_far;
break;
}
}
cy = mpn_mul_1 (rp, rp, rsize, big_base);
if (digits_computed_so_far == 0 && cy == 0)
{
abort ();
nexp += dig_per_u;
continue;
}
/* Convert N1 from BIG_BASE to a string of digits in BASE
using single precision operations. */
{
unsigned char *s = tstr + digits_computed_so_far + dig_per_u;
for (i = dig_per_u - 1; i >= 0; i--)
{
*--s = cy % base;
cy /= base;
}
}
digits_computed_so_far += dig_per_u;
}
if (exp_in_base == 0)
exp_in_base = -nexp;
}
finish_up:
/* We can have at most one leading 0. Remove it. */
if (tstr[0] == 0)
{
tstr++;
digits_computed_so_far--;
exp_in_base--;
}
/* We should normally have computed too many digits. Round the result
at the point indicated by n_digits. */
if (digits_computed_so_far > n_digits)
{
/* Round the result. */
if (tstr[n_digits] * 2 >= base)
{
digits_computed_so_far = n_digits;
for (i = n_digits - 1; i >= 0; i--)
{
unsigned int x;
x = ++(tstr[i]);
if (x < base)
goto rounded_ok;
digits_computed_so_far--;
}
tstr[0] = 1;
digits_computed_so_far = 1;
exp_in_base++;
rounded_ok:;
}
}
/* We might have fewer digits than requested as a result of rounding above,
(i.e. 0.999999 => 1.0) or because we have a number that simply doesn't
need many digits in this base (i.e., 0.125 in base 10). */
if (n_digits > digits_computed_so_far)
n_digits = digits_computed_so_far;
/* Remove trailing 0. There can be many zeros. */
while (n_digits != 0 && tstr[n_digits - 1] == 0)
n_digits--;
/* Translate to ascii and null-terminate. */
for (i = 0; i < n_digits; i++)
*str++ = num_to_text[tstr[i]];
*str = 0;
*exp = exp_in_base;
TMP_FREE (marker);
return digit_ptr;
}
#if COPY_THIS_TO_OTHER_PLACES
/* Use this expression in lots of places in the library instead of the
count_leading_zeros+expression that is used currently. This expression
is much more accurate and will save odles of memory. */
rsize = ((mp_size_t) (exp_in_base / __mp_bases[base].chars_per_bit_exactly)
+ BITS_PER_MP_LIMB) / BITS_PER_MP_LIMB;
#endif

38
gnu/lib/libgmp/mpf/init.c Normal file
View File

@ -0,0 +1,38 @@
/* mpf_init() -- Make a new multiple precision number with value 0.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_init (mpf_ptr r)
#else
mpf_init (r)
mpf_ptr r;
#endif
{
mp_size_t prec = __gmp_default_fp_limb_precision;
r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB);
r->_mp_prec = prec;
r->_mp_size = 0;
r->_mp_exp = 0;
}

View File

@ -0,0 +1,41 @@
/* mpf_init2() -- Make a new multiple precision number with value 0.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_init2 (mpf_ptr r, unsigned long int prec_in_bits)
#else
mpf_init2 (r, prec_in_bits)
mpf_ptr r;
unsigned long int prec_in_bits;
#endif
{
mp_size_t prec;
prec = (MAX (53, prec_in_bits) + 2 * BITS_PER_MP_LIMB - 1)/BITS_PER_MP_LIMB;
r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB);
r->_mp_prec = prec;
r->_mp_size = 0;
r->_mp_exp = 0;
}

View File

@ -0,0 +1,89 @@
/* mpf_inp_str(dest_float, stream, base) -- Input a number in base
BASE from stdio stream STREAM and store the result in DEST_FLOAT.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
#include <ctype.h>
#include "gmp.h"
#include "gmp-impl.h"
size_t
#if __STDC__
mpf_inp_str (mpf_ptr rop, FILE *stream, int base)
#else
mpf_inp_str (rop, stream, base)
mpf_ptr rop;
FILE *stream;
int base;
#endif
{
char *str;
size_t alloc_size, str_size;
int c;
size_t retval;
size_t nread;
if (stream == 0)
stream = stdin;
alloc_size = 100;
str = (char *) (*_mp_allocate_func) (alloc_size);
str_size = 0;
nread = 0;
/* Skip whitespace. */
do
{
c = getc (stream);
nread++;
}
while (isspace (c));
for (;;)
{
if (str_size >= alloc_size)
{
size_t old_alloc_size = alloc_size;
alloc_size = alloc_size * 3 / 2;
str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size);
}
if (c == EOF || isspace (c))
break;
str[str_size++] = c;
c = getc (stream);
}
ungetc (c, stream);
if (str_size >= alloc_size)
{
size_t old_alloc_size = alloc_size;
alloc_size = alloc_size * 3 / 2;
str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size);
}
str[str_size] = 0;
retval = mpf_set_str (rop, str, base);
if (retval == -1)
return 0; /* error */
(*_mp_free_func) (str, alloc_size);
return str_size + nread;
}

59
gnu/lib/libgmp/mpf/iset.c Normal file
View File

@ -0,0 +1,59 @@
/* mpf_init_set -- Initialize a float and assign it from another float.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_init_set (mpf_ptr r, mpf_srcptr s)
#else
mpf_init_set (r, s)
mpf_ptr r;
mpf_srcptr s;
#endif
{
mp_ptr rp, sp;
mp_size_t ssize, size;
mp_size_t prec;
prec = __gmp_default_fp_limb_precision;
r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB);
r->_mp_prec = prec;
prec++; /* lie not to lose precision in assignment */
ssize = s->_mp_size;
size = ABS (ssize);
rp = r->_mp_d;
sp = s->_mp_d;
if (size > prec)
{
sp += size - prec;
size = prec;
}
MPN_COPY (rp, sp, size);
r->_mp_exp = s->_mp_exp;
r->_mp_size = ssize >= 0 ? size : -size;
}

View File

@ -0,0 +1,39 @@
/* mpf_init_set_d -- Initialize a float and assign it from a double.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_init_set_d (mpf_ptr r, double val)
#else
mpf_init_set_d (r, val)
mpf_ptr r;
double val;
#endif
{
mp_size_t prec = __gmp_default_fp_limb_precision;
r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB);
r->_mp_prec = prec;
mpf_set_d (r, val);
}

View File

@ -0,0 +1,55 @@
/* mpf_init_set_si() -- Initialize a float and assign it from a signed int.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_init_set_si (mpf_ptr r, long int val)
#else
mpf_init_set_si (r, val)
mpf_ptr r;
long int val;
#endif
{
mp_size_t prec = __gmp_default_fp_limb_precision;
r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB);
r->_mp_prec = prec;
if (val > 0)
{
r->_mp_d[0] = val;
r->_mp_size = 1;
r->_mp_exp = 1;
}
else if (val < 0)
{
r->_mp_d[0] = -val;
r->_mp_size = -1;
r->_mp_exp = 1;
}
else
{
r->_mp_size = 0;
r->_mp_exp = 0;
}
}

View File

@ -0,0 +1,40 @@
/* mpf_init_set_str -- Initialize a float and assign it from a string.
Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
int
#if __STDC__
mpf_init_set_str (mpf_ptr r, const char *s, int base)
#else
mpf_init_set_str (r, s, base)
mpf_ptr r;
const char *s;
int base;
#endif
{
mp_size_t prec = __gmp_default_fp_limb_precision;
r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB);
r->_mp_prec = prec;
return mpf_set_str (r, s, base);
}

View File

@ -0,0 +1,40 @@
/* mpf_init_set_ui() -- Initialize a float and assign it from an unsigned int.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_init_set_ui (mpf_ptr r, unsigned long int val)
#else
mpf_init_set_ui (r, val)
mpf_ptr r;
unsigned long int val;
#endif
{
mp_size_t prec = __gmp_default_fp_limb_precision;
r->_mp_d = (mp_ptr) (*_mp_allocate_func) ((prec + 1) * BYTES_PER_MP_LIMB);
r->_mp_prec = prec;
r->_mp_d[0] = val;
r->_mp_size = val != 0;
r->_mp_exp = val != 0;
}

94
gnu/lib/libgmp/mpf/mul.c Normal file
View File

@ -0,0 +1,94 @@
/* mpf_mul -- Multiply two floats.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_mul (mpf_ptr r, mpf_srcptr u, mpf_srcptr v)
#else
mpf_mul (r, u, v)
mpf_ptr r;
mpf_srcptr u;
mpf_srcptr v;
#endif
{
mp_srcptr up, vp;
mp_size_t usize, vsize;
mp_size_t sign_product;
mp_size_t prec = r->_mp_prec;
TMP_DECL (marker);
TMP_MARK (marker);
usize = u->_mp_size;
vsize = v->_mp_size;
sign_product = usize ^ vsize;
usize = ABS (usize);
vsize = ABS (vsize);
up = u->_mp_d;
vp = v->_mp_d;
if (usize > prec)
{
up += usize - prec;
usize = prec;
}
if (vsize > prec)
{
vp += vsize - prec;
vsize = prec;
}
if (usize == 0 || vsize == 0)
{
r->_mp_size = 0;
r->_mp_exp = 0; /* ??? */
}
else
{
mp_size_t rsize;
mp_limb_t cy_limb;
mp_ptr rp, tp;
mp_size_t adj;
rsize = usize + vsize;
tp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB);
cy_limb = (usize >= vsize
? mpn_mul (tp, up, usize, vp, vsize)
: mpn_mul (tp, vp, vsize, up, usize));
adj = cy_limb == 0;
rsize -= adj;
prec++;
if (rsize > prec)
{
tp += rsize - prec;
rsize = prec;
}
rp = r->_mp_d;
MPN_COPY (rp, tp, rsize);
r->_mp_exp = u->_mp_exp + v->_mp_exp - adj;
r->_mp_size = sign_product >= 0 ? rsize : -rsize;
}
TMP_FREE (marker);
}

View File

@ -0,0 +1,89 @@
/* mpf_mul_2exp -- Multiply a float by 2^n.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_mul_2exp (mpf_ptr r, mpf_srcptr u, unsigned long int exp)
#else
mpf_mul_2exp (r, u, exp)
mpf_ptr r;
mpf_srcptr u;
unsigned long int exp;
#endif
{
mp_srcptr up;
mp_ptr rp = r->_mp_d;
mp_size_t usize;
mp_size_t abs_usize;
mp_size_t prec = r->_mp_prec;
mp_exp_t uexp = u->_mp_exp;
usize = u->_mp_size;
if (usize == 0)
{
r->_mp_size = 0;
r->_mp_exp = 0;
return;
}
abs_usize = ABS (usize);
up = u->_mp_d;
if (abs_usize > prec)
{
up += abs_usize - prec;
abs_usize = prec;
}
if (exp % BITS_PER_MP_LIMB == 0)
{
if (rp != up)
MPN_COPY (rp, up, abs_usize);
r->_mp_size = usize >= 0 ? abs_usize : -abs_usize;
r->_mp_exp = uexp + exp / BITS_PER_MP_LIMB;
}
else
{
mp_limb_t cy_limb;
if (r != u)
{
cy_limb = mpn_lshift (rp, up, abs_usize, exp % BITS_PER_MP_LIMB);
rp[abs_usize] = cy_limb;
cy_limb = cy_limb != 0;
}
else
{
/* Use mpn_rshift since mpn_lshift operates downwards, and we
therefore would clobber part of U before using that part. */
cy_limb = mpn_rshift (rp + 1, up, abs_usize, -exp % BITS_PER_MP_LIMB);
rp[0] = cy_limb;
cy_limb = rp[abs_usize] != 0;
}
abs_usize += cy_limb;
r->_mp_size = usize >= 0 ? abs_usize : -abs_usize;
r->_mp_exp = uexp + exp / BITS_PER_MP_LIMB + cy_limb;
}
}

View File

@ -0,0 +1,74 @@
/* mpf_mul_ui -- Multiply a float and an unsigned integer.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_mul_ui (mpf_ptr r, mpf_srcptr u, unsigned long int v)
#else
mpf_mul_ui (r, u, v)
mpf_ptr r;
mpf_srcptr u;
unsigned long int v;
#endif
{
mp_srcptr up;
mp_size_t usize;
mp_size_t size;
mp_size_t prec = r->_mp_prec;
mp_limb_t cy_limb;
mp_ptr rp;
usize = u->_mp_size;
size = ABS (usize);
rp = r->_mp_d;
up = u->_mp_d;
if (size > prec)
{
up += size - prec;
size = prec;
}
#if 0
/* Since we can do it at almost no cost, remove zero limbs at low end of
result. */
if (up[0] == 0)
up++, size--;
#endif
if (size == 0 || v == 0)
{
r->_mp_size = 0;
r->_mp_exp = 0; /* ??? */
}
else
{
cy_limb = mpn_mul_1 (rp, up, size, (mp_limb_t) v);
rp[size] = cy_limb;
cy_limb = cy_limb != 0;
r->_mp_exp = u->_mp_exp + cy_limb;
size += cy_limb;
r->_mp_size = usize >= 0 ? size : -size;
}
}

59
gnu/lib/libgmp/mpf/neg.c Normal file
View File

@ -0,0 +1,59 @@
/* mpf_neg -- Negate a float.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_neg (mpf_ptr r, mpf_srcptr u)
#else
mpf_neg (r, u)
mpf_ptr r;
mpf_srcptr u;
#endif
{
mp_size_t size;
size = -u->_mp_size;
if (r != u)
{
mp_size_t prec;
mp_size_t asize;
mp_ptr rp, up;
prec = r->_mp_prec + 1; /* lie not to lose precision in assignment */
asize = ABS (size);
rp = r->_mp_d;
up = u->_mp_d;
if (asize > prec)
{
up += asize - prec;
asize = prec;
}
MPN_COPY (rp, up, asize);
r->_mp_exp = u->_mp_exp;
size = size >= 0 ? asize : -asize;
}
r->_mp_size = size;
}

View File

@ -0,0 +1,89 @@
/* mpf_out_str (stream, base, n_digits, op) -- Print N_DIGITS digits from
the float OP to STREAM in base BASE. Return the number of characters
written, or 0 if an error occurred.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
size_t
#if __STDC__
mpf_out_str (FILE *stream, int base, size_t n_digits, mpf_srcptr op)
#else
mpf_out_str (stream, base, n_digits, op)
FILE *stream;
int base;
size_t n_digits;
mpf_srcptr op;
#endif
{
char *str;
mp_exp_t exp;
size_t written;
TMP_DECL (marker);
TMP_MARK (marker);
if (base == 0)
base = 10;
if (n_digits == 0)
n_digits = (((op->_mp_prec - 1) * BITS_PER_MP_LIMB)
* __mp_bases[base].chars_per_bit_exactly);
if (stream == 0)
stream = stdout;
str = (char *) TMP_ALLOC (n_digits + 2); /* extra for minus sign and \0 */
mpf_get_str (str, &exp, base, n_digits, op);
n_digits = strlen (str);
written = 0;
/* Write sign */
if (str[0] == '-')
{
str++;
fputc ('-', stream);
written = 1;
}
fwrite ("0.", 1, 2, stream);
written += 2;
/* Write mantissa */
{
size_t fwret;
fwret = fwrite (str, 1, n_digits, stream);
written += fwret;
}
/* Write exponent */
{
int fpret;
fpret = fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), exp);
written += fpret;
}
TMP_FREE (marker);
return ferror (stream) ? 0 : written;
}

View File

@ -0,0 +1,65 @@
/* mpf_random2 -- Generate a positive random mpf_t of specified size, with
long runs of consecutive ones and zeros in the binary representation.
Intended for testing of other MP routines.
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#if defined (__hpux) || defined (alpha__) || defined (__svr4__) || defined (__SVR4)
/* HPUX lacks random(). DEC OSF/1 1.2 random() returns a double. */
long mrand48 ();
static inline long
random ()
{
return mrand48 ();
}
#else
long random ();
#endif
void
#if __STDC__
mpf_random2 (mpf_ptr x, mp_size_t size, mp_exp_t exp)
#else
mpf_random2 (x, size, exp)
mpf_ptr x;
mp_size_t size;
mp_exp_t exp;
#endif
{
mp_size_t asize;
mp_size_t prec = x->_mp_prec;
asize = ABS (size);
if (asize != 0)
{
if (asize > prec + 1)
asize = prec + 1;
mpn_random2 (x->_mp_d, asize);
}
if (exp != 0)
exp = random () % (2 * exp) - exp;
x->_mp_exp = asize == 0 ? 0 : exp;
x->_mp_size = size < 0 ? -asize : asize;
}

View File

@ -0,0 +1,52 @@
/* mpf_reldiff -- Generate the relative difference of two floats.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_reldiff (mpf_t rdiff, mpf_srcptr x, mpf_srcptr y)
#else
mpf_reldiff (rdiff, x, y)
mpf_t rdiff;
mpf_srcptr x;
mpf_srcptr y;
#endif
{
if (mpf_cmp_ui (x, 0) == 0)
{
mpf_set_ui (rdiff, (unsigned long int) (mpf_sgn (y) != 0));
}
else
{
mpf_t d;
mp_limb_t tmp_limb[2];
d->_mp_prec = 1;
d->_mp_d = tmp_limb;
mpf_sub (d, x, y);
mpf_abs (d, d);
mpf_div (rdiff, d, x);
}
}

53
gnu/lib/libgmp/mpf/set.c Normal file
View File

@ -0,0 +1,53 @@
/* mpf_set -- Assign a float from another float.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_set (mpf_ptr r, mpf_srcptr u)
#else
mpf_set (r, u)
mpf_ptr r;
mpf_srcptr u;
#endif
{
mp_ptr rp, up;
mp_size_t size, asize;
mp_size_t prec;
prec = r->_mp_prec + 1; /* lie not to lose precision in assignment */
size = u->_mp_size;
asize = ABS (size);
rp = r->_mp_d;
up = u->_mp_d;
if (asize > prec)
{
up += asize - prec;
asize = prec;
}
MPN_COPY (rp, up, asize);
r->_mp_exp = u->_mp_exp;
r->_mp_size = size >= 0 ? asize : -asize;
}

View File

@ -0,0 +1,47 @@
/* mpf_set_d -- Assign a float from a IEEE double.
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_set_d (mpf_ptr r, double d)
#else
mpf_set_d (r, d)
mpf_ptr r;
double d;
#endif
{
int negative;
if (d == 0)
{
SIZ(r) = 0;
EXP(r) = 0;
return;
}
negative = d < 0;
d = ABS (d);
EXP(r) = __gmp_extract_double (PTR(r), d);
SIZ(r) = negative ? -LIMBS_PER_DOUBLE : LIMBS_PER_DOUBLE;
}

View File

@ -0,0 +1,40 @@
/* mpf_set_default_prec --
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
mp_size_t __gmp_default_fp_limb_precision
= (53 + 2 * BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB;
void
#if __STDC__
mpf_set_default_prec (unsigned long int prec_in_bits)
#else
mpf_set_default_prec (prec_in_bits)
unsigned long int prec_in_bits;
#endif
{
mp_size_t prec;
prec = (MAX (53, prec_in_bits) + 2 * BITS_PER_MP_LIMB - 1)/BITS_PER_MP_LIMB;
__gmp_default_fp_limb_precision = prec;
}

View File

@ -0,0 +1,57 @@
/* mpf_set_prec(x) -- Change the precision of x.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_set_prec (mpf_ptr x, unsigned long int prec_in_bits)
#else
mpf_set_prec (x, prec_in_bits)
mpf_ptr x;
unsigned long int prec_in_bits;
#endif
{
mp_size_t prec;
mp_size_t size = ABS (x->_mp_size);
prec = (MAX (53, prec_in_bits) + 2 * BITS_PER_MP_LIMB - 1)/BITS_PER_MP_LIMB;
/* We want the most significant limbs, so move the limbs down if we are
about to truncate the value. */
if (size > prec + 1)
{
mp_size_t offset = size - (prec + 1);
mp_ptr xp = x->_mp_d;
MPN_COPY (xp, xp + offset, prec + 1);
}
x->_mp_d = (mp_ptr) (*_mp_reallocate_func)
(x->_mp_d,
(x->_mp_prec + 1) * BYTES_PER_MP_LIMB, (prec + 1) * BYTES_PER_MP_LIMB);
x->_mp_prec = prec;
/* If the precision decreased, truncate the number. */
if (size > prec + 1)
x->_mp_size = x->_mp_size >= 0 ? (prec + 1) : -(prec + 1);
}

View File

@ -0,0 +1,39 @@
/* mpf_set_prec_raw(x,bits) -- Change the precision of x without changing
allocation. For proper operation, the original precision need to be reset
sooner or later.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_set_prec_raw (mpf_ptr x, unsigned long int prec_in_bits)
#else
mpf_set_prec_raw (x, prec_in_bits)
mpf_ptr x;
unsigned long int prec_in_bits;
#endif
{
mp_size_t prec;
prec = (MAX (53, prec_in_bits) + 2 * BITS_PER_MP_LIMB - 1)/BITS_PER_MP_LIMB;
x->_mp_prec = prec;
}

170
gnu/lib/libgmp/mpf/set_q.c Normal file
View File

@ -0,0 +1,170 @@
/* mpf_set_q (mpf_t rop, mpq_t op) -- Convert the rational op to the float rop.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
/* Algorithm:
1. Develop >= n bits of src.num / src.den, where n is the number of bits
in a double. This (partial) division will use all bits from the
denominator.
2. Use the remainder to determine how to round the result.
3. Assign the integral result to a temporary double.
4. Scale the temporary double, and return the result.
An alternative algorithm, that would be faster:
0. Let n be somewhat larger than the number of significant bits in a double.
1. Extract the most significant n bits of the denominator, and an equal
number of bits from the numerator.
2. Interpret the extracted numbers as integers, call them a and b
respectively, and develop n bits of the fractions ((a + 1) / b) and
(a / (b + 1)) using mpn_divrem.
3. If the computed values are identical UP TO THE POSITION WE CARE ABOUT,
we are done. If they are different, repeat the algorithm from step 1,
but first let n = n * 2.
4. If we end up using all bits from the numerator and denominator, fall
back to the first algorithm above.
5. Just to make life harder, The computation of a + 1 and b + 1 above
might give carry-out... Needs special handling. It might work to
subtract 1 in both cases instead.
*/
void
#if __STDC__
mpf_set_q (mpf_t r, mpq_srcptr q)
#else
mpf_set_q (r, q)
mpf_t r;
mpq_srcptr q;
#endif
{
mp_ptr np, dp;
mp_ptr rp;
mp_size_t nsize, dsize;
mp_size_t qsize, rsize;
mp_size_t sign_quotient;
unsigned normalization_steps;
mp_limb_t qlimb;
mp_ptr qp;
mp_size_t prec;
mp_exp_t exp;
TMP_DECL (marker);
nsize = SIZ (&q->_mp_num);
dsize = SIZ (&q->_mp_den);
if (nsize == 0)
{
SIZ (r) = 0;
EXP (r) = 0;
return;
}
prec = PREC (r) + 1;
TMP_MARK (marker);
qp = PTR (r);
sign_quotient = nsize ^ dsize;
nsize = ABS (nsize);
dsize = ABS (dsize);
np = PTR (&q->_mp_num);
dp = PTR (&q->_mp_den);
exp = nsize - dsize;
if (nsize > prec)
{
np += nsize - prec;
nsize = prec;
}
if (dsize > prec)
{
dp += dsize - prec;
dsize = prec;
}
rsize = MAX (nsize, dsize);
rp = (mp_ptr) TMP_ALLOC ((rsize + 1) * BYTES_PER_MP_LIMB);
count_leading_zeros (normalization_steps, dp[dsize - 1]);
/* Normalize the denominator, i.e. make its most significant bit set by
shifting it NORMALIZATION_STEPS bits to the left. Also shift the
numerator the same number of steps (to keep the quotient the same!). */
if (normalization_steps != 0)
{
mp_ptr tp;
mp_limb_t nlimb;
/* Shift up the denominator setting the most significant bit of
the most significant limb. Use temporary storage not to clobber
the original contents of the denominator. */
tp = (mp_ptr) TMP_ALLOC (dsize * BYTES_PER_MP_LIMB);
mpn_lshift (tp, dp, dsize, normalization_steps);
dp = tp;
if (rsize != nsize)
{
MPN_ZERO (rp, rsize - nsize);
nlimb = mpn_lshift (rp + (rsize - nsize),
np, nsize, normalization_steps);
}
else
{
nlimb = mpn_lshift (rp, np, nsize, normalization_steps);
}
if (nlimb != 0)
{
rp[rsize] = nlimb;
rsize++;
exp++;
}
}
else
{
if (rsize != nsize)
{
MPN_ZERO (rp, rsize - nsize);
MPN_COPY (rp + (rsize - nsize), np, nsize);
}
else
{
MPN_COPY (rp, np, rsize);
}
}
qlimb = mpn_divrem (qp, prec - 1 - (rsize - dsize), rp, rsize, dp, dsize);
qsize = prec - 1;
if (qlimb)
{
qp[qsize] = qlimb;
qsize++;
exp++;
}
EXP (r) = exp;
SIZ (r) = qsize;
TMP_FREE (marker);
}

View File

@ -0,0 +1,51 @@
/* mpf_set_si() -- Assign a float from a signed int.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_set_si (mpf_ptr x, long int val)
#else
mpf_set_si (x, val)
mpf_ptr x;
long int val;
#endif
{
if (val > 0)
{
x->_mp_d[0] = val;
x->_mp_size = 1;
x->_mp_exp = 1;
}
else if (val < 0)
{
x->_mp_d[0] = -val;
x->_mp_size = -1;
x->_mp_exp = 1;
}
else
{
x->_mp_size = 0;
x->_mp_exp = 0;
}
}

View File

@ -0,0 +1,302 @@
/* mpf_set_str (dest, string, base) -- Convert the string STRING
in base BASE to a float in dest. If BASE is zero, the leading characters
of STRING is used to figure out the base.
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <string.h>
#include <ctype.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
long int strtol _PROTO ((const char *, char **ptr, int));
static int
digit_value_in_base (c, base)
int c;
int base;
{
int digit;
if (isdigit (c))
digit = c - '0';
else if (islower (c))
digit = c - 'a' + 10;
else if (isupper (c))
digit = c - 'A' + 10;
else
return -1;
if (digit < base)
return digit;
return -1;
}
int
#if __STDC__
mpf_set_str (mpf_ptr x, const char *str, int base)
#else
mpf_set_str (x, str, base)
mpf_ptr x;
char *str;
int base;
#endif
{
size_t str_size;
char *s, *begs;
size_t i;
mp_size_t xsize;
int c;
int negative;
char *dotpos = 0;
int expflag;
int decimal_exponent_flag;
TMP_DECL (marker);
TMP_MARK (marker);
c = *str;
/* Skip whitespace. */
while (isspace (c))
c = *++str;
negative = 0;
if (c == '-')
{
negative = 1;
c = *++str;
}
decimal_exponent_flag = base < 0;
base = ABS (base);
if (digit_value_in_base (c, base == 0 ? 10 : base) < 0)
return -1; /* error if no digits */
/* If BASE is 0, try to find out the base by looking at the initial
characters. */
if (base == 0)
{
base = 10;
#if 0
if (c == '0')
{
base = 8;
c = *++str;
if (c == 'x' || c == 'X')
base = 16;
}
#endif
}
expflag = 0;
str_size = strlen (str);
for (i = 0; i < str_size; i++)
{
c = str[i];
if (c == '@' || (base <= 10 && (c == 'e' || c == 'E')))
{
expflag = 1;
str_size = i;
break;
}
}
s = begs = (char *) TMP_ALLOC (str_size + 1);
for (i = 0; i < str_size; i++)
{
c = *str;
if (!isspace (c))
{
int dig;
if (c == '.')
{
if (dotpos != 0)
{
TMP_FREE (marker);
return -1;
}
dotpos = s;
}
else
{
dig = digit_value_in_base (c, base);
if (dig < 0)
{
TMP_FREE (marker);
return -1;
}
*s++ = dig;
}
}
c = *++str;
}
str_size = s - begs;
xsize = str_size / __mp_bases[base].chars_per_limb + 2;
{
long exp_in_base;
mp_size_t rsize, msize;
int cnt, i;
mp_ptr mp, xp, tp, rp;
mp_limb_t cy;
mp_exp_t exp_in_limbs;
mp_size_t prec = x->_mp_prec;
int divflag;
mp_size_t xxx = 0;
mp = (mp_ptr) TMP_ALLOC (xsize * BYTES_PER_MP_LIMB);
msize = mpn_set_str (mp, (unsigned char *) begs, str_size, base);
if (msize == 0)
{
x->_mp_size = 0;
x->_mp_exp = 0;
TMP_FREE (marker);
return 0;
}
if (expflag != 0)
exp_in_base = strtol (str + 1, (char **) 0,
decimal_exponent_flag ? 10 : base);
else
exp_in_base = 0;
if (dotpos != 0)
exp_in_base -= s - dotpos;
divflag = exp_in_base < 0;
exp_in_base = ABS (exp_in_base);
if (exp_in_base == 0)
{
MPN_COPY (x->_mp_d, mp, msize);
x->_mp_size = negative ? -msize : msize;
x->_mp_exp = msize;
TMP_FREE (marker);
return 0;
}
#if 1
rsize = (((mp_size_t) (exp_in_base / __mp_bases[base].chars_per_bit_exactly))
/ BITS_PER_MP_LIMB + 3);
#else
count_leading_zeros (cnt, (mp_limb_t) base);
rsize = exp_in_base - cnt * exp_in_base / BITS_PER_MP_LIMB + 1;
#endif
rp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB);
tp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB);
rp[0] = base;
rsize = 1;
count_leading_zeros (cnt, exp_in_base);
for (i = BITS_PER_MP_LIMB - cnt - 2; i >= 0; i--)
{
mpn_mul_n (tp, rp, rp, rsize);
rsize = 2 * rsize;
rsize -= tp[rsize - 1] == 0;
xp = tp; tp = rp; rp = xp;
if (((exp_in_base >> i) & 1) != 0)
{
cy = mpn_mul_1 (rp, rp, rsize, (mp_limb_t) base);
rp[rsize] = cy;
rsize += cy != 0;
}
}
if (rsize > prec)
{
xxx += rsize - prec;
rp += rsize - prec;
rsize = prec;
}
#if 0
if (msize > prec)
{
xxx -= msize - prec;
mp += msize - prec;
msize = prec;
}
#endif
if (divflag)
{
mp_ptr qp;
mp_limb_t qflag;
mp_size_t xtra;
if (msize <= rsize)
{
/* Allocate extra limb for current divrem sematics. */
mp_ptr tmp = (mp_ptr) TMP_ALLOC ((rsize + 1) * BYTES_PER_MP_LIMB);
MPN_ZERO (tmp, rsize - msize);
MPN_COPY (tmp + rsize - msize, mp, msize);
mp = tmp;
xxx += rsize - msize;
msize = rsize;
}
count_leading_zeros (cnt, rp[rsize - 1]);
if (cnt != 0)
{
mpn_lshift (rp, rp, rsize, cnt);
cy = mpn_lshift (mp, mp, msize, cnt);
if (cy)
mp[msize++] = cy;
}
qp = (mp_ptr) TMP_ALLOC ((prec + 1) * BYTES_PER_MP_LIMB);
xtra = prec - (msize - rsize);
qflag = mpn_divrem (qp, xtra, mp, msize, rp, rsize);
qp[prec] = qflag;
tp = qp;
rsize = prec + qflag;
exp_in_limbs = rsize - xtra - xxx;
}
else
{
tp = (mp_ptr) TMP_ALLOC ((rsize + msize) * BYTES_PER_MP_LIMB);
if (rsize > msize)
mpn_mul (tp, rp, rsize, mp, msize);
else
mpn_mul (tp, mp, msize, rp, rsize);
rsize += msize;
rsize -= tp[rsize - 1] == 0;
exp_in_limbs = rsize + xxx;
if (rsize > prec)
{
xxx = rsize - prec;
tp += rsize - prec;
rsize = prec;
exp_in_limbs += 0;
}
}
MPN_COPY (x->_mp_d, tp, rsize);
x->_mp_size = negative ? -rsize : rsize;
x->_mp_exp = exp_in_limbs;
TMP_FREE (marker);
return 0;
}
}

View File

@ -0,0 +1,45 @@
/* mpf_set_ui() -- Assign a float from an unsigned int.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_set_ui (mpf_ptr x, unsigned long int val)
#else
mpf_set_ui (x, val)
mpf_ptr x;
unsigned long int val;
#endif
{
if (val != 0)
{
x->_mp_d[0] = val;
x->_mp_size = 1;
x->_mp_exp = 1;
}
else
{
x->_mp_size = 0;
x->_mp_exp = 0;
}
}

View File

@ -0,0 +1,54 @@
/* mpf_set_z -- Assign a float from an integer.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_set_z (mpf_ptr r, mpz_srcptr u)
#else
mpf_set_z (r, u)
mpf_ptr r;
mpz_srcptr u;
#endif
{
mp_ptr rp, up;
mp_size_t size, asize;
mp_size_t prec;
prec = PREC (r) + 1;
size = SIZ (u);
asize = ABS (size);
rp = PTR (r);
up = PTR (u);
EXP (r) = asize;
if (asize > prec)
{
up += asize - prec;
asize = prec;
}
MPN_COPY (rp, up, asize);
SIZ (r) = size >= 0 ? asize : -asize;
}

35
gnu/lib/libgmp/mpf/size.c Normal file
View File

@ -0,0 +1,35 @@
/* mpf_size(x) -- return the number of limbs currently used by the
value of the float X.
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
size_t
#if __STDC__
mpf_size (mpf_srcptr x)
#else
mpf_size (x)
mpf_srcptr x;
#endif
{
return ABS (x->_mp_size);
}

75
gnu/lib/libgmp/mpf/sqrt.c Normal file
View File

@ -0,0 +1,75 @@
/* mpf_sqrt -- Compute the square root of a float.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_sqrt (mpf_ptr r, mpf_srcptr u)
#else
mpf_sqrt (r, u)
mpf_ptr r;
mpf_srcptr u;
#endif
{
mp_size_t usize;
mp_ptr up, tp;
mp_size_t prec;
mp_exp_t tsize, rexp;
TMP_DECL (marker);
usize = u->_mp_size;
if (usize <= 0)
{
usize = 1 - 1 / (usize == 0); /* Divide by zero for negative OP. */
r->_mp_size = usize; /* cheat flow by using usize here */
r->_mp_exp = 0;
return;
}
TMP_MARK (marker);
prec = r->_mp_prec;
rexp = (u->_mp_exp + 1) >> 1; /* round towards -inf */
tsize = 2 * prec + (u->_mp_exp & 1);
up = u->_mp_d;
tp = (mp_ptr) TMP_ALLOC (tsize * BYTES_PER_MP_LIMB);
if (usize > tsize)
{
up += usize - tsize;
usize = tsize;
MPN_COPY (tp, up, tsize);
}
else
{
MPN_ZERO (tp, tsize - usize);
MPN_COPY (tp + (tsize - usize), up, usize);
}
mpn_sqrtrem (r->_mp_d, NULL, tp, tsize);
r->_mp_size = (tsize + 1) / 2;
r->_mp_exp = rexp;
TMP_FREE (marker);
}

View File

@ -0,0 +1,61 @@
/* mpf_sqrt_ui -- Compute the square root of an unsigned integer.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_sqrt_ui (mpf_ptr r, unsigned long int u)
#else
mpf_sqrt_ui (r, u)
mpf_ptr r;
unsigned long int u;
#endif
{
mp_size_t rsize;
mp_ptr tp;
mp_size_t prec;
TMP_DECL (marker);
if (u == 0)
{
r->_mp_size = 0;
r->_mp_exp = 0;
return;
}
TMP_MARK (marker);
prec = r->_mp_prec;
rsize = 2 * prec + 1;
tp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB);
MPN_ZERO (tp, rsize - 1);
tp[rsize - 1] = u;
mpn_sqrtrem (r->_mp_d, NULL, tp, rsize);
r->_mp_size = prec + 1;
r->_mp_exp = 1;
TMP_FREE (marker);
}

402
gnu/lib/libgmp/mpf/sub.c Normal file
View File

@ -0,0 +1,402 @@
/* mpf_sub -- Subtract two floats.
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_sub (mpf_ptr r, mpf_srcptr u, mpf_srcptr v)
#else
mpf_sub (r, u, v)
mpf_ptr r;
mpf_srcptr u;
mpf_srcptr v;
#endif
{
mp_srcptr up, vp;
mp_ptr rp, tp;
mp_size_t usize, vsize, rsize;
mp_size_t prec;
mp_exp_t exp;
mp_size_t ediff;
int negate;
TMP_DECL (marker);
usize = u->_mp_size;
vsize = v->_mp_size;
/* Handle special cases that don't work in generic code below. */
if (usize == 0)
{
mpf_neg (r, v);
return;
}
if (vsize == 0)
{
mpf_set (r, u);
return;
}
/* If signs of U and V are different, perform addition. */
if ((usize ^ vsize) < 0)
{
__mpf_struct v_negated;
v_negated._mp_size = -vsize;
v_negated._mp_exp = v->_mp_exp;
v_negated._mp_d = v->_mp_d;
mpf_add (r, u, &v_negated);
return;
}
TMP_MARK (marker);
/* Signs are now known to be the same. */
negate = usize < 0;
/* Make U be the operand with the largest exponent. */
if (u->_mp_exp < v->_mp_exp)
{
mpf_srcptr t;
t = u; u = v; v = t;
negate ^= 1;
usize = u->_mp_size;
vsize = v->_mp_size;
}
usize = ABS (usize);
vsize = ABS (vsize);
up = u->_mp_d;
vp = v->_mp_d;
rp = r->_mp_d;
prec = r->_mp_prec + 1;
exp = u->_mp_exp;
ediff = u->_mp_exp - v->_mp_exp;
/* If ediff is 0 or 1, we might have a situation where the operands are
extremely close. We need to scan the operands from the most significant
end ignore the initial parts that are equal. */
if (ediff <= 1)
{
if (ediff == 0)
{
/* Skip leading limbs in U and V that are equal. */
if (up[usize - 1] == vp[vsize - 1])
{
/* This loop normally exits immediately. Optimize for that. */
do
{
usize--;
vsize--;
exp--;
if (usize == 0)
{
rsize = vsize;
tp = (mp_ptr) vp;
negate ^= 1;
goto normalize;
}
if (vsize == 0)
{
rsize = usize;
tp = (mp_ptr) up;
goto normalize;
}
}
while (up[usize - 1] == vp[vsize - 1]);
}
if (up[usize - 1] < vp[vsize - 1])
{
/* For simplicity, swap U and V. Note that since the loop above
wouldn't have exited unless up[usize - 1] and vp[vsize - 1]
were non-equal, this if-statement catches all cases where U
is smaller than V. */
{ mp_srcptr tp = up; up = vp; vp = tp; }
{ mp_size_t tsize = usize; usize = vsize; vsize = tsize; }
negate ^= 1;
/* negating ediff not necessary since it is 0. */
}
/* Check for
x+1 00000000 ...
x ffffffff ... */
if (up[usize - 1] != vp[vsize - 1] + 1)
goto general_case;
usize--;
vsize--;
exp--;
}
else /* ediff == 1 */
{
/* Check for
1 00000000 ...
0 ffffffff ... */
if (up[usize - 1] != 1 || vp[vsize - 1] != ~(mp_limb_t) 0
|| (usize >= 2 && up[usize - 2] != 0))
goto general_case;
usize--;
exp--;
}
/* Skip sequences of 00000000/ffffffff */
while (vsize != 0 && usize != 0 && up[usize - 1] == 0
&& vp[vsize - 1] == ~(mp_limb_t) 0)
{
usize--;
vsize--;
exp--;
}
if (usize == 0)
{
while (vsize != 0 && vp[vsize - 1] == ~(mp_limb_t) 0)
{
vsize--;
exp--;
}
}
if (usize > prec - 1)
{
up += usize - (prec - 1);
usize = prec - 1;
}
if (vsize > prec - 1)
{
vp += vsize - (prec - 1);
vsize = prec - 1;
}
tp = (mp_ptr) TMP_ALLOC (prec * BYTES_PER_MP_LIMB);
{
mp_limb_t cy_limb;
if (vsize == 0)
{
mp_size_t size, i;
size = usize;
for (i = 0; i < size; i++)
tp[i] = up[i];
tp[size] = 1;
rsize = size + 1;
exp++;
goto normalize;
}
if (usize == 0)
{
mp_size_t size, i;
size = vsize;
for (i = 0; i < size; i++)
tp[i] = ~vp[i];
cy_limb = 1 - mpn_add_1 (tp, tp, vsize, (mp_limb_t) 1);
rsize = vsize;
if (cy_limb == 0)
{
tp[rsize] = 1;
rsize++;
exp++;
}
goto normalize;
}
if (usize >= vsize)
{
/* uuuu */
/* vv */
mp_size_t size;
size = usize - vsize;
MPN_COPY (tp, up, size);
cy_limb = mpn_sub_n (tp + size, up + size, vp, vsize);
rsize = usize;
}
else /* (usize < vsize) */
{
/* uuuu */
/* vvvvvvv */
mp_size_t size, i;
size = vsize - usize;
for (i = 0; i < size; i++)
tp[i] = ~vp[i];
cy_limb = mpn_sub_n (tp + size, up, vp + size, usize);
cy_limb+= mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1);
cy_limb-= mpn_add_1 (tp, tp, vsize, (mp_limb_t) 1);
rsize = vsize;
}
if (cy_limb == 0)
{
tp[rsize] = 1;
rsize++;
exp++;
}
goto normalize;
}
}
general_case:
/* If U extends beyond PREC, ignore the part that does. */
if (usize > prec)
{
up += usize - prec;
usize = prec;
}
/* If V extends beyond PREC, ignore the part that does.
Note that this may make vsize negative. */
if (vsize + ediff > prec)
{
vp += vsize + ediff - prec;
vsize = prec - ediff;
}
/* Allocate temp space for the result. Allocate
just vsize + ediff later??? */
tp = (mp_ptr) TMP_ALLOC (prec * BYTES_PER_MP_LIMB);
if (ediff >= prec)
{
/* V completely cancelled. */
if (tp != up)
MPN_COPY (rp, up, usize);
rsize = usize;
}
else
{
/* Locate the least significant non-zero limb in (the needed
parts of) U and V, to simplify the code below. */
for (;;)
{
if (vsize == 0)
{
MPN_COPY (rp, up, usize);
rsize = usize;
goto done;
}
if (vp[0] != 0)
break;
vp++, vsize--;
}
for (;;)
{
if (usize == 0)
{
MPN_COPY (rp, vp, vsize);
rsize = vsize;
negate ^= 1;
goto done;
}
if (up[0] != 0)
break;
up++, usize--;
}
/* uuuu | uuuu | uuuu | uuuu | uuuu */
/* vvvvvvv | vv | vvvvv | v | vv */
if (usize > ediff)
{
/* U and V partially overlaps. */
if (ediff == 0)
{
/* Have to compare the leading limbs of u and v
to determine whether to compute u - v or v - u. */
if (usize >= vsize)
{
/* uuuu */
/* vv */
mp_size_t size;
size = usize - vsize;
MPN_COPY (tp, up, size);
mpn_sub_n (tp + size, up + size, vp, vsize);
rsize = usize;
}
else /* (usize < vsize) */
{
/* uuuu */
/* vvvvvvv */
mp_size_t size, i;
size = vsize - usize;
tp[0] = -vp[0];
for (i = 1; i < size; i++)
tp[i] = ~vp[i];
mpn_sub_n (tp + size, up, vp + size, usize);
mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1);
rsize = vsize;
}
}
else
{
if (vsize + ediff <= usize)
{
/* uuuu */
/* v */
mp_size_t size;
size = usize - ediff - vsize;
MPN_COPY (tp, up, size);
mpn_sub (tp + size, up + size, usize - size, vp, vsize);
rsize = usize;
}
else
{
/* uuuu */
/* vvvvv */
mp_size_t size, i;
size = vsize + ediff - usize;
tp[0] = -vp[0];
for (i = 1; i < size; i++)
tp[i] = ~vp[i];
mpn_sub (tp + size, up, usize, vp + size, usize - ediff);
mpn_sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1);
rsize = vsize + ediff;
}
}
}
else
{
/* uuuu */
/* vv */
mp_size_t size, i;
size = vsize + ediff - usize;
tp[0] = -vp[0];
for (i = 1; i < vsize; i++)
tp[i] = ~vp[i];
for (i = vsize; i < size; i++)
tp[i] = ~(mp_limb_t) 0;
mpn_sub_1 (tp + size, up, usize, (mp_limb_t) 1);
rsize = size + usize;
}
normalize:
/* Full normalize. Optimize later. */
while (rsize != 0 && tp[rsize - 1] == 0)
{
rsize--;
exp--;
}
MPN_COPY (rp, tp, rsize);
}
done:
r->_mp_size = negate ? -rsize : rsize;
r->_mp_exp = exp;
TMP_FREE (marker);
}

View File

@ -0,0 +1,49 @@
/* mpf_sub_ui -- Subtract an unsigned integer from a float.
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mpf_sub_ui (mpf_ptr sum, mpf_srcptr u, unsigned long int v)
#else
mpf_sub_ui (sum, u, v)
mpf_ptr sum;
mpf_srcptr u;
unsigned long int v;
#endif
{
__mpf_struct vv;
mp_limb_t vl;
if (v == 0)
{
mpf_set (sum, u);
return;
}
vl = v;
vv._mp_size = 1;
vv._mp_d = &vl;
vv._mp_exp = 1;
mpf_sub (sum, u, &vv);
}

View File

@ -0,0 +1,75 @@
# Makefile for mpf/tests for GNU MP
srcdir = .
CC = gcc
TEST_LIBS = ../../libgmp.a
INCLUDES = -I../../mpn -I$(srcdir)/../..
CFLAGS = -g -O
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $(XCFLAGS) $<
TEST_SRCS = t-add.c t-sub.c t-conv.c t-sqrt.c t-muldiv.c t-dm2exp.c t-reuse.c ref.c
TEST_OBJS = t-add.o t-sub.o t-conv.o t-sqrt.o t-muldiv.o t-dm2exp.c reuse.o
TESTS = t-add t-sub t-conv t-sqrt t-muldiv t-dm2exp reuse
check: Makefile st-add st-sub st-conv st-sqrt st-muldiv st-dm2exp st-reuse
@echo "The tests passed."
st-add: t-add
./t-add
touch $@
st-sub: t-sub
./t-sub
touch $@
st-conv: t-conv
./t-conv
touch $@
st-sqrt: t-sqrt
./t-sqrt
touch $@
st-muldiv: t-muldiv
./t-muldiv
touch $@
st-dm2exp: t-dm2exp
./t-dm2exp
touch $@
st-reuse: reuse
./reuse
touch $@
H = $(srcdir)/../../gmp.h $(srcdir)/../../gmp-impl.h \
$(srcdir)/../../urandom.h ../../mpn/gmp-mparam.h
t-add: t-add.o ref.o $(TEST_LIBS)
$(CC) -o $@ $@.o ref.o $(TEST_LIBS) $(CFLAGS)
t-sub: t-sub.o ref.o $(TEST_LIBS)
$(CC) -o $@ $@.o ref.o $(TEST_LIBS) $(CFLAGS)
t-conv: t-conv.o $(TEST_LIBS)
$(CC) -o $@ $@.o $(TEST_LIBS) $(CFLAGS)
t-sqrt: t-sqrt.o $(TEST_LIBS)
$(CC) -o $@ $@.o $(TEST_LIBS) $(CFLAGS)
t-muldiv: t-muldiv.o $(TEST_LIBS)
$(CC) -o $@ $@.o $(TEST_LIBS) $(CFLAGS)
t-dm2exp: t-dm2exp.o $(TEST_LIBS)
$(CC) -o $@ $@.o $(TEST_LIBS) $(CFLAGS)
reuse: reuse.o $(TEST_LIBS)
$(CC) -o $@ $@.o $(TEST_LIBS) $(CFLAGS)
t-add.o: $(srcdir)/t-add.c
t-sub.o: $(srcdir)/t-sub.c
t-conv.o: $(srcdir)/t-conv.c
t-sqrt.o: $(srcdir)/t-sqrt.c
t-muldiv.o: $(srcdir)/t-muldiv.c
t-dm2exp.o: $(srcdir)/t-dm2exp.c
reuse.o: $(srcdir)/reuse.c
clean mostlyclean:
rm -f *.o st-* $(TESTS)
distclean maintainer-clean: clean
rm -f Makefile config.status
Makefile: $(srcdir)/Makefile.in
$(SHELL) ./config.status

View File

@ -0,0 +1,11 @@
# This file is a shell script that supplies the information necessary
# to tailor a template configure script into the configure script
# appropriate for this directory. For more information, check any
# existing configure script.
srctrigger=t-add.c
srcname="gmp/mpf/tests"
# per-host:
# per-target:

View File

@ -0,0 +1,203 @@
/* Reference floating point routines.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#if __STDC__
void ref_mpf_add (mpf_t, const mpf_t, const mpf_t);
void ref_mpf_sub (mpf_t, const mpf_t, const mpf_t);
#else
void ref_mpf_add ();
void ref_mpf_sub ();
#endif
void
#if __STDC__
ref_mpf_add (mpf_t w, const mpf_t u, const mpf_t v)
#else
ref_mpf_add (w, u, v)
mpf_t w;
const mpf_t u;
const mpf_t v;
#endif
{
mp_size_t hi, lo, size;
mp_ptr ut, vt, wt;
int neg;
mp_exp_t exp;
mp_limb_t cy;
TMP_DECL (mark);
TMP_MARK (mark);
if (SIZ (u) == 0)
{
size = ABSIZ (v);
wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB);
MPN_COPY (wt, PTR (v), size);
exp = EXP (v);
neg = SIZ (v) < 0;
goto done;
}
if (SIZ (v) == 0)
{
size = ABSIZ (u);
wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB);
MPN_COPY (wt, PTR (u), size);
exp = EXP (u);
neg = SIZ (u) < 0;
goto done;
}
if ((SIZ (u) ^ SIZ (v)) < 0)
{
mpf_t tmp;
SIZ (tmp) = -SIZ (v);
EXP (tmp) = EXP (v);
PTR (tmp) = PTR (v);
ref_mpf_sub (w, u, tmp);
return;
}
neg = SIZ (u) < 0;
/* Compute the significance of the hi and lo end of the result. */
hi = MAX (EXP (u), EXP (v));
lo = MIN (EXP (u) - ABSIZ (u), EXP (v) - ABSIZ (v));
size = hi - lo;
ut = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
vt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
wt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
MPN_ZERO (ut, size);
MPN_ZERO (vt, size);
{int off;
off = size + (EXP (u) - hi) - ABSIZ (u);
MPN_COPY (ut + off, PTR (u), ABSIZ (u));
off = size + (EXP (v) - hi) - ABSIZ (v);
MPN_COPY (vt + off, PTR (v), ABSIZ (v));
}
cy = mpn_add_n (wt, ut, vt, size);
wt[size] = cy;
size += cy;
exp = hi + cy;
done:
if (size > PREC (w))
{
wt += size - PREC (w);
size = PREC (w);
}
MPN_COPY (PTR (w), wt, size);
SIZ (w) = neg == 0 ? size : -size;
EXP (w) = exp;
TMP_FREE (mark);
}
void
#if __STDC__
ref_mpf_sub (mpf_t w, const mpf_t u, const mpf_t v)
#else
ref_mpf_sub (w, u, v)
mpf_t w;
const mpf_t u;
const mpf_t v;
#endif
{
mp_size_t hi, lo, size;
mp_ptr ut, vt, wt;
int neg;
mp_exp_t exp;
TMP_DECL (mark);
TMP_MARK (mark);
if (SIZ (u) == 0)
{
size = ABSIZ (v);
wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB);
MPN_COPY (wt, PTR (v), size);
exp = EXP (v);
neg = SIZ (v) > 0;
goto done;
}
if (SIZ (v) == 0)
{
size = ABSIZ (u);
wt = (mp_ptr) TMP_ALLOC (size * BYTES_PER_MP_LIMB);
MPN_COPY (wt, PTR (u), size);
exp = EXP (u);
neg = SIZ (u) < 0;
goto done;
}
if ((SIZ (u) ^ SIZ (v)) < 0)
{
mpf_t tmp;
SIZ (tmp) = -SIZ (v);
EXP (tmp) = EXP (v);
PTR (tmp) = PTR (v);
ref_mpf_add (w, u, tmp);
if (SIZ (u) < 0)
mpf_neg (w, w);
return;
}
neg = SIZ (u) < 0;
/* Compute the significance of the hi and lo end of the result. */
hi = MAX (EXP (u), EXP (v));
lo = MIN (EXP (u) - ABSIZ (u), EXP (v) - ABSIZ (v));
size = hi - lo;
ut = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
vt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
wt = (mp_ptr) TMP_ALLOC ((size + 1) * BYTES_PER_MP_LIMB);
MPN_ZERO (ut, size);
MPN_ZERO (vt, size);
{int off;
off = size + (EXP (u) - hi) - ABSIZ (u);
MPN_COPY (ut + off, PTR (u), ABSIZ (u));
off = size + (EXP (v) - hi) - ABSIZ (v);
MPN_COPY (vt + off, PTR (v), ABSIZ (v));
}
if (mpn_cmp (ut, vt, size) >= 0)
mpn_sub_n (wt, ut, vt, size);
else
{
mpn_sub_n (wt, vt, ut, size);
neg ^= 1;
}
exp = hi;
while (size != 0 && wt[size - 1] == 0)
{
size--;
exp--;
}
done:
if (size > PREC (w))
{
wt += size - PREC (w);
size = PREC (w);
}
MPN_COPY (PTR (w), wt, size);
SIZ (w) = neg == 0 ? size : -size;
EXP (w) = exp;
TMP_FREE (mark);
}

View File

@ -0,0 +1,186 @@
/* Test that routines allow reusing a source variable as destination. */
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "urandom.h"
#ifndef SIZE
#define SIZE 16
#endif
#ifndef EXPO
#define EXPO 32
#endif
#if __STDC__
typedef void (*dss_func) (mpf_ptr, mpf_srcptr, mpf_srcptr);
#else
typedef void (*dss_func) ();
#endif
dss_func dss_funcs[] =
{
mpf_div, mpf_add, mpf_mul, mpf_sub,
};
char *dss_func_names[] =
{
"mpf_div", "mpf_add", "mpf_mul", "mpf_sub",
};
#if __STDC__
typedef void (*dsi_func) (mpf_ptr, mpf_srcptr, unsigned long int);
#else
typedef void (*dsi_func) ();
#endif
dsi_func dsi_funcs[] =
{
mpf_div_ui, mpf_add_ui, mpf_mul_ui, mpf_sub_ui,
};
char *dsi_func_names[] =
{
"mpf_div_ui", "mpf_add_ui", "mpf_mul_ui", "mpf_sub_ui",
};
#if __STDC__
typedef void (*dis_func) (mpf_ptr, unsigned long int, mpf_srcptr);
#else
typedef void (*dis_func) ();
#endif
dis_func dis_funcs[] =
{
mpf_ui_div, mpf_ui_sub,
};
char *dis_func_names[] =
{
"mpf_ui_div", "mpf_ui_sub",
};
main (argc, argv)
int argc;
char **argv;
{
int i;
int pass, reps = 100000;
mpf_t in1, in2, out1;
unsigned long int in1i, in2i;
mpf_t res1, res2, res3;
mp_size_t bprec = 100;
if (argc > 1)
{
reps = strtol (argv[1], 0, 0);
if (argc > 2)
bprec = strtol (argv[2], 0, 0);
}
mpf_set_default_prec (bprec);
mpf_init (in1);
mpf_init (in2);
mpf_init (out1);
mpf_init (res1);
mpf_init (res2);
mpf_init (res3);
for (pass = 1; pass <= reps; pass++)
{
mpf_random2 (in1, urandom () % SIZE - SIZE/2, urandom () % EXPO);
mpf_random2 (in2, urandom () % SIZE - SIZE/2, urandom () % EXPO);
for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++)
{
/* Don't divide by 0. */
if (i == 0 && mpf_cmp_ui (in2, 0) == 0)
continue;
(dss_funcs[i]) (res1, in1, in2);
mpf_set (out1, in1);
(dss_funcs[i]) (out1, out1, in2);
mpf_set (res2, out1);
mpf_set (out1, in2);
(dss_funcs[i]) (out1, in1, out1);
mpf_set (res3, out1);
if (mpf_cmp (res1, res2) != 0)
dump_abort (dss_func_names[i], res1, res2);
if (mpf_cmp (res1, res3) != 0)
dump_abort (dss_func_names[i], res1, res3);
}
in2i = urandom ();
for (i = 0; i < sizeof (dsi_funcs) / sizeof (dsi_func); i++)
{
/* Don't divide by 0. */
if (i == 0 && in2i == 0)
continue;
(dsi_funcs[i]) (res1, in1, in2i);
mpf_set (out1, in1);
(dsi_funcs[i]) (out1, out1, in2i);
mpf_set (res2, out1);
if (mpf_cmp (res1, res2) != 0)
dump_abort (dsi_func_names[i], res1, res2);
}
in1i = urandom ();
for (i = 0; i < sizeof (dis_funcs) / sizeof (dis_func); i++)
{
/* Don't divide by 0. */
if (i == 0 && mpf_cmp_ui (in2, 0) == 0)
continue;
(dis_funcs[i]) (res1, in1i, in2);
mpf_set (out1, in2);
(dis_funcs[i]) (out1, in1i, in2);
mpf_set (res2, out1);
if (mpf_cmp (res1, res2) != 0)
dump_abort (dis_func_names[i], res1, res2);
}
}
exit (0);
}
dump_abort (name, res1, res2)
char *name;
mpf_t res1, res2;
{
printf ("failure in %s:", name);
oo (res1);
oo (res2);
abort ();
}
oo (x)
mpf_t x;
{
mp_size_t i;
printf (" exp = %ld\n", x->_mp_exp);
printf ("size = %d\n", x->_mp_size);
for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
printf ("%08lX ", x->_mp_d[i]);
printf ("\n");
mpf_dump (x);
}
#if 0
void mpf_div_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_mul_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_abs _PROTO ((mpf_ptr, mpf_srcptr));
void mpf_sqrt _PROTO ((mpf_ptr, mpf_srcptr));
void mpf_neg _PROTO ((mpf_ptr, mpf_srcptr));
#endif

View File

@ -0,0 +1,117 @@
/* Test mpf_add.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
The GNU MP 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "urandom.h"
#ifndef SIZE
#define SIZE 16
#endif
#if __STDC__
void ref_mpf_add (mpf_t, const mpf_t, const mpf_t);
void ref_mpf_sub (mpf_t, const mpf_t, const mpf_t);
#else
void ref_mpf_add ();
void ref_mpf_sub ();
#endif
main (argc, argv)
int argc;
char **argv;
{
mp_size_t size;
mp_exp_t exp;
int reps = 100000;
int i;
mpf_t u, v, w, wref;
mp_size_t bprec = 100;
mpf_t rerr, max_rerr, limit_rerr;
if (argc > 1)
{
reps = strtol (argv[1], 0, 0);
if (argc > 2)
bprec = strtol (argv[2], 0, 0);
}
mpf_set_default_prec (bprec);
mpf_init_set_ui (limit_rerr, 1);
mpf_div_2exp (limit_rerr, limit_rerr, bprec);
#if VERBOSE
mpf_dump (limit_rerr);
#endif
mpf_init (rerr);
mpf_init_set_ui (max_rerr, 0);
mpf_init (u);
mpf_init (v);
mpf_init (w);
mpf_init (wref);
for (i = 0; i < reps; i++)
{
size = urandom () % (2 * SIZE) - SIZE;
exp = urandom () % SIZE;
mpf_random2 (u, size, exp);
size = urandom () % (2 * SIZE) - SIZE;
exp = urandom () % SIZE;
mpf_random2 (v, size, exp);
mpf_add (w, u, v);
ref_mpf_add (wref, u, v);
mpf_reldiff (rerr, w, wref);
if (mpf_cmp (rerr, max_rerr) > 0)
{
mpf_set (max_rerr, rerr);
#if VERBOSE
mpf_dump (max_rerr);
#endif
if (mpf_cmp (rerr, limit_rerr) > 0)
{
printf ("ERROR after %d tests\n", i);
printf (" u = "); mpf_dump (u);
printf (" v = "); mpf_dump (v);
printf ("wref = "); mpf_dump (wref);
printf (" w = "); mpf_dump (w);
abort ();
}
}
}
exit (0);
}
oo (x)
mpf_t x;
{
mp_size_t i;
printf (" exp = %ld\n", x->_mp_exp);
printf ("size = %d\n", x->_mp_size);
for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
printf ("%08lX ", x->_mp_d[i]);
printf ("\n");
mpf_dump (x);
}

Some files were not shown because too many files have changed in this diff Show More