1 |
dashley |
25 |
// $Header: /cvsroot/esrg/sfesrg/esrgpcpj/unittest/ginttest.c,v 1.14 2002/05/16 04:21:50 dtashley Exp $
|
2 |
|
|
|
3 |
|
|
//--------------------------------------------------------------------------------
|
4 |
|
|
//Copyright 2002 David T. Ashley
|
5 |
|
|
//-------------------------------------------------------------------------------------------------
|
6 |
|
|
//This source code and any program in which it is compiled/used is provided under the GNU GENERAL
|
7 |
|
|
//PUBLIC LICENSE, Version 3, full license text below.
|
8 |
|
|
//-------------------------------------------------------------------------------------------------
|
9 |
|
|
// GNU GENERAL PUBLIC LICENSE
|
10 |
|
|
// Version 3, 29 June 2007
|
11 |
|
|
//
|
12 |
|
|
// Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
13 |
|
|
// Everyone is permitted to copy and distribute verbatim copies
|
14 |
|
|
// of this license document, but changing it is not allowed.
|
15 |
|
|
//
|
16 |
|
|
// Preamble
|
17 |
|
|
//
|
18 |
|
|
// The GNU General Public License is a free, copyleft license for
|
19 |
|
|
//software and other kinds of works.
|
20 |
|
|
//
|
21 |
|
|
// The licenses for most software and other practical works are designed
|
22 |
|
|
//to take away your freedom to share and change the works. By contrast,
|
23 |
|
|
//the GNU General Public License is intended to guarantee your freedom to
|
24 |
|
|
//share and change all versions of a program--to make sure it remains free
|
25 |
|
|
//software for all its users. We, the Free Software Foundation, use the
|
26 |
|
|
//GNU General Public License for most of our software; it applies also to
|
27 |
|
|
//any other work released this way by its authors. You can apply it to
|
28 |
|
|
//your programs, too.
|
29 |
|
|
//
|
30 |
|
|
// When we speak of free software, we are referring to freedom, not
|
31 |
|
|
//price. Our General Public Licenses are designed to make sure that you
|
32 |
|
|
//have the freedom to distribute copies of free software (and charge for
|
33 |
|
|
//them if you wish), that you receive source code or can get it if you
|
34 |
|
|
//want it, that you can change the software or use pieces of it in new
|
35 |
|
|
//free programs, and that you know you can do these things.
|
36 |
|
|
//
|
37 |
|
|
// To protect your rights, we need to prevent others from denying you
|
38 |
|
|
//these rights or asking you to surrender the rights. Therefore, you have
|
39 |
|
|
//certain responsibilities if you distribute copies of the software, or if
|
40 |
|
|
//you modify it: responsibilities to respect the freedom of others.
|
41 |
|
|
//
|
42 |
|
|
// For example, if you distribute copies of such a program, whether
|
43 |
|
|
//gratis or for a fee, you must pass on to the recipients the same
|
44 |
|
|
//freedoms that you received. You must make sure that they, too, receive
|
45 |
|
|
//or can get the source code. And you must show them these terms so they
|
46 |
|
|
//know their rights.
|
47 |
|
|
//
|
48 |
|
|
// Developers that use the GNU GPL protect your rights with two steps:
|
49 |
|
|
//(1) assert copyright on the software, and (2) offer you this License
|
50 |
|
|
//giving you legal permission to copy, distribute and/or modify it.
|
51 |
|
|
//
|
52 |
|
|
// For the developers' and authors' protection, the GPL clearly explains
|
53 |
|
|
//that there is no warranty for this free software. For both users' and
|
54 |
|
|
//authors' sake, the GPL requires that modified versions be marked as
|
55 |
|
|
//changed, so that their problems will not be attributed erroneously to
|
56 |
|
|
//authors of previous versions.
|
57 |
|
|
//
|
58 |
|
|
// Some devices are designed to deny users access to install or run
|
59 |
|
|
//modified versions of the software inside them, although the manufacturer
|
60 |
|
|
//can do so. This is fundamentally incompatible with the aim of
|
61 |
|
|
//protecting users' freedom to change the software. The systematic
|
62 |
|
|
//pattern of such abuse occurs in the area of products for individuals to
|
63 |
|
|
//use, which is precisely where it is most unacceptable. Therefore, we
|
64 |
|
|
//have designed this version of the GPL to prohibit the practice for those
|
65 |
|
|
//products. If such problems arise substantially in other domains, we
|
66 |
|
|
//stand ready to extend this provision to those domains in future versions
|
67 |
|
|
//of the GPL, as needed to protect the freedom of users.
|
68 |
|
|
//
|
69 |
|
|
// Finally, every program is threatened constantly by software patents.
|
70 |
|
|
//States should not allow patents to restrict development and use of
|
71 |
|
|
//software on general-purpose computers, but in those that do, we wish to
|
72 |
|
|
//avoid the special danger that patents applied to a free program could
|
73 |
|
|
//make it effectively proprietary. To prevent this, the GPL assures that
|
74 |
|
|
//patents cannot be used to render the program non-free.
|
75 |
|
|
//
|
76 |
|
|
// The precise terms and conditions for copying, distribution and
|
77 |
|
|
//modification follow.
|
78 |
|
|
//
|
79 |
|
|
// TERMS AND CONDITIONS
|
80 |
|
|
//
|
81 |
|
|
// 0. Definitions.
|
82 |
|
|
//
|
83 |
|
|
// "This License" refers to version 3 of the GNU General Public License.
|
84 |
|
|
//
|
85 |
|
|
// "Copyright" also means copyright-like laws that apply to other kinds of
|
86 |
|
|
//works, such as semiconductor masks.
|
87 |
|
|
//
|
88 |
|
|
// "The Program" refers to any copyrightable work licensed under this
|
89 |
|
|
//License. Each licensee is addressed as "you". "Licensees" and
|
90 |
|
|
//"recipients" may be individuals or organizations.
|
91 |
|
|
//
|
92 |
|
|
// To "modify" a work means to copy from or adapt all or part of the work
|
93 |
|
|
//in a fashion requiring copyright permission, other than the making of an
|
94 |
|
|
//exact copy. The resulting work is called a "modified version" of the
|
95 |
|
|
//earlier work or a work "based on" the earlier work.
|
96 |
|
|
//
|
97 |
|
|
// A "covered work" means either the unmodified Program or a work based
|
98 |
|
|
//on the Program.
|
99 |
|
|
//
|
100 |
|
|
// To "propagate" a work means to do anything with it that, without
|
101 |
|
|
//permission, would make you directly or secondarily liable for
|
102 |
|
|
//infringement under applicable copyright law, except executing it on a
|
103 |
|
|
//computer or modifying a private copy. Propagation includes copying,
|
104 |
|
|
//distribution (with or without modification), making available to the
|
105 |
|
|
//public, and in some countries other activities as well.
|
106 |
|
|
//
|
107 |
|
|
// To "convey" a work means any kind of propagation that enables other
|
108 |
|
|
//parties to make or receive copies. Mere interaction with a user through
|
109 |
|
|
//a computer network, with no transfer of a copy, is not conveying.
|
110 |
|
|
//
|
111 |
|
|
// An interactive user interface displays "Appropriate Legal Notices"
|
112 |
|
|
//to the extent that it includes a convenient and prominently visible
|
113 |
|
|
//feature that (1) displays an appropriate copyright notice, and (2)
|
114 |
|
|
//tells the user that there is no warranty for the work (except to the
|
115 |
|
|
//extent that warranties are provided), that licensees may convey the
|
116 |
|
|
//work under this License, and how to view a copy of this License. If
|
117 |
|
|
//the interface presents a list of user commands or options, such as a
|
118 |
|
|
//menu, a prominent item in the list meets this criterion.
|
119 |
|
|
//
|
120 |
|
|
// 1. Source Code.
|
121 |
|
|
//
|
122 |
|
|
// The "source code" for a work means the preferred form of the work
|
123 |
|
|
//for making modifications to it. "Object code" means any non-source
|
124 |
|
|
//form of a work.
|
125 |
|
|
//
|
126 |
|
|
// A "Standard Interface" means an interface that either is an official
|
127 |
|
|
//standard defined by a recognized standards body, or, in the case of
|
128 |
|
|
//interfaces specified for a particular programming language, one that
|
129 |
|
|
//is widely used among developers working in that language.
|
130 |
|
|
//
|
131 |
|
|
// The "System Libraries" of an executable work include anything, other
|
132 |
|
|
//than the work as a whole, that (a) is included in the normal form of
|
133 |
|
|
//packaging a Major Component, but which is not part of that Major
|
134 |
|
|
//Component, and (b) serves only to enable use of the work with that
|
135 |
|
|
//Major Component, or to implement a Standard Interface for which an
|
136 |
|
|
//implementation is available to the public in source code form. A
|
137 |
|
|
//"Major Component", in this context, means a major essential component
|
138 |
|
|
//(kernel, window system, and so on) of the specific operating system
|
139 |
|
|
//(if any) on which the executable work runs, or a compiler used to
|
140 |
|
|
//produce the work, or an object code interpreter used to run it.
|
141 |
|
|
//
|
142 |
|
|
// The "Corresponding Source" for a work in object code form means all
|
143 |
|
|
//the source code needed to generate, install, and (for an executable
|
144 |
|
|
//work) run the object code and to modify the work, including scripts to
|
145 |
|
|
//control those activities. However, it does not include the work's
|
146 |
|
|
//System Libraries, or general-purpose tools or generally available free
|
147 |
|
|
//programs which are used unmodified in performing those activities but
|
148 |
|
|
//which are not part of the work. For example, Corresponding Source
|
149 |
|
|
//includes interface definition files associated with source files for
|
150 |
|
|
//the work, and the source code for shared libraries and dynamically
|
151 |
|
|
//linked subprograms that the work is specifically designed to require,
|
152 |
|
|
//such as by intimate data communication or control flow between those
|
153 |
|
|
//subprograms and other parts of the work.
|
154 |
|
|
//
|
155 |
|
|
// The Corresponding Source need not include anything that users
|
156 |
|
|
//can regenerate automatically from other parts of the Corresponding
|
157 |
|
|
//Source.
|
158 |
|
|
//
|
159 |
|
|
// The Corresponding Source for a work in source code form is that
|
160 |
|
|
//same work.
|
161 |
|
|
//
|
162 |
|
|
// 2. Basic Permissions.
|
163 |
|
|
//
|
164 |
|
|
// All rights granted under this License are granted for the term of
|
165 |
|
|
//copyright on the Program, and are irrevocable provided the stated
|
166 |
|
|
//conditions are met. This License explicitly affirms your unlimited
|
167 |
|
|
//permission to run the unmodified Program. The output from running a
|
168 |
|
|
//covered work is covered by this License only if the output, given its
|
169 |
|
|
//content, constitutes a covered work. This License acknowledges your
|
170 |
|
|
//rights of fair use or other equivalent, as provided by copyright law.
|
171 |
|
|
//
|
172 |
|
|
// You may make, run and propagate covered works that you do not
|
173 |
|
|
//convey, without conditions so long as your license otherwise remains
|
174 |
|
|
//in force. You may convey covered works to others for the sole purpose
|
175 |
|
|
//of having them make modifications exclusively for you, or provide you
|
176 |
|
|
//with facilities for running those works, provided that you comply with
|
177 |
|
|
//the terms of this License in conveying all material for which you do
|
178 |
|
|
//not control copyright. Those thus making or running the covered works
|
179 |
|
|
//for you must do so exclusively on your behalf, under your direction
|
180 |
|
|
//and control, on terms that prohibit them from making any copies of
|
181 |
|
|
//your copyrighted material outside their relationship with you.
|
182 |
|
|
//
|
183 |
|
|
// Conveying under any other circumstances is permitted solely under
|
184 |
|
|
//the conditions stated below. Sublicensing is not allowed; section 10
|
185 |
|
|
//makes it unnecessary.
|
186 |
|
|
//
|
187 |
|
|
// 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
188 |
|
|
//
|
189 |
|
|
// No covered work shall be deemed part of an effective technological
|
190 |
|
|
//measure under any applicable law fulfilling obligations under article
|
191 |
|
|
//11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
192 |
|
|
//similar laws prohibiting or restricting circumvention of such
|
193 |
|
|
//measures.
|
194 |
|
|
//
|
195 |
|
|
// When you convey a covered work, you waive any legal power to forbid
|
196 |
|
|
//circumvention of technological measures to the extent such circumvention
|
197 |
|
|
//is effected by exercising rights under this License with respect to
|
198 |
|
|
//the covered work, and you disclaim any intention to limit operation or
|
199 |
|
|
//modification of the work as a means of enforcing, against the work's
|
200 |
|
|
//users, your or third parties' legal rights to forbid circumvention of
|
201 |
|
|
//technological measures.
|
202 |
|
|
//
|
203 |
|
|
// 4. Conveying Verbatim Copies.
|
204 |
|
|
//
|
205 |
|
|
// You may convey verbatim copies of the Program's source code as you
|
206 |
|
|
//receive it, in any medium, provided that you conspicuously and
|
207 |
|
|
//appropriately publish on each copy an appropriate copyright notice;
|
208 |
|
|
//keep intact all notices stating that this License and any
|
209 |
|
|
//non-permissive terms added in accord with section 7 apply to the code;
|
210 |
|
|
//keep intact all notices of the absence of any warranty; and give all
|
211 |
|
|
//recipients a copy of this License along with the Program.
|
212 |
|
|
//
|
213 |
|
|
// You may charge any price or no price for each copy that you convey,
|
214 |
|
|
//and you may offer support or warranty protection for a fee.
|
215 |
|
|
//
|
216 |
|
|
// 5. Conveying Modified Source Versions.
|
217 |
|
|
//
|
218 |
|
|
// You may convey a work based on the Program, or the modifications to
|
219 |
|
|
//produce it from the Program, in the form of source code under the
|
220 |
|
|
//terms of section 4, provided that you also meet all of these conditions:
|
221 |
|
|
//
|
222 |
|
|
// a) The work must carry prominent notices stating that you modified
|
223 |
|
|
// it, and giving a relevant date.
|
224 |
|
|
//
|
225 |
|
|
// b) The work must carry prominent notices stating that it is
|
226 |
|
|
// released under this License and any conditions added under section
|
227 |
|
|
// 7. This requirement modifies the requirement in section 4 to
|
228 |
|
|
// "keep intact all notices".
|
229 |
|
|
//
|
230 |
|
|
// c) You must license the entire work, as a whole, under this
|
231 |
|
|
// License to anyone who comes into possession of a copy. This
|
232 |
|
|
// License will therefore apply, along with any applicable section 7
|
233 |
|
|
// additional terms, to the whole of the work, and all its parts,
|
234 |
|
|
// regardless of how they are packaged. This License gives no
|
235 |
|
|
// permission to license the work in any other way, but it does not
|
236 |
|
|
// invalidate such permission if you have separately received it.
|
237 |
|
|
//
|
238 |
|
|
// d) If the work has interactive user interfaces, each must display
|
239 |
|
|
// Appropriate Legal Notices; however, if the Program has interactive
|
240 |
|
|
// interfaces that do not display Appropriate Legal Notices, your
|
241 |
|
|
// work need not make them do so.
|
242 |
|
|
//
|
243 |
|
|
// A compilation of a covered work with other separate and independent
|
244 |
|
|
//works, which are not by their nature extensions of the covered work,
|
245 |
|
|
//and which are not combined with it such as to form a larger program,
|
246 |
|
|
//in or on a volume of a storage or distribution medium, is called an
|
247 |
|
|
//"aggregate" if the compilation and its resulting copyright are not
|
248 |
|
|
//used to limit the access or legal rights of the compilation's users
|
249 |
|
|
//beyond what the individual works permit. Inclusion of a covered work
|
250 |
|
|
//in an aggregate does not cause this License to apply to the other
|
251 |
|
|
//parts of the aggregate.
|
252 |
|
|
//
|
253 |
|
|
// 6. Conveying Non-Source Forms.
|
254 |
|
|
//
|
255 |
|
|
// You may convey a covered work in object code form under the terms
|
256 |
|
|
//of sections 4 and 5, provided that you also convey the
|
257 |
|
|
//machine-readable Corresponding Source under the terms of this License,
|
258 |
|
|
//in one of these ways:
|
259 |
|
|
//
|
260 |
|
|
// a) Convey the object code in, or embodied in, a physical product
|
261 |
|
|
// (including a physical distribution medium), accompanied by the
|
262 |
|
|
// Corresponding Source fixed on a durable physical medium
|
263 |
|
|
// customarily used for software interchange.
|
264 |
|
|
//
|
265 |
|
|
// b) Convey the object code in, or embodied in, a physical product
|
266 |
|
|
// (including a physical distribution medium), accompanied by a
|
267 |
|
|
// written offer, valid for at least three years and valid for as
|
268 |
|
|
// long as you offer spare parts or customer support for that product
|
269 |
|
|
// model, to give anyone who possesses the object code either (1) a
|
270 |
|
|
// copy of the Corresponding Source for all the software in the
|
271 |
|
|
// product that is covered by this License, on a durable physical
|
272 |
|
|
// medium customarily used for software interchange, for a price no
|
273 |
|
|
// more than your reasonable cost of physically performing this
|
274 |
|
|
// conveying of source, or (2) access to copy the
|
275 |
|
|
// Corresponding Source from a network server at no charge.
|
276 |
|
|
//
|
277 |
|
|
// c) Convey individual copies of the object code with a copy of the
|
278 |
|
|
// written offer to provide the Corresponding Source. This
|
279 |
|
|
// alternative is allowed only occasionally and noncommercially, and
|
280 |
|
|
// only if you received the object code with such an offer, in accord
|
281 |
|
|
// with subsection 6b.
|
282 |
|
|
//
|
283 |
|
|
// d) Convey the object code by offering access from a designated
|
284 |
|
|
// place (gratis or for a charge), and offer equivalent access to the
|
285 |
|
|
// Corresponding Source in the same way through the same place at no
|
286 |
|
|
// further charge. You need not require recipients to copy the
|
287 |
|
|
// Corresponding Source along with the object code. If the place to
|
288 |
|
|
// copy the object code is a network server, the Corresponding Source
|
289 |
|
|
// may be on a different server (operated by you or a third party)
|
290 |
|
|
// that supports equivalent copying facilities, provided you maintain
|
291 |
|
|
// clear directions next to the object code saying where to find the
|
292 |
|
|
// Corresponding Source. Regardless of what server hosts the
|
293 |
|
|
// Corresponding Source, you remain obligated to ensure that it is
|
294 |
|
|
// available for as long as needed to satisfy these requirements.
|
295 |
|
|
//
|
296 |
|
|
// e) Convey the object code using peer-to-peer transmission, provided
|
297 |
|
|
// you inform other peers where the object code and Corresponding
|
298 |
|
|
// Source of the work are being offered to the general public at no
|
299 |
|
|
// charge under subsection 6d.
|
300 |
|
|
//
|
301 |
|
|
// A separable portion of the object code, whose source code is excluded
|
302 |
|
|
//from the Corresponding Source as a System Library, need not be
|
303 |
|
|
//included in conveying the object code work.
|
304 |
|
|
//
|
305 |
|
|
// A "User Product" is either (1) a "consumer product", which means any
|
306 |
|
|
//tangible personal property which is normally used for personal, family,
|
307 |
|
|
//or household purposes, or (2) anything designed or sold for incorporation
|
308 |
|
|
//into a dwelling. In determining whether a product is a consumer product,
|
309 |
|
|
//doubtful cases shall be resolved in favor of coverage. For a particular
|
310 |
|
|
//product received by a particular user, "normally used" refers to a
|
311 |
|
|
//typical or common use of that class of product, regardless of the status
|
312 |
|
|
//of the particular user or of the way in which the particular user
|
313 |
|
|
//actually uses, or expects or is expected to use, the product. A product
|
314 |
|
|
//is a consumer product regardless of whether the product has substantial
|
315 |
|
|
//commercial, industrial or non-consumer uses, unless such uses represent
|
316 |
|
|
//the only significant mode of use of the product.
|
317 |
|
|
//
|
318 |
|
|
// "Installation Information" for a User Product means any methods,
|
319 |
|
|
//procedures, authorization keys, or other information required to install
|
320 |
|
|
//and execute modified versions of a covered work in that User Product from
|
321 |
|
|
//a modified version of its Corresponding Source. The information must
|
322 |
|
|
//suffice to ensure that the continued functioning of the modified object
|
323 |
|
|
//code is in no case prevented or interfered with solely because
|
324 |
|
|
//modification has been made.
|
325 |
|
|
//
|
326 |
|
|
// If you convey an object code work under this section in, or with, or
|
327 |
|
|
//specifically for use in, a User Product, and the conveying occurs as
|
328 |
|
|
//part of a transaction in which the right of possession and use of the
|
329 |
|
|
//User Product is transferred to the recipient in perpetuity or for a
|
330 |
|
|
//fixed term (regardless of how the transaction is characterized), the
|
331 |
|
|
//Corresponding Source conveyed under this section must be accompanied
|
332 |
|
|
//by the Installation Information. But this requirement does not apply
|
333 |
|
|
//if neither you nor any third party retains the ability to install
|
334 |
|
|
//modified object code on the User Product (for example, the work has
|
335 |
|
|
//been installed in ROM).
|
336 |
|
|
//
|
337 |
|
|
// The requirement to provide Installation Information does not include a
|
338 |
|
|
//requirement to continue to provide support service, warranty, or updates
|
339 |
|
|
//for a work that has been modified or installed by the recipient, or for
|
340 |
|
|
//the User Product in which it has been modified or installed. Access to a
|
341 |
|
|
//network may be denied when the modification itself materially and
|
342 |
|
|
//adversely affects the operation of the network or violates the rules and
|
343 |
|
|
//protocols for communication across the network.
|
344 |
|
|
//
|
345 |
|
|
// Corresponding Source conveyed, and Installation Information provided,
|
346 |
|
|
//in accord with this section must be in a format that is publicly
|
347 |
|
|
//documented (and with an implementation available to the public in
|
348 |
|
|
//source code form), and must require no special password or key for
|
349 |
|
|
//unpacking, reading or copying.
|
350 |
|
|
//
|
351 |
|
|
// 7. Additional Terms.
|
352 |
|
|
//
|
353 |
|
|
// "Additional permissions" are terms that supplement the terms of this
|
354 |
|
|
//License by making exceptions from one or more of its conditions.
|
355 |
|
|
//Additional permissions that are applicable to the entire Program shall
|
356 |
|
|
//be treated as though they were included in this License, to the extent
|
357 |
|
|
//that they are valid under applicable law. If additional permissions
|
358 |
|
|
//apply only to part of the Program, that part may be used separately
|
359 |
|
|
//under those permissions, but the entire Program remains governed by
|
360 |
|
|
//this License without regard to the additional permissions.
|
361 |
|
|
//
|
362 |
|
|
// When you convey a copy of a covered work, you may at your option
|
363 |
|
|
//remove any additional permissions from that copy, or from any part of
|
364 |
|
|
//it. (Additional permissions may be written to require their own
|
365 |
|
|
//removal in certain cases when you modify the work.) You may place
|
366 |
|
|
//additional permissions on material, added by you to a covered work,
|
367 |
|
|
//for which you have or can give appropriate copyright permission.
|
368 |
|
|
//
|
369 |
|
|
// Notwithstanding any other provision of this License, for material you
|
370 |
|
|
//add to a covered work, you may (if authorized by the copyright holders of
|
371 |
|
|
//that material) supplement the terms of this License with terms:
|
372 |
|
|
//
|
373 |
|
|
// a) Disclaiming warranty or limiting liability differently from the
|
374 |
|
|
// terms of sections 15 and 16 of this License; or
|
375 |
|
|
//
|
376 |
|
|
// b) Requiring preservation of specified reasonable legal notices or
|
377 |
|
|
// author attributions in that material or in the Appropriate Legal
|
378 |
|
|
// Notices displayed by works containing it; or
|
379 |
|
|
//
|
380 |
|
|
// c) Prohibiting misrepresentation of the origin of that material, or
|
381 |
|
|
// requiring that modified versions of such material be marked in
|
382 |
|
|
// reasonable ways as different from the original version; or
|
383 |
|
|
//
|
384 |
|
|
// d) Limiting the use for publicity purposes of names of licensors or
|
385 |
|
|
// authors of the material; or
|
386 |
|
|
//
|
387 |
|
|
// e) Declining to grant rights under trademark law for use of some
|
388 |
|
|
// trade names, trademarks, or service marks; or
|
389 |
|
|
//
|
390 |
|
|
// f) Requiring indemnification of licensors and authors of that
|
391 |
|
|
// material by anyone who conveys the material (or modified versions of
|
392 |
|
|
// it) with contractual assumptions of liability to the recipient, for
|
393 |
|
|
// any liability that these contractual assumptions directly impose on
|
394 |
|
|
// those licensors and authors.
|
395 |
|
|
//
|
396 |
|
|
// All other non-permissive additional terms are considered "further
|
397 |
|
|
//restrictions" within the meaning of section 10. If the Program as you
|
398 |
|
|
//received it, or any part of it, contains a notice stating that it is
|
399 |
|
|
//governed by this License along with a term that is a further
|
400 |
|
|
//restriction, you may remove that term. If a license document contains
|
401 |
|
|
//a further restriction but permits relicensing or conveying under this
|
402 |
|
|
//License, you may add to a covered work material governed by the terms
|
403 |
|
|
//of that license document, provided that the further restriction does
|
404 |
|
|
//not survive such relicensing or conveying.
|
405 |
|
|
//
|
406 |
|
|
// If you add terms to a covered work in accord with this section, you
|
407 |
|
|
//must place, in the relevant source files, a statement of the
|
408 |
|
|
//additional terms that apply to those files, or a notice indicating
|
409 |
|
|
//where to find the applicable terms.
|
410 |
|
|
//
|
411 |
|
|
// Additional terms, permissive or non-permissive, may be stated in the
|
412 |
|
|
//form of a separately written license, or stated as exceptions;
|
413 |
|
|
//the above requirements apply either way.
|
414 |
|
|
//
|
415 |
|
|
// 8. Termination.
|
416 |
|
|
//
|
417 |
|
|
// You may not propagate or modify a covered work except as expressly
|
418 |
|
|
//provided under this License. Any attempt otherwise to propagate or
|
419 |
|
|
//modify it is void, and will automatically terminate your rights under
|
420 |
|
|
//this License (including any patent licenses granted under the third
|
421 |
|
|
//paragraph of section 11).
|
422 |
|
|
//
|
423 |
|
|
// However, if you cease all violation of this License, then your
|
424 |
|
|
//license from a particular copyright holder is reinstated (a)
|
425 |
|
|
//provisionally, unless and until the copyright holder explicitly and
|
426 |
|
|
//finally terminates your license, and (b) permanently, if the copyright
|
427 |
|
|
//holder fails to notify you of the violation by some reasonable means
|
428 |
|
|
//prior to 60 days after the cessation.
|
429 |
|
|
//
|
430 |
|
|
// Moreover, your license from a particular copyright holder is
|
431 |
|
|
//reinstated permanently if the copyright holder notifies you of the
|
432 |
|
|
//violation by some reasonable means, this is the first time you have
|
433 |
|
|
//received notice of violation of this License (for any work) from that
|
434 |
|
|
//copyright holder, and you cure the violation prior to 30 days after
|
435 |
|
|
//your receipt of the notice.
|
436 |
|
|
//
|
437 |
|
|
// Termination of your rights under this section does not terminate the
|
438 |
|
|
//licenses of parties who have received copies or rights from you under
|
439 |
|
|
//this License. If your rights have been terminated and not permanently
|
440 |
|
|
//reinstated, you do not qualify to receive new licenses for the same
|
441 |
|
|
//material under section 10.
|
442 |
|
|
//
|
443 |
|
|
// 9. Acceptance Not Required for Having Copies.
|
444 |
|
|
//
|
445 |
|
|
// You are not required to accept this License in order to receive or
|
446 |
|
|
//run a copy of the Program. Ancillary propagation of a covered work
|
447 |
|
|
//occurring solely as a consequence of using peer-to-peer transmission
|
448 |
|
|
//to receive a copy likewise does not require acceptance. However,
|
449 |
|
|
//nothing other than this License grants you permission to propagate or
|
450 |
|
|
//modify any covered work. These actions infringe copyright if you do
|
451 |
|
|
//not accept this License. Therefore, by modifying or propagating a
|
452 |
|
|
//covered work, you indicate your acceptance of this License to do so.
|
453 |
|
|
//
|
454 |
|
|
// 10. Automatic Licensing of Downstream Recipients.
|
455 |
|
|
//
|
456 |
|
|
// Each time you convey a covered work, the recipient automatically
|
457 |
|
|
//receives a license from the original licensors, to run, modify and
|
458 |
|
|
//propagate that work, subject to this License. You are not responsible
|
459 |
|
|
//for enforcing compliance by third parties with this License.
|
460 |
|
|
//
|
461 |
|
|
// An "entity transaction" is a transaction transferring control of an
|
462 |
|
|
//organization, or substantially all assets of one, or subdividing an
|
463 |
|
|
//organization, or merging organizations. If propagation of a covered
|
464 |
|
|
//work results from an entity transaction, each party to that
|
465 |
|
|
//transaction who receives a copy of the work also receives whatever
|
466 |
|
|
//licenses to the work the party's predecessor in interest had or could
|
467 |
|
|
//give under the previous paragraph, plus a right to possession of the
|
468 |
|
|
//Corresponding Source of the work from the predecessor in interest, if
|
469 |
|
|
//the predecessor has it or can get it with reasonable efforts.
|
470 |
|
|
//
|
471 |
|
|
// You may not impose any further restrictions on the exercise of the
|
472 |
|
|
//rights granted or affirmed under this License. For example, you may
|
473 |
|
|
//not impose a license fee, royalty, or other charge for exercise of
|
474 |
|
|
//rights granted under this License, and you may not initiate litigation
|
475 |
|
|
//(including a cross-claim or counterclaim in a lawsuit) alleging that
|
476 |
|
|
//any patent claim is infringed by making, using, selling, offering for
|
477 |
|
|
//sale, or importing the Program or any portion of it.
|
478 |
|
|
//
|
479 |
|
|
// 11. Patents.
|
480 |
|
|
//
|
481 |
|
|
// A "contributor" is a copyright holder who authorizes use under this
|
482 |
|
|
//License of the Program or a work on which the Program is based. The
|
483 |
|
|
//work thus licensed is called the contributor's "contributor version".
|
484 |
|
|
//
|
485 |
|
|
// A contributor's "essential patent claims" are all patent claims
|
486 |
|
|
//owned or controlled by the contributor, whether already acquired or
|
487 |
|
|
//hereafter acquired, that would be infringed by some manner, permitted
|
488 |
|
|
//by this License, of making, using, or selling its contributor version,
|
489 |
|
|
//but do not include claims that would be infringed only as a
|
490 |
|
|
//consequence of further modification of the contributor version. For
|
491 |
|
|
//purposes of this definition, "control" includes the right to grant
|
492 |
|
|
//patent sublicenses in a manner consistent with the requirements of
|
493 |
|
|
//this License.
|
494 |
|
|
//
|
495 |
|
|
// Each contributor grants you a non-exclusive, worldwide, royalty-free
|
496 |
|
|
//patent license under the contributor's essential patent claims, to
|
497 |
|
|
//make, use, sell, offer for sale, import and otherwise run, modify and
|
498 |
|
|
//propagate the contents of its contributor version.
|
499 |
|
|
//
|
500 |
|
|
// In the following three paragraphs, a "patent license" is any express
|
501 |
|
|
//agreement or commitment, however denominated, not to enforce a patent
|
502 |
|
|
//(such as an express permission to practice a patent or covenant not to
|
503 |
|
|
//sue for patent infringement). To "grant" such a patent license to a
|
504 |
|
|
//party means to make such an agreement or commitment not to enforce a
|
505 |
|
|
//patent against the party.
|
506 |
|
|
//
|
507 |
|
|
// If you convey a covered work, knowingly relying on a patent license,
|
508 |
|
|
//and the Corresponding Source of the work is not available for anyone
|
509 |
|
|
//to copy, free of charge and under the terms of this License, through a
|
510 |
|
|
//publicly available network server or other readily accessible means,
|
511 |
|
|
//then you must either (1) cause the Corresponding Source to be so
|
512 |
|
|
//available, or (2) arrange to deprive yourself of the benefit of the
|
513 |
|
|
//patent license for this particular work, or (3) arrange, in a manner
|
514 |
|
|
//consistent with the requirements of this License, to extend the patent
|
515 |
|
|
//license to downstream recipients. "Knowingly relying" means you have
|
516 |
|
|
//actual knowledge that, but for the patent license, your conveying the
|
517 |
|
|
//covered work in a country, or your recipient's use of the covered work
|
518 |
|
|
//in a country, would infringe one or more identifiable patents in that
|
519 |
|
|
//country that you have reason to believe are valid.
|
520 |
|
|
//
|
521 |
|
|
// If, pursuant to or in connection with a single transaction or
|
522 |
|
|
//arrangement, you convey, or propagate by procuring conveyance of, a
|
523 |
|
|
//covered work, and grant a patent license to some of the parties
|
524 |
|
|
//receiving the covered work authorizing them to use, propagate, modify
|
525 |
|
|
//or convey a specific copy of the covered work, then the patent license
|
526 |
|
|
//you grant is automatically extended to all recipients of the covered
|
527 |
|
|
//work and works based on it.
|
528 |
|
|
//
|
529 |
|
|
// A patent license is "discriminatory" if it does not include within
|
530 |
|
|
//the scope of its coverage, prohibits the exercise of, or is
|
531 |
|
|
//conditioned on the non-exercise of one or more of the rights that are
|
532 |
|
|
//specifically granted under this License. You may not convey a covered
|
533 |
|
|
//work if you are a party to an arrangement with a third party that is
|
534 |
|
|
//in the business of distributing software, under which you make payment
|
535 |
|
|
//to the third party based on the extent of your activity of conveying
|
536 |
|
|
//the work, and under which the third party grants, to any of the
|
537 |
|
|
//parties who would receive the covered work from you, a discriminatory
|
538 |
|
|
//patent license (a) in connection with copies of the covered work
|
539 |
|
|
//conveyed by you (or copies made from those copies), or (b) primarily
|
540 |
|
|
//for and in connection with specific products or compilations that
|
541 |
|
|
//contain the covered work, unless you entered into that arrangement,
|
542 |
|
|
//or that patent license was granted, prior to 28 March 2007.
|
543 |
|
|
//
|
544 |
|
|
// Nothing in this License shall be construed as excluding or limiting
|
545 |
|
|
//any implied license or other defenses to infringement that may
|
546 |
|
|
//otherwise be available to you under applicable patent law.
|
547 |
|
|
//
|
548 |
|
|
// 12. No Surrender of Others' Freedom.
|
549 |
|
|
//
|
550 |
|
|
// If conditions are imposed on you (whether by court order, agreement or
|
551 |
|
|
//otherwise) that contradict the conditions of this License, they do not
|
552 |
|
|
//excuse you from the conditions of this License. If you cannot convey a
|
553 |
|
|
//covered work so as to satisfy simultaneously your obligations under this
|
554 |
|
|
//License and any other pertinent obligations, then as a consequence you may
|
555 |
|
|
//not convey it at all. For example, if you agree to terms that obligate you
|
556 |
|
|
//to collect a royalty for further conveying from those to whom you convey
|
557 |
|
|
//the Program, the only way you could satisfy both those terms and this
|
558 |
|
|
//License would be to refrain entirely from conveying the Program.
|
559 |
|
|
//
|
560 |
|
|
// 13. Use with the GNU Affero General Public License.
|
561 |
|
|
//
|
562 |
|
|
// Notwithstanding any other provision of this License, you have
|
563 |
|
|
//permission to link or combine any covered work with a work licensed
|
564 |
|
|
//under version 3 of the GNU Affero General Public License into a single
|
565 |
|
|
//combined work, and to convey the resulting work. The terms of this
|
566 |
|
|
//License will continue to apply to the part which is the covered work,
|
567 |
|
|
//but the special requirements of the GNU Affero General Public License,
|
568 |
|
|
//section 13, concerning interaction through a network will apply to the
|
569 |
|
|
//combination as such.
|
570 |
|
|
//
|
571 |
|
|
// 14. Revised Versions of this License.
|
572 |
|
|
//
|
573 |
|
|
// The Free Software Foundation may publish revised and/or new versions of
|
574 |
|
|
//the GNU General Public License from time to time. Such new versions will
|
575 |
|
|
//be similar in spirit to the present version, but may differ in detail to
|
576 |
|
|
//address new problems or concerns.
|
577 |
|
|
//
|
578 |
|
|
// Each version is given a distinguishing version number. If the
|
579 |
|
|
//Program specifies that a certain numbered version of the GNU General
|
580 |
|
|
//Public License "or any later version" applies to it, you have the
|
581 |
|
|
//option of following the terms and conditions either of that numbered
|
582 |
|
|
//version or of any later version published by the Free Software
|
583 |
|
|
//Foundation. If the Program does not specify a version number of the
|
584 |
|
|
//GNU General Public License, you may choose any version ever published
|
585 |
|
|
//by the Free Software Foundation.
|
586 |
|
|
//
|
587 |
|
|
// If the Program specifies that a proxy can decide which future
|
588 |
|
|
//versions of the GNU General Public License can be used, that proxy's
|
589 |
|
|
//public statement of acceptance of a version permanently authorizes you
|
590 |
|
|
//to choose that version for the Program.
|
591 |
|
|
//
|
592 |
|
|
// Later license versions may give you additional or different
|
593 |
|
|
//permissions. However, no additional obligations are imposed on any
|
594 |
|
|
//author or copyright holder as a result of your choosing to follow a
|
595 |
|
|
//later version.
|
596 |
|
|
//
|
597 |
|
|
// 15. Disclaimer of Warranty.
|
598 |
|
|
//
|
599 |
|
|
// THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
600 |
|
|
//APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
601 |
|
|
//HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
602 |
|
|
//OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
603 |
|
|
//THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
604 |
|
|
//PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
605 |
|
|
//IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
606 |
|
|
//ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
607 |
|
|
//
|
608 |
|
|
// 16. Limitation of Liability.
|
609 |
|
|
//
|
610 |
|
|
// IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
611 |
|
|
//WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
612 |
|
|
//THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
613 |
|
|
//GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
614 |
|
|
//USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
615 |
|
|
//DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
616 |
|
|
//PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
617 |
|
|
//EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
618 |
|
|
//SUCH DAMAGES.
|
619 |
|
|
//
|
620 |
|
|
// 17. Interpretation of Sections 15 and 16.
|
621 |
|
|
//
|
622 |
|
|
// If the disclaimer of warranty and limitation of liability provided
|
623 |
|
|
//above cannot be given local legal effect according to their terms,
|
624 |
|
|
//reviewing courts shall apply local law that most closely approximates
|
625 |
|
|
//an absolute waiver of all civil liability in connection with the
|
626 |
|
|
//Program, unless a warranty or assumption of liability accompanies a
|
627 |
|
|
//copy of the Program in return for a fee.
|
628 |
|
|
//
|
629 |
|
|
// END OF TERMS AND CONDITIONS
|
630 |
|
|
//
|
631 |
|
|
// How to Apply These Terms to Your New Programs
|
632 |
|
|
//
|
633 |
|
|
// If you develop a new program, and you want it to be of the greatest
|
634 |
|
|
//possible use to the public, the best way to achieve this is to make it
|
635 |
|
|
//free software which everyone can redistribute and change under these terms.
|
636 |
|
|
//
|
637 |
|
|
// To do so, attach the following notices to the program. It is safest
|
638 |
|
|
//to attach them to the start of each source file to most effectively
|
639 |
|
|
//state the exclusion of warranty; and each file should have at least
|
640 |
|
|
//the "copyright" line and a pointer to where the full notice is found.
|
641 |
|
|
//
|
642 |
|
|
// <one line to give the program's name and a brief idea of what it does.>
|
643 |
|
|
// Copyright (C) <year> <name of author>
|
644 |
|
|
//
|
645 |
|
|
// This program is free software: you can redistribute it and/or modify
|
646 |
|
|
// it under the terms of the GNU General Public License as published by
|
647 |
|
|
// the Free Software Foundation, either version 3 of the License, or
|
648 |
|
|
// (at your option) any later version.
|
649 |
|
|
//
|
650 |
|
|
// This program is distributed in the hope that it will be useful,
|
651 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
652 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
653 |
|
|
// GNU General Public License for more details.
|
654 |
|
|
//
|
655 |
|
|
// You should have received a copy of the GNU General Public License
|
656 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
657 |
|
|
//
|
658 |
|
|
//Also add information on how to contact you by electronic and paper mail.
|
659 |
|
|
//
|
660 |
|
|
// If the program does terminal interaction, make it output a short
|
661 |
|
|
//notice like this when it starts in an interactive mode:
|
662 |
|
|
//
|
663 |
|
|
// <program> Copyright (C) <year> <name of author>
|
664 |
|
|
// This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
665 |
|
|
// This is free software, and you are welcome to redistribute it
|
666 |
|
|
// under certain conditions; type `show c' for details.
|
667 |
|
|
//
|
668 |
|
|
//The hypothetical commands `show w' and `show c' should show the appropriate
|
669 |
|
|
//parts of the General Public License. Of course, your program's commands
|
670 |
|
|
//might be different; for a GUI interface, you would use an "about box".
|
671 |
|
|
//
|
672 |
|
|
// You should also get your employer (if you work as a programmer) or school,
|
673 |
|
|
//if any, to sign a "copyright disclaimer" for the program, if necessary.
|
674 |
|
|
//For more information on this, and how to apply and follow the GNU GPL, see
|
675 |
|
|
//<http://www.gnu.org/licenses/>.
|
676 |
|
|
//
|
677 |
|
|
// The GNU General Public License does not permit incorporating your program
|
678 |
|
|
//into proprietary programs. If your program is a subroutine library, you
|
679 |
|
|
//may consider it more useful to permit linking proprietary applications with
|
680 |
|
|
//the library. If this is what you want to do, use the GNU Lesser General
|
681 |
|
|
//Public License instead of this License. But first, please read
|
682 |
|
|
//<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
683 |
|
|
//-------------------------------------------------------------------------------------------------
|
684 |
|
|
//--------------------------------------------------------------------------------
|
685 |
|
|
#define MODULE_GINTTEST
|
686 |
|
|
|
687 |
|
|
#include <malloc.h>
|
688 |
|
|
#include <process.h>
|
689 |
|
|
#include <stdio.h>
|
690 |
|
|
#include <string.h>
|
691 |
|
|
#include <time.h>
|
692 |
|
|
|
693 |
|
|
#include "bstrfunc.h"
|
694 |
|
|
#include "fcmiof.h"
|
695 |
|
|
#include "ginttest.h"
|
696 |
|
|
#include "gmp_ints.h"
|
697 |
|
|
|
698 |
|
|
|
699 |
|
|
int GINTTEST_data_sizes_wrong_test(void)
|
700 |
|
|
{
|
701 |
|
|
printf("Testing the GMP_INTS_data_sizes_are_wrong() function.\n");
|
702 |
|
|
|
703 |
|
|
FCMIOF_hline();
|
704 |
|
|
|
705 |
|
|
if (GMP_INTS_data_sizes_are_wrong())
|
706 |
|
|
return(1);
|
707 |
|
|
else
|
708 |
|
|
return(0);
|
709 |
|
|
}
|
710 |
|
|
|
711 |
|
|
|
712 |
|
|
int GINTTEST_mpn_add_1_test(void)
|
713 |
|
|
{
|
714 |
|
|
int rv=0;
|
715 |
|
|
int i, j;
|
716 |
|
|
int carry_out;
|
717 |
|
|
|
718 |
|
|
GMP_INTS_limb_t inlimbs[5];
|
719 |
|
|
GMP_INTS_limb_t outlimbs[5];
|
720 |
|
|
|
721 |
|
|
//These are the test vectors for the
|
722 |
|
|
//add_1 function.
|
723 |
|
|
static struct add_1_test_vector_struct
|
724 |
|
|
{
|
725 |
|
|
char *desc;
|
726 |
|
|
//The purpose of the test vector, what is
|
727 |
|
|
//is trying to show.
|
728 |
|
|
//The starting values of the "input" of up to
|
729 |
|
|
//5 limbs.
|
730 |
|
|
GMP_INTS_limb_t sin4;
|
731 |
|
|
GMP_INTS_limb_t sin3;
|
732 |
|
|
GMP_INTS_limb_t sin2;
|
733 |
|
|
GMP_INTS_limb_t sin1;
|
734 |
|
|
GMP_INTS_limb_t sin0;
|
735 |
|
|
//The fill value for the output struct.
|
736 |
|
|
//It is filled to avoid undetected corruption.
|
737 |
|
|
GMP_INTS_limb_t ofillval;
|
738 |
|
|
int size; //The size of the array of limbs to
|
739 |
|
|
//be added to.
|
740 |
|
|
GMP_INTS_limb_t addval;
|
741 |
|
|
//The value of the single limb to be added.
|
742 |
|
|
//The required values for the output array.
|
743 |
|
|
GMP_INTS_limb_t oreq4;
|
744 |
|
|
GMP_INTS_limb_t oreq3;
|
745 |
|
|
GMP_INTS_limb_t oreq2;
|
746 |
|
|
GMP_INTS_limb_t oreq1;
|
747 |
|
|
GMP_INTS_limb_t oreq0;
|
748 |
|
|
//The required carry out.
|
749 |
|
|
int reqcarry;
|
750 |
|
|
} tvs[] =
|
751 |
|
|
{
|
752 |
|
|
{
|
753 |
|
|
"Zero added to zero in one limb must be zero.",
|
754 |
|
|
0, 0, 0, 0, 0,
|
755 |
|
|
0xA55AA55A,
|
756 |
|
|
1,
|
757 |
|
|
0,
|
758 |
|
|
0xA55AA55A,0xA55AA55A,0xA55AA55A,0xA55AA55A,0,
|
759 |
|
|
0
|
760 |
|
|
},
|
761 |
|
|
{
|
762 |
|
|
"Zero added to zero in two limbs must be zero.",
|
763 |
|
|
0, 0, 0, 0, 0,
|
764 |
|
|
0xA55AA55A,
|
765 |
|
|
2,
|
766 |
|
|
0,
|
767 |
|
|
0xA55AA55A,0xA55AA55A,0xA55AA55A,0,0,
|
768 |
|
|
0
|
769 |
|
|
},
|
770 |
|
|
{
|
771 |
|
|
"Zero added to zero in three limbs must be zero.",
|
772 |
|
|
0, 0, 0, 0, 0,
|
773 |
|
|
0xA55AA55A,
|
774 |
|
|
3,
|
775 |
|
|
0,
|
776 |
|
|
0xA55AA55A,0xA55AA55A,0,0,0,
|
777 |
|
|
0
|
778 |
|
|
},
|
779 |
|
|
{
|
780 |
|
|
"Checking carry out of single-limb result.",
|
781 |
|
|
0, 0, 0, 0, 3,
|
782 |
|
|
0xA55AA55A,
|
783 |
|
|
1,
|
784 |
|
|
0xFFFFFFFD,
|
785 |
|
|
0xA55AA55A,0xA55AA55A,0xA55AA55A,0xA55AA55A,0,
|
786 |
|
|
1
|
787 |
|
|
},
|
788 |
|
|
{
|
789 |
|
|
"Checking rollover out of single-limb result.",
|
790 |
|
|
0, 0, 0, 0, 5,
|
791 |
|
|
0xA55AA55A,
|
792 |
|
|
1,
|
793 |
|
|
0xFFFFFFFD,
|
794 |
|
|
0xA55AA55A,0xA55AA55A,0xA55AA55A,0xA55AA55A,2,
|
795 |
|
|
1
|
796 |
|
|
},
|
797 |
|
|
{
|
798 |
|
|
"Checking three limb roll to zero.",
|
799 |
|
|
0, 0, 0xFFFFFFFF, 0xFFFFFFFF, 3,
|
800 |
|
|
0xA55AA55A,
|
801 |
|
|
3,
|
802 |
|
|
0xFFFFFFFD,
|
803 |
|
|
0xA55AA55A,0xA55AA55A,0,0,0,
|
804 |
|
|
1
|
805 |
|
|
},
|
806 |
|
|
{
|
807 |
|
|
"Checking three limb failure to roll.",
|
808 |
|
|
0, 0, 0xFFFFFFFF, 0xFFFFFFFF, 2,
|
809 |
|
|
0xA55AA55A,
|
810 |
|
|
3,
|
811 |
|
|
0xFFFFFFFD,
|
812 |
|
|
0xA55AA55A,0xA55AA55A,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
813 |
|
|
0
|
814 |
|
|
},
|
815 |
|
|
};
|
816 |
|
|
|
817 |
|
|
//For each test vector.
|
818 |
|
|
for(i=0; i<sizeof(tvs)/sizeof(tvs[0]); i++)
|
819 |
|
|
{
|
820 |
|
|
struct add_1_test_vector_struct *p;
|
821 |
|
|
p = &(tvs[i]);
|
822 |
|
|
|
823 |
|
|
printf("Executing GMP_INTS_mpn_add_1() test vector: %d\n", i);
|
824 |
|
|
printf("Test vector purpose:\n %s\n", p->desc);
|
825 |
|
|
|
826 |
|
|
//Set up for the test vector.
|
827 |
|
|
inlimbs[4] = p->sin4;
|
828 |
|
|
inlimbs[3] = p->sin3;
|
829 |
|
|
inlimbs[2] = p->sin2;
|
830 |
|
|
inlimbs[1] = p->sin1;
|
831 |
|
|
inlimbs[0] = p->sin0;
|
832 |
|
|
for (j=0; j<5; j++)
|
833 |
|
|
{
|
834 |
|
|
outlimbs[j] = p->ofillval;
|
835 |
|
|
}
|
836 |
|
|
|
837 |
|
|
carry_out = GMP_INTS_mpn_add_1(outlimbs,
|
838 |
|
|
inlimbs,
|
839 |
|
|
p->size,
|
840 |
|
|
p->addval);
|
841 |
|
|
|
842 |
|
|
if (carry_out != p->reqcarry)
|
843 |
|
|
{
|
844 |
|
|
rv = 1;
|
845 |
|
|
printf(" Carry FAILED.\n");
|
846 |
|
|
}
|
847 |
|
|
if (inlimbs[4] != p->sin4)
|
848 |
|
|
{
|
849 |
|
|
rv = 1;
|
850 |
|
|
printf(" inlimbs[4] FAILED.\n");
|
851 |
|
|
}
|
852 |
|
|
if (inlimbs[3] != p->sin3)
|
853 |
|
|
{
|
854 |
|
|
rv = 1;
|
855 |
|
|
printf(" inlimbs[3] FAILED.\n");
|
856 |
|
|
}
|
857 |
|
|
if (inlimbs[2] != p->sin2)
|
858 |
|
|
{
|
859 |
|
|
rv = 1;
|
860 |
|
|
printf(" inlimbs[2] FAILED.\n");
|
861 |
|
|
}
|
862 |
|
|
if (inlimbs[1] != p->sin1)
|
863 |
|
|
{
|
864 |
|
|
rv = 1;
|
865 |
|
|
printf(" inlimbs[1] FAILED.\n");
|
866 |
|
|
}
|
867 |
|
|
if (inlimbs[0] != p->sin0)
|
868 |
|
|
{
|
869 |
|
|
rv = 1;
|
870 |
|
|
printf(" inlimbs[0] FAILED.\n");
|
871 |
|
|
}
|
872 |
|
|
if (outlimbs[4] != p->oreq4)
|
873 |
|
|
{
|
874 |
|
|
rv = 1;
|
875 |
|
|
printf(" outlimbs[4] FAILED.\n");
|
876 |
|
|
}
|
877 |
|
|
if (outlimbs[3] != p->oreq3)
|
878 |
|
|
{
|
879 |
|
|
rv = 1;
|
880 |
|
|
printf(" outlimbs[3] FAILED.\n");
|
881 |
|
|
}
|
882 |
|
|
if (outlimbs[2] != p->oreq2)
|
883 |
|
|
{
|
884 |
|
|
rv = 1;
|
885 |
|
|
printf(" outlimbs[2] FAILED.\n");
|
886 |
|
|
}
|
887 |
|
|
if (outlimbs[1] != p->oreq1)
|
888 |
|
|
{
|
889 |
|
|
rv = 1;
|
890 |
|
|
printf(" outlimbs[1] FAILED.\n");
|
891 |
|
|
}
|
892 |
|
|
if (outlimbs[0] != p->oreq0)
|
893 |
|
|
{
|
894 |
|
|
rv = 1;
|
895 |
|
|
printf(" outlimbs[0] FAILED.\n");
|
896 |
|
|
}
|
897 |
|
|
|
898 |
|
|
FCMIOF_hline();
|
899 |
|
|
}
|
900 |
|
|
|
901 |
|
|
return(rv);
|
902 |
|
|
}
|
903 |
|
|
|
904 |
|
|
|
905 |
|
|
int GINTTEST_mpn_sub_1_test(void)
|
906 |
|
|
{
|
907 |
|
|
int rv=0;
|
908 |
|
|
int i, j;
|
909 |
|
|
int carry_out;
|
910 |
|
|
|
911 |
|
|
GMP_INTS_limb_t inlimbs[5];
|
912 |
|
|
GMP_INTS_limb_t outlimbs[5];
|
913 |
|
|
|
914 |
|
|
//These are the test vectors for the
|
915 |
|
|
//add_1 function.
|
916 |
|
|
static struct sub_1_test_vector_struct
|
917 |
|
|
{
|
918 |
|
|
char *desc;
|
919 |
|
|
//The purpose of the test vector, what is
|
920 |
|
|
//is trying to show.
|
921 |
|
|
//The starting values of the "input" of up to
|
922 |
|
|
//5 limbs.
|
923 |
|
|
GMP_INTS_limb_t sin4;
|
924 |
|
|
GMP_INTS_limb_t sin3;
|
925 |
|
|
GMP_INTS_limb_t sin2;
|
926 |
|
|
GMP_INTS_limb_t sin1;
|
927 |
|
|
GMP_INTS_limb_t sin0;
|
928 |
|
|
//The fill value for the output struct.
|
929 |
|
|
//It is filled to avoid undetected corruption.
|
930 |
|
|
GMP_INTS_limb_t ofillval;
|
931 |
|
|
int size; //The size of the array of limbs to
|
932 |
|
|
//be added to.
|
933 |
|
|
GMP_INTS_limb_t subval;
|
934 |
|
|
//The value of the single limb to be subtracted.
|
935 |
|
|
//The required values for the output array.
|
936 |
|
|
GMP_INTS_limb_t oreq4;
|
937 |
|
|
GMP_INTS_limb_t oreq3;
|
938 |
|
|
GMP_INTS_limb_t oreq2;
|
939 |
|
|
GMP_INTS_limb_t oreq1;
|
940 |
|
|
GMP_INTS_limb_t oreq0;
|
941 |
|
|
//The required borrow out.
|
942 |
|
|
int reqborrow;
|
943 |
|
|
} tvs[] =
|
944 |
|
|
{
|
945 |
|
|
{
|
946 |
|
|
"Zero subracted from zero in one limb must be zero.",
|
947 |
|
|
0, 0, 0, 0, 0,
|
948 |
|
|
0xA55AA55A,
|
949 |
|
|
1,
|
950 |
|
|
0,
|
951 |
|
|
0xA55AA55A,0xA55AA55A,0xA55AA55A,0xA55AA55A,0,
|
952 |
|
|
0
|
953 |
|
|
},
|
954 |
|
|
{
|
955 |
|
|
"Zero subtracted from zero in two limbs must be zero.",
|
956 |
|
|
0, 0, 0, 0, 0,
|
957 |
|
|
0xA55AA55A,
|
958 |
|
|
2,
|
959 |
|
|
0,
|
960 |
|
|
0xA55AA55A,0xA55AA55A,0xA55AA55A,0,0,
|
961 |
|
|
0
|
962 |
|
|
},
|
963 |
|
|
{
|
964 |
|
|
"Zero subtracted from zero in three limbs must be zero.",
|
965 |
|
|
0, 0, 0, 0, 0,
|
966 |
|
|
0xA55AA55A,
|
967 |
|
|
3,
|
968 |
|
|
0,
|
969 |
|
|
0xA55AA55A,0xA55AA55A,0,0,0,
|
970 |
|
|
0
|
971 |
|
|
},
|
972 |
|
|
{
|
973 |
|
|
"Checking borrow out of single-limb result.",
|
974 |
|
|
0, 0, 0, 0, 3,
|
975 |
|
|
0xA55AA55A,
|
976 |
|
|
1,
|
977 |
|
|
4,
|
978 |
|
|
0xA55AA55A,0xA55AA55A,0xA55AA55A,0xA55AA55A,0xFFFFFFFF,
|
979 |
|
|
1
|
980 |
|
|
},
|
981 |
|
|
{
|
982 |
|
|
"Checking three limb roll to -1.",
|
983 |
|
|
0, 0, 0, 0, 12,
|
984 |
|
|
0xA55AA55A,
|
985 |
|
|
3,
|
986 |
|
|
13,
|
987 |
|
|
0xA55AA55A,0xA55AA55A,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
988 |
|
|
1
|
989 |
|
|
},
|
990 |
|
|
{
|
991 |
|
|
"Checking three limb failure to roll backwards.",
|
992 |
|
|
0, 0, 0, 0, 2,
|
993 |
|
|
0xA55AA55A,
|
994 |
|
|
3,
|
995 |
|
|
2,
|
996 |
|
|
0xA55AA55A,0xA55AA55A,0,0,0,
|
997 |
|
|
0
|
998 |
|
|
},
|
999 |
|
|
};
|
1000 |
|
|
|
1001 |
|
|
//For each test vector.
|
1002 |
|
|
for(i=0; i<sizeof(tvs)/sizeof(tvs[0]); i++)
|
1003 |
|
|
{
|
1004 |
|
|
struct sub_1_test_vector_struct *p;
|
1005 |
|
|
p = &(tvs[i]);
|
1006 |
|
|
|
1007 |
|
|
printf("Executing GMP_INTS_mpn_sub_1() test vector: %d\n", i);
|
1008 |
|
|
printf("Test vector purpose:\n %s\n", p->desc);
|
1009 |
|
|
|
1010 |
|
|
//Set up for the test vector.
|
1011 |
|
|
inlimbs[4] = p->sin4;
|
1012 |
|
|
inlimbs[3] = p->sin3;
|
1013 |
|
|
inlimbs[2] = p->sin2;
|
1014 |
|
|
inlimbs[1] = p->sin1;
|
1015 |
|
|
inlimbs[0] = p->sin0;
|
1016 |
|
|
for (j=0; j<5; j++)
|
1017 |
|
|
{
|
1018 |
|
|
outlimbs[j] = p->ofillval;
|
1019 |
|
|
}
|
1020 |
|
|
|
1021 |
|
|
carry_out = GMP_INTS_mpn_sub_1(outlimbs,
|
1022 |
|
|
inlimbs,
|
1023 |
|
|
p->size,
|
1024 |
|
|
p->subval);
|
1025 |
|
|
|
1026 |
|
|
if (carry_out != p->reqborrow)
|
1027 |
|
|
{
|
1028 |
|
|
rv = 1;
|
1029 |
|
|
printf(" Borrow FAILED.\n");
|
1030 |
|
|
}
|
1031 |
|
|
if (inlimbs[4] != p->sin4)
|
1032 |
|
|
{
|
1033 |
|
|
rv = 1;
|
1034 |
|
|
printf(" inlimbs[4] FAILED.\n");
|
1035 |
|
|
}
|
1036 |
|
|
if (inlimbs[3] != p->sin3)
|
1037 |
|
|
{
|
1038 |
|
|
rv = 1;
|
1039 |
|
|
printf(" inlimbs[3] FAILED.\n");
|
1040 |
|
|
}
|
1041 |
|
|
if (inlimbs[2] != p->sin2)
|
1042 |
|
|
{
|
1043 |
|
|
rv = 1;
|
1044 |
|
|
printf(" inlimbs[2] FAILED.\n");
|
1045 |
|
|
}
|
1046 |
|
|
if (inlimbs[1] != p->sin1)
|
1047 |
|
|
{
|
1048 |
|
|
rv = 1;
|
1049 |
|
|
printf(" inlimbs[1] FAILED.\n");
|
1050 |
|
|
}
|
1051 |
|
|
if (inlimbs[0] != p->sin0)
|
1052 |
|
|
{
|
1053 |
|
|
rv = 1;
|
1054 |
|
|
printf(" inlimbs[0] FAILED.\n");
|
1055 |
|
|
}
|
1056 |
|
|
if (outlimbs[4] != p->oreq4)
|
1057 |
|
|
{
|
1058 |
|
|
rv = 1;
|
1059 |
|
|
printf(" outlimbs[4] FAILED.\n");
|
1060 |
|
|
}
|
1061 |
|
|
if (outlimbs[3] != p->oreq3)
|
1062 |
|
|
{
|
1063 |
|
|
rv = 1;
|
1064 |
|
|
printf(" outlimbs[3] FAILED.\n");
|
1065 |
|
|
}
|
1066 |
|
|
if (outlimbs[2] != p->oreq2)
|
1067 |
|
|
{
|
1068 |
|
|
rv = 1;
|
1069 |
|
|
printf(" outlimbs[2] FAILED.\n");
|
1070 |
|
|
}
|
1071 |
|
|
if (outlimbs[1] != p->oreq1)
|
1072 |
|
|
{
|
1073 |
|
|
rv = 1;
|
1074 |
|
|
printf(" outlimbs[1] FAILED.\n");
|
1075 |
|
|
}
|
1076 |
|
|
if (outlimbs[0] != p->oreq0)
|
1077 |
|
|
{
|
1078 |
|
|
rv = 1;
|
1079 |
|
|
printf(" outlimbs[0] FAILED.\n");
|
1080 |
|
|
}
|
1081 |
|
|
|
1082 |
|
|
FCMIOF_hline();
|
1083 |
|
|
}
|
1084 |
|
|
|
1085 |
|
|
return(rv);
|
1086 |
|
|
}
|
1087 |
|
|
|
1088 |
|
|
|
1089 |
|
|
int GINTTEST_mpn_mul_1_test(void)
|
1090 |
|
|
{
|
1091 |
|
|
int rv=0;
|
1092 |
|
|
int i, j;
|
1093 |
|
|
GMP_INTS_limb_t carry_out;
|
1094 |
|
|
|
1095 |
|
|
GMP_INTS_limb_t inlimbs[5];
|
1096 |
|
|
GMP_INTS_limb_t outlimbs[5];
|
1097 |
|
|
|
1098 |
|
|
//These are the test vectors for the
|
1099 |
|
|
//mul_1 function.
|
1100 |
|
|
static struct mul_1_test_vector_struct
|
1101 |
|
|
{
|
1102 |
|
|
char *desc;
|
1103 |
|
|
//The purpose of the test vector, what is
|
1104 |
|
|
//is trying to show.
|
1105 |
|
|
//The starting values of the "input" of up to
|
1106 |
|
|
//5 limbs.
|
1107 |
|
|
GMP_INTS_limb_t sin4;
|
1108 |
|
|
GMP_INTS_limb_t sin3;
|
1109 |
|
|
GMP_INTS_limb_t sin2;
|
1110 |
|
|
GMP_INTS_limb_t sin1;
|
1111 |
|
|
GMP_INTS_limb_t sin0;
|
1112 |
|
|
//The fill value for the output struct.
|
1113 |
|
|
//It is filled to avoid undetected corruption.
|
1114 |
|
|
GMP_INTS_limb_t ofillval;
|
1115 |
|
|
int size; //The size of the array of limbs to
|
1116 |
|
|
//be added to.
|
1117 |
|
|
GMP_INTS_limb_t mulval;
|
1118 |
|
|
//The value of the single limb to be multiplied.
|
1119 |
|
|
//The required values for the output array.
|
1120 |
|
|
GMP_INTS_limb_t oreq4;
|
1121 |
|
|
GMP_INTS_limb_t oreq3;
|
1122 |
|
|
GMP_INTS_limb_t oreq2;
|
1123 |
|
|
GMP_INTS_limb_t oreq1;
|
1124 |
|
|
GMP_INTS_limb_t oreq0;
|
1125 |
|
|
//The required carry out.
|
1126 |
|
|
GMP_INTS_limb_t reqcarry;
|
1127 |
|
|
} tvs[] =
|
1128 |
|
|
{
|
1129 |
|
|
{
|
1130 |
|
|
"Zero multiplied by zero in one limb must be zero.",
|
1131 |
|
|
0, 0, 0, 0, 0,
|
1132 |
|
|
0xA55AA55A,
|
1133 |
|
|
1,
|
1134 |
|
|
0,
|
1135 |
|
|
0xA55AA55A,0xA55AA55A,0xA55AA55A,0xA55AA55A,0,
|
1136 |
|
|
0
|
1137 |
|
|
},
|
1138 |
|
|
{
|
1139 |
|
|
"Zero multiplied by zero in two limbs must be zero.",
|
1140 |
|
|
0, 0, 0, 0, 0,
|
1141 |
|
|
0xA55AA55A,
|
1142 |
|
|
2,
|
1143 |
|
|
0,
|
1144 |
|
|
0xA55AA55A,0xA55AA55A,0xA55AA55A,0,0,
|
1145 |
|
|
0
|
1146 |
|
|
},
|
1147 |
|
|
{
|
1148 |
|
|
"Zero multiplied by zero in three limbs must be zero.",
|
1149 |
|
|
0, 0, 0, 0, 0,
|
1150 |
|
|
0xA55AA55A,
|
1151 |
|
|
3,
|
1152 |
|
|
0,
|
1153 |
|
|
0xA55AA55A,0xA55AA55A,0,0,0,
|
1154 |
|
|
0
|
1155 |
|
|
},
|
1156 |
|
|
{
|
1157 |
|
|
"Zero times anything must be zero in 3 limbs.",
|
1158 |
|
|
0, 0, 0xA5, 0x5A5A5A5A, 33,
|
1159 |
|
|
0xA55AA55A,
|
1160 |
|
|
3,
|
1161 |
|
|
0,
|
1162 |
|
|
0xA55AA55A,0xA55AA55A,0,0,0,
|
1163 |
|
|
0
|
1164 |
|
|
},
|
1165 |
|
|
{
|
1166 |
|
|
"Anything times zero must be zero in 3 limbs.",
|
1167 |
|
|
0, 0, 0, 0, 0,
|
1168 |
|
|
0xA55AA55A,
|
1169 |
|
|
3,
|
1170 |
|
|
0xA55AA55A,
|
1171 |
|
|
0xA55AA55A,0xA55AA55A,0,0,0,
|
1172 |
|
|
0
|
1173 |
|
|
},
|
1174 |
|
|
{
|
1175 |
|
|
"150001 times 150003 must generate 0x53D23E8C3.",
|
1176 |
|
|
0, 0, 0, 0, 150003,
|
1177 |
|
|
0xA55AA55A,
|
1178 |
|
|
3,
|
1179 |
|
|
150001,
|
1180 |
|
|
0xA55AA55A,0xA55AA55A,0,0x5,0x3D23E8C3,
|
1181 |
|
|
0
|
1182 |
|
|
},
|
1183 |
|
|
{
|
1184 |
|
|
"150001 times 150003 in 1 limb must generate 0x3D23E8C3 and carry of 5.",
|
1185 |
|
|
0, 0, 0, 0, 150003,
|
1186 |
|
|
0xA55AA55A,
|
1187 |
|
|
1,
|
1188 |
|
|
150001,
|
1189 |
|
|
0xA55AA55A,0xA55AA55A,0xA55AA55A,0xA55AA55A,0x3D23E8C3,
|
1190 |
|
|
5
|
1191 |
|
|
},
|
1192 |
|
|
};
|
1193 |
|
|
|
1194 |
|
|
|
1195 |
|
|
//For each test vector.
|
1196 |
|
|
for(i=0; i<sizeof(tvs)/sizeof(tvs[0]); i++)
|
1197 |
|
|
{
|
1198 |
|
|
struct mul_1_test_vector_struct *p;
|
1199 |
|
|
p = &(tvs[i]);
|
1200 |
|
|
|
1201 |
|
|
printf("Executing GMP_INTS_mpn_mul_1() test vector: %d\n", i);
|
1202 |
|
|
printf("Test vector purpose:\n %s\n", p->desc);
|
1203 |
|
|
|
1204 |
|
|
//Set up for the test vector.
|
1205 |
|
|
inlimbs[4] = p->sin4;
|
1206 |
|
|
inlimbs[3] = p->sin3;
|
1207 |
|
|
inlimbs[2] = p->sin2;
|
1208 |
|
|
inlimbs[1] = p->sin1;
|
1209 |
|
|
inlimbs[0] = p->sin0;
|
1210 |
|
|
for (j=0; j<5; j++)
|
1211 |
|
|
{
|
1212 |
|
|
outlimbs[j] = p->ofillval;
|
1213 |
|
|
}
|
1214 |
|
|
|
1215 |
|
|
carry_out = GMP_INTS_mpn_mul_1(outlimbs,
|
1216 |
|
|
inlimbs,
|
1217 |
|
|
p->size,
|
1218 |
|
|
p->mulval);
|
1219 |
|
|
|
1220 |
|
|
if (carry_out != p->reqcarry)
|
1221 |
|
|
{
|
1222 |
|
|
rv = 1;
|
1223 |
|
|
printf(" Borrow FAILED.\n");
|
1224 |
|
|
}
|
1225 |
|
|
if (inlimbs[4] != p->sin4)
|
1226 |
|
|
{
|
1227 |
|
|
rv = 1;
|
1228 |
|
|
printf(" inlimbs[4] FAILED.\n");
|
1229 |
|
|
}
|
1230 |
|
|
if (inlimbs[3] != p->sin3)
|
1231 |
|
|
{
|
1232 |
|
|
rv = 1;
|
1233 |
|
|
printf(" inlimbs[3] FAILED.\n");
|
1234 |
|
|
}
|
1235 |
|
|
if (inlimbs[2] != p->sin2)
|
1236 |
|
|
{
|
1237 |
|
|
rv = 1;
|
1238 |
|
|
printf(" inlimbs[2] FAILED.\n");
|
1239 |
|
|
}
|
1240 |
|
|
if (inlimbs[1] != p->sin1)
|
1241 |
|
|
{
|
1242 |
|
|
rv = 1;
|
1243 |
|
|
printf(" inlimbs[1] FAILED.\n");
|
1244 |
|
|
}
|
1245 |
|
|
if (inlimbs[0] != p->sin0)
|
1246 |
|
|
{
|
1247 |
|
|
rv = 1;
|
1248 |
|
|
printf(" inlimbs[0] FAILED.\n");
|
1249 |
|
|
}
|
1250 |
|
|
if (outlimbs[4] != p->oreq4)
|
1251 |
|
|
{
|
1252 |
|
|
rv = 1;
|
1253 |
|
|
printf(" outlimbs[4] FAILED.\n");
|
1254 |
|
|
}
|
1255 |
|
|
if (outlimbs[3] != p->oreq3)
|
1256 |
|
|
{
|
1257 |
|
|
rv = 1;
|
1258 |
|
|
printf(" outlimbs[3] FAILED.\n");
|
1259 |
|
|
}
|
1260 |
|
|
if (outlimbs[2] != p->oreq2)
|
1261 |
|
|
{
|
1262 |
|
|
rv = 1;
|
1263 |
|
|
printf(" outlimbs[2] FAILED.\n");
|
1264 |
|
|
}
|
1265 |
|
|
if (outlimbs[1] != p->oreq1)
|
1266 |
|
|
{
|
1267 |
|
|
rv = 1;
|
1268 |
|
|
printf(" outlimbs[1] FAILED.\n");
|
1269 |
|
|
}
|
1270 |
|
|
if (outlimbs[0] != p->oreq0)
|
1271 |
|
|
{
|
1272 |
|
|
rv = 1;
|
1273 |
|
|
printf(" outlimbs[0] FAILED.\n");
|
1274 |
|
|
}
|
1275 |
|
|
|
1276 |
|
|
FCMIOF_hline();
|
1277 |
|
|
}
|
1278 |
|
|
|
1279 |
|
|
return(rv);
|
1280 |
|
|
}
|
1281 |
|
|
|
1282 |
|
|
|
1283 |
|
|
int GINTTEST_alloca_test(void)
|
1284 |
|
|
{
|
1285 |
|
|
int rv=0;
|
1286 |
|
|
GMP_INTS_limb_ptr p1, p2;
|
1287 |
|
|
time_t t;
|
1288 |
|
|
int i;
|
1289 |
|
|
|
1290 |
|
|
printf("Testing _alloca() function.\n");
|
1291 |
|
|
|
1292 |
|
|
//Grab the time to get a random element. Will use
|
1293 |
|
|
//the last two bits of this to decide what order to
|
1294 |
|
|
//try things. The danger in doing it another way
|
1295 |
|
|
//has to do once stack segments allocated are not
|
1296 |
|
|
//automatically unallocated--any sequential (rather than
|
1297 |
|
|
//random) approach may not reveal holes.
|
1298 |
|
|
|
1299 |
|
|
t = time(NULL);
|
1300 |
|
|
|
1301 |
|
|
//Grab two pointers to outrageous max chunks of memory.
|
1302 |
|
|
//This is expected to be beyond worst case.
|
1303 |
|
|
|
1304 |
|
|
|
1305 |
|
|
p1 = _alloca((GMP_INTS_MAXIMUM_LIMBS_PER_INT+100) * sizeof(GMP_INTS_limb_t));
|
1306 |
|
|
p2 = _alloca((GMP_INTS_MAXIMUM_LIMBS_PER_INT+200) * sizeof(GMP_INTS_limb_t));
|
1307 |
|
|
|
1308 |
|
|
switch (t&0x7)
|
1309 |
|
|
{
|
1310 |
|
|
case 0:
|
1311 |
|
|
printf("Case 0: p1 ascending, then p2 ascending.\n");
|
1312 |
|
|
for (i=0; i<GMP_INTS_MAXIMUM_LIMBS_PER_INT+100; i++)
|
1313 |
|
|
p1[i] = (0xA55AA55A ^ t);
|
1314 |
|
|
for (i=0; i<GMP_INTS_MAXIMUM_LIMBS_PER_INT+200; i++)
|
1315 |
|
|
p2[i] = (0xA55AA55A ^ t);
|
1316 |
|
|
break;
|
1317 |
|
|
case 1:
|
1318 |
|
|
printf("Case 1: p1 ascending, then p2 descending.\n");
|
1319 |
|
|
for (i=0; i<GMP_INTS_MAXIMUM_LIMBS_PER_INT+100; i++)
|
1320 |
|
|
p1[i] = (0xA55AA55A ^ t);
|
1321 |
|
|
for (i=GMP_INTS_MAXIMUM_LIMBS_PER_INT+200-1; i>=0; i--)
|
1322 |
|
|
p2[i] = (0xA55AA55A ^ t);
|
1323 |
|
|
break;
|
1324 |
|
|
case 2:
|
1325 |
|
|
printf("Case 2: p1 descending, then p2 ascending.\n");
|
1326 |
|
|
for (i=GMP_INTS_MAXIMUM_LIMBS_PER_INT+100-1; i>=0; i--)
|
1327 |
|
|
p1[i] = (0xA55AA55A ^ t);
|
1328 |
|
|
for (i=0; i<GMP_INTS_MAXIMUM_LIMBS_PER_INT+200; i++)
|
1329 |
|
|
p2[i] = (0xA55AA55A ^ t);
|
1330 |
|
|
break;
|
1331 |
|
|
case 3:
|
1332 |
|
|
printf("Case 3: p1 descending, then p2 descending.\n");
|
1333 |
|
|
for (i=GMP_INTS_MAXIMUM_LIMBS_PER_INT+100-1; i>=0; i--)
|
1334 |
|
|
p1[i] = (0xA55AA55A ^ t);
|
1335 |
|
|
for (i=GMP_INTS_MAXIMUM_LIMBS_PER_INT+200-1; i>=0; i--)
|
1336 |
|
|
p2[i] = (0xA55AA55A ^ t);
|
1337 |
|
|
break;
|
1338 |
|
|
case 4:
|
1339 |
|
|
printf("Case 4: p2 ascending, then p1 ascending.\n");
|
1340 |
|
|
for (i=0; i<GMP_INTS_MAXIMUM_LIMBS_PER_INT+200; i++)
|
1341 |
|
|
p2[i] = (0xA55AA55A ^ t);
|
1342 |
|
|
for (i=0; i<GMP_INTS_MAXIMUM_LIMBS_PER_INT+100; i++)
|
1343 |
|
|
p1[i] = (0xA55AA55A ^ t);
|
1344 |
|
|
break;
|
1345 |
|
|
case 5:
|
1346 |
|
|
printf("Case 5: p2 descending, then p1 ascending.\n");
|
1347 |
|
|
for (i=GMP_INTS_MAXIMUM_LIMBS_PER_INT+200-1; i>=0; i--)
|
1348 |
|
|
p2[i] = (0xA55AA55A ^ t);
|
1349 |
|
|
for (i=0; i<GMP_INTS_MAXIMUM_LIMBS_PER_INT+100; i++)
|
1350 |
|
|
p1[i] = (0xA55AA55A ^ t);
|
1351 |
|
|
break;
|
1352 |
|
|
case 6:
|
1353 |
|
|
printf("Case 6: p2 ascending, then p1 descending.\n");
|
1354 |
|
|
for (i=0; i<GMP_INTS_MAXIMUM_LIMBS_PER_INT+200; i++)
|
1355 |
|
|
p2[i] = (0xA55AA55A ^ t);
|
1356 |
|
|
for (i=GMP_INTS_MAXIMUM_LIMBS_PER_INT+100-1; i>=0; i--)
|
1357 |
|
|
p1[i] = (0xA55AA55A ^ t);
|
1358 |
|
|
break;
|
1359 |
|
|
case 7:
|
1360 |
|
|
printf("Case 7: p2 descending, p1 descending.\n");
|
1361 |
|
|
for (i=GMP_INTS_MAXIMUM_LIMBS_PER_INT+200-1; i>=0; i--)
|
1362 |
|
|
p2[i] = (0xA55AA55A ^ t);
|
1363 |
|
|
for (i=GMP_INTS_MAXIMUM_LIMBS_PER_INT+100-1; i>=0; i--)
|
1364 |
|
|
p1[i] = (0xA55AA55A ^ t);
|
1365 |
|
|
break;
|
1366 |
|
|
default:
|
1367 |
|
|
abort();
|
1368 |
|
|
break;
|
1369 |
|
|
}
|
1370 |
|
|
|
1371 |
|
|
|
1372 |
|
|
FCMIOF_hline();
|
1373 |
|
|
|
1374 |
|
|
return(rv);
|
1375 |
|
|
}
|
1376 |
|
|
|
1377 |
|
|
|
1378 |
|
|
int GINTTEST_mpz_set_simple_char_str_test(void)
|
1379 |
|
|
{
|
1380 |
|
|
int rv=0;
|
1381 |
|
|
int i;
|
1382 |
|
|
GMP_INTS_mpz_struct x;
|
1383 |
|
|
|
1384 |
|
|
char *sa[] =
|
1385 |
|
|
{
|
1386 |
|
|
"0",
|
1387 |
|
|
"1",
|
1388 |
|
|
"-1",
|
1389 |
|
|
"2",
|
1390 |
|
|
"-2",
|
1391 |
|
|
"3",
|
1392 |
|
|
"-3",
|
1393 |
|
|
"9",
|
1394 |
|
|
"-9",
|
1395 |
|
|
"10",
|
1396 |
|
|
"-10",
|
1397 |
|
|
"232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319",
|
1398 |
|
|
};
|
1399 |
|
|
|
1400 |
|
|
printf("Testing GMP_INTS_mpz_set_simple_char_str() function.\n");
|
1401 |
|
|
printf("This test will consist of setting an integer to several\n");
|
1402 |
|
|
printf("string values and examining the result.\n");
|
1403 |
|
|
FCMIOF_hline();
|
1404 |
|
|
|
1405 |
|
|
//Initialize the integer.
|
1406 |
|
|
GMP_INTS_mpz_init(&x);
|
1407 |
|
|
|
1408 |
|
|
for (i=0; i<sizeof(sa)/sizeof(sa[0]); i++)
|
1409 |
|
|
{
|
1410 |
|
|
printf("Trying value: %s\n", sa[i]);
|
1411 |
|
|
GMP_INTS_mpz_set_simple_char_str(&x, sa[i]);
|
1412 |
|
|
GMP_INTS_mpz_print_int(stdout, &x, "Result.");
|
1413 |
|
|
FCMIOF_hline();
|
1414 |
|
|
}
|
1415 |
|
|
|
1416 |
|
|
//Destroy the integer.
|
1417 |
|
|
GMP_INTS_mpz_clear(&x);
|
1418 |
|
|
|
1419 |
|
|
return(rv);
|
1420 |
|
|
}
|
1421 |
|
|
|
1422 |
|
|
|
1423 |
|
|
|
1424 |
|
|
int GINTTEST_mpz_add_test(void)
|
1425 |
|
|
{
|
1426 |
|
|
int rv=0;
|
1427 |
|
|
int i;
|
1428 |
|
|
|
1429 |
|
|
GMP_INTS_mpz_struct k0, k1, k2, k3, k1000, kneg1, x, y, z;
|
1430 |
|
|
|
1431 |
|
|
//First, check the move upwards from zero.
|
1432 |
|
|
printf("Preparing to test mpz_add() function.\n");
|
1433 |
|
|
FCMIOF_hline();
|
1434 |
|
|
printf("Allocating integers.\n");
|
1435 |
|
|
GMP_INTS_mpz_init(&k0);
|
1436 |
|
|
GMP_INTS_mpz_init(&k1);
|
1437 |
|
|
GMP_INTS_mpz_init(&k2);
|
1438 |
|
|
GMP_INTS_mpz_init(&k3);
|
1439 |
|
|
GMP_INTS_mpz_init(&k1000);
|
1440 |
|
|
GMP_INTS_mpz_init(&kneg1);
|
1441 |
|
|
GMP_INTS_mpz_init(&x);
|
1442 |
|
|
GMP_INTS_mpz_init(&y);
|
1443 |
|
|
GMP_INTS_mpz_init(&z);
|
1444 |
|
|
FCMIOF_hline();
|
1445 |
|
|
|
1446 |
|
|
printf("Setting constants to prescribed values.\n");
|
1447 |
|
|
GMP_INTS_mpz_set_si (&k0, 0);
|
1448 |
|
|
GMP_INTS_mpz_set_si (&k1, 1);
|
1449 |
|
|
GMP_INTS_mpz_set_si (&k2, 2);
|
1450 |
|
|
GMP_INTS_mpz_set_si (&k3, 3);
|
1451 |
|
|
GMP_INTS_mpz_set_si (&k1000, 1000);
|
1452 |
|
|
GMP_INTS_mpz_set_si (&kneg1, -1);
|
1453 |
|
|
|
1454 |
|
|
|
1455 |
|
|
printf("Starting from zero and going up by 1's.\n");
|
1456 |
|
|
GMP_INTS_mpz_set_si (&x, 0);
|
1457 |
|
|
|
1458 |
|
|
for (i=0; i<15; i++)
|
1459 |
|
|
{
|
1460 |
|
|
GMP_INTS_mpz_add(&x, &k1, &x);
|
1461 |
|
|
GMP_INTS_mpz_print_int(stdout, &x, "Addition result.");
|
1462 |
|
|
FCMIOF_hline();
|
1463 |
|
|
}
|
1464 |
|
|
|
1465 |
|
|
printf("Adding a negative number, going back by 1's.\n");
|
1466 |
|
|
for (i=0; i<29; i++)
|
1467 |
|
|
{
|
1468 |
|
|
GMP_INTS_mpz_add(&x, &kneg1, &x);
|
1469 |
|
|
GMP_INTS_mpz_print_int(stdout, &x, "Addition result.");
|
1470 |
|
|
FCMIOF_hline();
|
1471 |
|
|
}
|
1472 |
|
|
|
1473 |
|
|
printf("Now checking exponential growth until overflow.\n");
|
1474 |
|
|
FCMIOF_hline();
|
1475 |
|
|
|
1476 |
|
|
i=0;
|
1477 |
|
|
while (!GMP_INTS_mpz_get_flags(&x))
|
1478 |
|
|
{
|
1479 |
|
|
i++;
|
1480 |
|
|
GMP_INTS_mpz_add(&x, &x, &x);
|
1481 |
|
|
//GMP_INTS_mpz_print_int(stdout, &x, "Addition result.");
|
1482 |
|
|
//FCMIOF_hline();
|
1483 |
|
|
}
|
1484 |
|
|
|
1485 |
|
|
printf("Exponential growth terminated in %d iterations.\n", i);
|
1486 |
|
|
|
1487 |
|
|
printf("Deallocating integers.\n");
|
1488 |
|
|
GMP_INTS_mpz_clear(&k0);
|
1489 |
|
|
GMP_INTS_mpz_clear(&k1);
|
1490 |
|
|
GMP_INTS_mpz_clear(&k2);
|
1491 |
|
|
GMP_INTS_mpz_clear(&k3);
|
1492 |
|
|
GMP_INTS_mpz_clear(&k1000);
|
1493 |
|
|
GMP_INTS_mpz_clear(&x);
|
1494 |
|
|
GMP_INTS_mpz_clear(&y);
|
1495 |
|
|
GMP_INTS_mpz_clear(&z);
|
1496 |
|
|
GMP_INTS_mpz_clear(&kneg1);
|
1497 |
|
|
FCMIOF_hline();
|
1498 |
|
|
|
1499 |
|
|
return(rv);
|
1500 |
|
|
}
|
1501 |
|
|
|
1502 |
|
|
|
1503 |
|
|
int GINTTEST_mpz_tdiv_qr_test(void)
|
1504 |
|
|
{
|
1505 |
|
|
int rv=0;
|
1506 |
|
|
int i;
|
1507 |
|
|
|
1508 |
|
|
GMP_INTS_mpz_struct dividend, divisor, quotient, remainder;
|
1509 |
|
|
|
1510 |
|
|
//For each of these tests, we want to walk through the division
|
1511 |
|
|
//routine (with a debugger) to make sure that everything is
|
1512 |
|
|
//as expected. The table below is a list of dividends
|
1513 |
|
|
//and divisors.
|
1514 |
|
|
static struct
|
1515 |
|
|
{
|
1516 |
|
|
char *dividend;
|
1517 |
|
|
char *divisor;
|
1518 |
|
|
} ttbl[]
|
1519 |
|
|
= {
|
1520 |
|
|
{
|
1521 |
|
|
"0",
|
1522 |
|
|
"0"
|
1523 |
|
|
},
|
1524 |
|
|
{
|
1525 |
|
|
"14",
|
1526 |
|
|
"25"
|
1527 |
|
|
},
|
1528 |
|
|
{
|
1529 |
|
|
"25",
|
1530 |
|
|
"14"
|
1531 |
|
|
},
|
1532 |
|
|
{
|
1533 |
|
|
"259414911",
|
1534 |
|
|
"1479"
|
1535 |
|
|
},
|
1536 |
|
|
};
|
1537 |
|
|
|
1538 |
|
|
|
1539 |
|
|
//Initialize all four of the arbitrary integers.
|
1540 |
|
|
GMP_INTS_mpz_init(÷nd);
|
1541 |
|
|
GMP_INTS_mpz_init(&divisor);
|
1542 |
|
|
GMP_INTS_mpz_init("ient);
|
1543 |
|
|
GMP_INTS_mpz_init(&remainder);
|
1544 |
|
|
|
1545 |
|
|
//For each of the sets of integers, go through and
|
1546 |
|
|
//try them out. Will take a debugger on these.
|
1547 |
|
|
for (i=0; i<sizeof(ttbl)/sizeof(ttbl[0]); i++)
|
1548 |
|
|
{
|
1549 |
|
|
//Announce what is happening.
|
1550 |
|
|
printf("Testing GINTTEST_mpz_tdiv_qr().\n");
|
1551 |
|
|
printf("Dividend: %s\n", ttbl[i].dividend);
|
1552 |
|
|
printf("Divisor: %s\n", ttbl[i].divisor);
|
1553 |
|
|
FCMIOF_hline();
|
1554 |
|
|
|
1555 |
|
|
//Set the integers.
|
1556 |
|
|
GMP_INTS_mpz_set_simple_char_str(÷nd, ttbl[i].dividend);
|
1557 |
|
|
GMP_INTS_mpz_set_simple_char_str(&divisor, ttbl[i].divisor);
|
1558 |
|
|
|
1559 |
|
|
//Announce what has been set, plus the other parameters.
|
1560 |
|
|
GMP_INTS_mpz_print_int(stdout, ÷nd, "Dividend before division.");
|
1561 |
|
|
FCMIOF_hline();
|
1562 |
|
|
GMP_INTS_mpz_print_int(stdout, &divisor, "Divisor before division.");
|
1563 |
|
|
FCMIOF_hline();
|
1564 |
|
|
GMP_INTS_mpz_print_int(stdout, "ient, "Quotient before division.");
|
1565 |
|
|
FCMIOF_hline();
|
1566 |
|
|
GMP_INTS_mpz_print_int(stdout, &remainder,"Remainder before division.");
|
1567 |
|
|
FCMIOF_hline();
|
1568 |
|
|
|
1569 |
|
|
//Perform the actual division.
|
1570 |
|
|
printf("Performing division ... ");
|
1571 |
|
|
GMP_INTS_mpz_tdiv_qr ("ient, &remainder, ÷nd, &divisor);
|
1572 |
|
|
printf("done.\n");
|
1573 |
|
|
FCMIOF_hline();
|
1574 |
|
|
|
1575 |
|
|
//Print out the results after the division.
|
1576 |
|
|
GMP_INTS_mpz_print_int(stdout, "ient, "Quotient after division.");
|
1577 |
|
|
FCMIOF_hline();
|
1578 |
|
|
GMP_INTS_mpz_print_int(stdout, &remainder,"Remainder after division.");
|
1579 |
|
|
FCMIOF_hline();
|
1580 |
|
|
GMP_INTS_mpz_print_int(stdout, ÷nd, "Dividend after division.");
|
1581 |
|
|
FCMIOF_hline();
|
1582 |
|
|
GMP_INTS_mpz_print_int(stdout, &divisor, "Divisor after division.");
|
1583 |
|
|
FCMIOF_hline();
|
1584 |
|
|
}
|
1585 |
|
|
|
1586 |
|
|
//Deallocate all four of the arbitrary integers.
|
1587 |
|
|
GMP_INTS_mpz_clear(÷nd);
|
1588 |
|
|
GMP_INTS_mpz_clear(&divisor);
|
1589 |
|
|
GMP_INTS_mpz_clear("ient);
|
1590 |
|
|
GMP_INTS_mpz_clear(&remainder);
|
1591 |
|
|
|
1592 |
|
|
return(rv);
|
1593 |
|
|
}
|
1594 |
|
|
|
1595 |
|
|
|
1596 |
|
|
int GINTTEST_mpz_mul_test(void)
|
1597 |
|
|
{
|
1598 |
|
|
int rv=0;
|
1599 |
|
|
GMP_INTS_mpz_struct x;
|
1600 |
|
|
|
1601 |
|
|
printf("Preparing to test mpz_mul() function.\n");
|
1602 |
|
|
|
1603 |
|
|
//There isn't a lot that can be tested without more test
|
1604 |
|
|
//cases.
|
1605 |
|
|
//For now, just be sure that large powers of two show a
|
1606 |
|
|
//corresponding bit pattern.
|
1607 |
|
|
|
1608 |
|
|
GMP_INTS_mpz_init(&x);
|
1609 |
|
|
|
1610 |
|
|
//This string constant was obtained from the RAP program
|
1611 |
|
|
//and is known to be 2**4000. This is my only test case
|
1612 |
|
|
//for now.
|
1613 |
|
|
GMP_INTS_mpz_set_simple_char_str
|
1614 |
|
|
(
|
1615 |
|
|
&x,
|
1616 |
|
|
"13,182,040,934,309,431,"
|
1617 |
|
|
"001,038,897,942,365,913,631,840,191,"
|
1618 |
|
|
"610,932,727,690,928,034,502,417,569,"
|
1619 |
|
|
"281,128,344,551,079,752,123,172,122,"
|
1620 |
|
|
"033,140,940,756,480,716,823,038,446,"
|
1621 |
|
|
"817,694,240,581,281,731,062,452,512,"
|
1622 |
|
|
"184,038,544,674,444,386,888,956,328,"
|
1623 |
|
|
"970,642,771,993,930,036,586,552,924,"
|
1624 |
|
|
"249,514,488,832,183,389,415,832,375,"
|
1625 |
|
|
"620,009,284,922,608,946,111,038,578,"
|
1626 |
|
|
"754,077,913,265,440,918,583,125,586,"
|
1627 |
|
|
"050,431,647,284,603,636,490,823,850,"
|
1628 |
|
|
"007,826,811,672,468,900,210,689,104,"
|
1629 |
|
|
"488,089,485,347,192,152,708,820,119,"
|
1630 |
|
|
"765,006,125,944,858,397,761,874,669,"
|
1631 |
|
|
"301,278,745,233,504,796,586,994,514,"
|
1632 |
|
|
"054,435,217,053,803,732,703,240,283,"
|
1633 |
|
|
"400,815,926,169,348,364,799,472,716,"
|
1634 |
|
|
"094,576,894,007,243,168,662,568,886,"
|
1635 |
|
|
"603,065,832,486,830,606,125,017,643,"
|
1636 |
|
|
"356,469,732,407,252,874,567,217,733,"
|
1637 |
|
|
"694,824,236,675,323,341,755,681,839,"
|
1638 |
|
|
"221,954,693,820,456,072,020,253,884,"
|
1639 |
|
|
"371,226,826,844,858,636,194,212,875,"
|
1640 |
|
|
"139,566,587,445,390,068,014,747,975,"
|
1641 |
|
|
"813,971,748,114,770,439,248,826,688,"
|
1642 |
|
|
"667,129,237,954,128,555,841,874,460,"
|
1643 |
|
|
"665,729,630,492,658,600,179,338,272,"
|
1644 |
|
|
"579,110,020,881,228,767,361,200,603,"
|
1645 |
|
|
"478,973,120,168,893,997,574,353,727,"
|
1646 |
|
|
"653,998,969,223,092,798,255,701,666,"
|
1647 |
|
|
"067,972,698,906,236,921,628,764,772,"
|
1648 |
|
|
"837,915,526,086,464,389,161,570,534,"
|
1649 |
|
|
"616,956,703,744,840,502,975,279,094,"
|
1650 |
|
|
"087,587,298,968,423,516,531,626,090,"
|
1651 |
|
|
"898,389,351,449,020,056,851,221,079,"
|
1652 |
|
|
"048,966,718,878,943,309,232,071,978,"
|
1653 |
|
|
"575,639,877,208,621,237,040,940,126,"
|
1654 |
|
|
"912,767,610,658,141,079,378,758,043,"
|
1655 |
|
|
"403,611,425,454,744,180,577,150,855,"
|
1656 |
|
|
"204,937,163,460,902,512,732,551,260,"
|
1657 |
|
|
"539,639,221,457,005,977,247,266,676,"
|
1658 |
|
|
"344,018,155,647,509,515,396,711,351,"
|
1659 |
|
|
"487,546,062,479,444,592,779,055,555,"
|
1660 |
|
|
"421,362,722,504,575,706,910,949,376");
|
1661 |
|
|
|
1662 |
|
|
GMP_INTS_mpz_print_int(stdout, &x, "2**4000 (I hope)");
|
1663 |
|
|
|
1664 |
|
|
GMP_INTS_mpz_clear(&x);
|
1665 |
|
|
|
1666 |
|
|
FCMIOF_hline();
|
1667 |
|
|
|
1668 |
|
|
return(rv);
|
1669 |
|
|
}
|
1670 |
|
|
|
1671 |
|
|
|
1672 |
|
|
int GINTTEST_speed_tests(void)
|
1673 |
|
|
{
|
1674 |
|
|
int rv=0;
|
1675 |
|
|
int fnum;
|
1676 |
|
|
int i;
|
1677 |
|
|
unsigned long lc;
|
1678 |
|
|
time_t time1, time2;
|
1679 |
|
|
GMP_INTS_limb_t arg1[10];
|
1680 |
|
|
GMP_INTS_limb_t arg2[10];
|
1681 |
|
|
GMP_INTS_limb_t arg3[10];
|
1682 |
|
|
|
1683 |
|
|
GMP_INTS_mpz_struct ten_limber_a, ten_limber_b, result;
|
1684 |
|
|
|
1685 |
|
|
//Initialize (allocate space) for three arbitrary integers.
|
1686 |
|
|
GMP_INTS_mpz_init(&ten_limber_a);
|
1687 |
|
|
GMP_INTS_mpz_init(&ten_limber_b);
|
1688 |
|
|
GMP_INTS_mpz_init(&result);
|
1689 |
|
|
|
1690 |
|
|
//Assign two different integers to be 10-limb integers.
|
1691 |
|
|
GMP_INTS_mpz_set_simple_char_str(
|
1692 |
|
|
&ten_limber_a,
|
1693 |
|
|
"232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1694 |
|
|
GMP_INTS_mpz_set_simple_char_str(
|
1695 |
|
|
&ten_limber_b,
|
1696 |
|
|
"232754932472365498327432654903279999966943265932609327423947234793297873254943265943265943265319");
|
1697 |
|
|
|
1698 |
|
|
//Set up sets of test limbs.
|
1699 |
|
|
for (i=0; i<10; i++)
|
1700 |
|
|
{
|
1701 |
|
|
arg1[i] = 0xA55AA55A;
|
1702 |
|
|
arg2[i] = 0x5AA55AA5;
|
1703 |
|
|
arg3[i] = 0xA55AA55A;
|
1704 |
|
|
}
|
1705 |
|
|
|
1706 |
|
|
|
1707 |
|
|
printf("Beginning speed testing of GMP_INTS module functions.\n");
|
1708 |
|
|
|
1709 |
|
|
FCMIOF_hline();
|
1710 |
|
|
|
1711 |
|
|
for (fnum=0; fnum<14; fnum++)
|
1712 |
|
|
{
|
1713 |
|
|
printf("Speed-testing function: ");
|
1714 |
|
|
|
1715 |
|
|
switch(fnum)
|
1716 |
|
|
{
|
1717 |
|
|
case 0: printf("GMP_INTS_data_sizes_are_wrong()");
|
1718 |
|
|
break;
|
1719 |
|
|
case 1: printf("GMP_INTS_mpz_sgn()");
|
1720 |
|
|
break;
|
1721 |
|
|
case 2: printf("GMP_INTS_is_neg()");
|
1722 |
|
|
break;
|
1723 |
|
|
case 3: printf("GMP_INTS_is_zero()");
|
1724 |
|
|
break;
|
1725 |
|
|
case 4: printf("GMP_INTS_is_pos()");
|
1726 |
|
|
break;
|
1727 |
|
|
case 5: printf("GMP_INTS_is_odd()");
|
1728 |
|
|
break;
|
1729 |
|
|
case 6: printf("GMP_INTS_is_even()");
|
1730 |
|
|
break;
|
1731 |
|
|
case 7: printf("GMP_INTS_mpn_add_1()");
|
1732 |
|
|
break;
|
1733 |
|
|
case 8: printf("GMP_INTS_mpn_sub_1()");
|
1734 |
|
|
break;
|
1735 |
|
|
case 9: printf("GMP_INTS_mpn_mul_1()");
|
1736 |
|
|
break;
|
1737 |
|
|
case 10: printf("GMP_INTS_mpn_add_n()");
|
1738 |
|
|
break;
|
1739 |
|
|
case 11: printf("GMP_INTS_mpz_add()");
|
1740 |
|
|
break;
|
1741 |
|
|
case 12: printf("GMP_INTS_mpz_set_simple_char_str()");
|
1742 |
|
|
break;
|
1743 |
|
|
case 13: printf("GMP_INTS_mpz_mul()");
|
1744 |
|
|
break;
|
1745 |
|
|
default:
|
1746 |
|
|
abort();
|
1747 |
|
|
break;
|
1748 |
|
|
}
|
1749 |
|
|
|
1750 |
|
|
printf("\n");
|
1751 |
|
|
printf("All operands are 10 limbs (320 bits) long.\n");
|
1752 |
|
|
|
1753 |
|
|
//Synchronize to a change in seconds.
|
1754 |
|
|
time1 = time(NULL);
|
1755 |
|
|
while (time1 == (time2 = time(NULL)));
|
1756 |
|
|
//We had a transition. time2 has the new time.
|
1757 |
|
|
|
1758 |
|
|
lc = 0;
|
1759 |
|
|
while (time2 == time(NULL))
|
1760 |
|
|
{
|
1761 |
|
|
lc ++;
|
1762 |
|
|
|
1763 |
|
|
switch(fnum)
|
1764 |
|
|
{
|
1765 |
|
|
case 0: GMP_INTS_data_sizes_are_wrong();
|
1766 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1767 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1768 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1769 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1770 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1771 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1772 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1773 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1774 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1775 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1776 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1777 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1778 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1779 |
|
|
GMP_INTS_data_sizes_are_wrong();
|
1780 |
|
|
break;
|
1781 |
|
|
case 1: //Can't test int GMP_INTS_mpz_sgn()
|
1782 |
|
|
//yet.
|
1783 |
|
|
break;
|
1784 |
|
|
case 2: //Can't test int GMP_INTS_mpz_is_neg()
|
1785 |
|
|
//yet.
|
1786 |
|
|
break;
|
1787 |
|
|
case 3: //Can't test int GMP_INTS_mpz_is_zero()
|
1788 |
|
|
//yet.
|
1789 |
|
|
break;
|
1790 |
|
|
case 4: //Can't test int GMP_INTS_mpz_is_pos()
|
1791 |
|
|
//yet.
|
1792 |
|
|
break;
|
1793 |
|
|
case 5: //Can't test int GMP_INTS_mpz_is_odd()
|
1794 |
|
|
//yet.
|
1795 |
|
|
break;
|
1796 |
|
|
case 6: //Can't test int GMP_INTS_mpz_is_even()
|
1797 |
|
|
//yet.
|
1798 |
|
|
break;
|
1799 |
|
|
case 7: GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1800 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1801 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1802 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1803 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1804 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1805 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1806 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1807 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1808 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1809 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1810 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1811 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1812 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1813 |
|
|
GMP_INTS_mpn_add_1(arg3, arg1, 10, arg2[0]);
|
1814 |
|
|
break;
|
1815 |
|
|
case 8: GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1816 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1817 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1818 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1819 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1820 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1821 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1822 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1823 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1824 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1825 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1826 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1827 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1828 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1829 |
|
|
GMP_INTS_mpn_sub_1(arg3, arg1, 10, arg2[0]);
|
1830 |
|
|
break;
|
1831 |
|
|
case 9: GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1832 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1833 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1834 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1835 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1836 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1837 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1838 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1839 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1840 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1841 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1842 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1843 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1844 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1845 |
|
|
GMP_INTS_mpn_mul_1(arg3, arg1, 10, arg2[0]);
|
1846 |
|
|
break;
|
1847 |
|
|
case 10: GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1848 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1849 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1850 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1851 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1852 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1853 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1854 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1855 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1856 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1857 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1858 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1859 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1860 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1861 |
|
|
GMP_INTS_mpn_add_n(arg3, arg2, arg1, 10);
|
1862 |
|
|
break;
|
1863 |
|
|
case 11: GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1864 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1865 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1866 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1867 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1868 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1869 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1870 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1871 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1872 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1873 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1874 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1875 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1876 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1877 |
|
|
GMP_INTS_mpz_add(&result, &ten_limber_a, &ten_limber_b);
|
1878 |
|
|
break;
|
1879 |
|
|
case 12: GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1880 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1881 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1882 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1883 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1884 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1885 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1886 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1887 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1888 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1889 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1890 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1891 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1892 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1893 |
|
|
GMP_INTS_mpz_set_simple_char_str(&result, "232754932472365498327432654903274693266943265932609327423947234793297873254943265943265943265319");
|
1894 |
|
|
break;
|
1895 |
|
|
case 13: GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1896 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1897 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1898 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1899 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1900 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1901 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1902 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1903 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1904 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1905 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1906 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1907 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1908 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1909 |
|
|
GMP_INTS_mpz_mul(&result, &ten_limber_a, &ten_limber_b);
|
1910 |
|
|
break;
|
1911 |
|
|
default:
|
1912 |
|
|
abort();
|
1913 |
|
|
break;
|
1914 |
|
|
}
|
1915 |
|
|
|
1916 |
|
|
}
|
1917 |
|
|
|
1918 |
|
|
|
1919 |
|
|
lc *= 15;
|
1920 |
|
|
printf("%ld executions in 1 second, ignoring time() call.\n", lc);
|
1921 |
|
|
|
1922 |
|
|
|
1923 |
|
|
FCMIOF_hline();
|
1924 |
|
|
}
|
1925 |
|
|
|
1926 |
|
|
printf("Ending speed testing of GMP_INTS module functions.\n");
|
1927 |
|
|
|
1928 |
|
|
//Clear (deallocate storage) for three integers.
|
1929 |
|
|
GMP_INTS_mpz_clear(&ten_limber_a);
|
1930 |
|
|
GMP_INTS_mpz_clear(&ten_limber_b);
|
1931 |
|
|
GMP_INTS_mpz_clear(&result);
|
1932 |
|
|
|
1933 |
|
|
FCMIOF_hline();
|
1934 |
|
|
|
1935 |
|
|
return(rv);
|
1936 |
|
|
}
|
1937 |
|
|
|
1938 |
|
|
|
1939 |
|
|
int GINTTEST_to_string_test(void)
|
1940 |
|
|
{
|
1941 |
|
|
int rv=0;
|
1942 |
|
|
int predicted, actual;
|
1943 |
|
|
char *p;
|
1944 |
|
|
|
1945 |
|
|
GMP_INTS_mpz_struct old_arg;
|
1946 |
|
|
GMP_INTS_mpz_struct arg;
|
1947 |
|
|
GMP_INTS_mpz_struct k3;
|
1948 |
|
|
|
1949 |
|
|
printf("Testing string formatting.\n");
|
1950 |
|
|
FCMIOF_hline();
|
1951 |
|
|
|
1952 |
|
|
//Initialize (allocate space) for integer.
|
1953 |
|
|
GMP_INTS_mpz_init(&old_arg);
|
1954 |
|
|
GMP_INTS_mpz_init(&arg);
|
1955 |
|
|
GMP_INTS_mpz_init(&k3);
|
1956 |
|
|
|
1957 |
|
|
//The central strategy of this
|
1958 |
|
|
//function is just to keep on going until
|
1959 |
|
|
//overflow.
|
1960 |
|
|
GMP_INTS_mpz_set_si(&k3, -1097116912);
|
1961 |
|
|
GMP_INTS_mpz_set_ui(&arg, 1);
|
1962 |
|
|
|
1963 |
|
|
do
|
1964 |
|
|
{
|
1965 |
|
|
//Multiply the arg by k3 until we hit a fair size.
|
1966 |
|
|
GMP_INTS_mpz_copy(&old_arg, &arg);
|
1967 |
|
|
GMP_INTS_mpz_mul(&arg, &arg, &k3);
|
1968 |
|
|
}
|
1969 |
|
|
while (arg.size < 100);
|
1970 |
|
|
|
1971 |
|
|
GMP_INTS_mpz_copy(&arg, &old_arg);
|
1972 |
|
|
|
1973 |
|
|
//Figure out and announce how many characters are
|
1974 |
|
|
//required to hold result.
|
1975 |
|
|
predicted = GMP_INTS_mpz_size_in_base_10(&arg);
|
1976 |
|
|
|
1977 |
|
|
printf("Predicting %d chars to hold value.\n", predicted);
|
1978 |
|
|
|
1979 |
|
|
p = malloc(sizeof(char) * predicted * 2);
|
1980 |
|
|
|
1981 |
|
|
printf("Formatting string.\n");
|
1982 |
|
|
|
1983 |
|
|
GMP_INTS_mpz_to_string(p, &arg);
|
1984 |
|
|
|
1985 |
|
|
printf("Done. String is below.\n");
|
1986 |
|
|
|
1987 |
|
|
FCMIOF_hline();
|
1988 |
|
|
|
1989 |
|
|
printf("%s\n", p);
|
1990 |
|
|
|
1991 |
|
|
FCMIOF_hline();
|
1992 |
|
|
|
1993 |
|
|
actual = strlen(p);
|
1994 |
|
|
|
1995 |
|
|
printf("Actual space consumption before commas: %d\n", actual+1);
|
1996 |
|
|
|
1997 |
|
|
FCMIOF_hline();
|
1998 |
|
|
|
1999 |
|
|
printf("Adding commas now ...");
|
2000 |
|
|
BSTRFUNC_commanate(p);
|
2001 |
|
|
printf("Done. String is below.\n");
|
2002 |
|
|
FCMIOF_hline();
|
2003 |
|
|
|
2004 |
|
|
FCMIOF_hline();
|
2005 |
|
|
|
2006 |
|
|
printf("%s\n", p);
|
2007 |
|
|
|
2008 |
|
|
FCMIOF_hline();
|
2009 |
|
|
|
2010 |
|
|
actual = strlen(p);
|
2011 |
|
|
|
2012 |
|
|
printf("Actual space consumption after commas: %d\n", actual+1);
|
2013 |
|
|
|
2014 |
|
|
FCMIOF_hline();
|
2015 |
|
|
if ((actual+1) > predicted)
|
2016 |
|
|
rv = 1;
|
2017 |
|
|
|
2018 |
|
|
free(p);
|
2019 |
|
|
|
2020 |
|
|
//Deallocate integer space.
|
2021 |
|
|
GMP_INTS_mpz_clear(&old_arg);
|
2022 |
|
|
GMP_INTS_mpz_clear(&arg);
|
2023 |
|
|
GMP_INTS_mpz_clear(&k3);
|
2024 |
|
|
|
2025 |
|
|
//FCMIOF_hline();
|
2026 |
|
|
|
2027 |
|
|
return(rv);
|
2028 |
|
|
}
|
2029 |
|
|
|
2030 |
|
|
|
2031 |
|
|
int GMP_long_int_format_to_stream_test(void)
|
2032 |
|
|
{
|
2033 |
|
|
int rv=0, j;
|
2034 |
|
|
GMP_INTS_mpz_struct i;
|
2035 |
|
|
|
2036 |
|
|
printf("Testing GMP_long_int_format_to_stream() function.\n");
|
2037 |
|
|
FCMIOF_hline();
|
2038 |
|
|
|
2039 |
|
|
//We need an integer to take through the paces to see what it does.
|
2040 |
|
|
//Let's start with 0, then go to 1, and keep alternating on both
|
2041 |
|
|
//sides of 0. Must also test NAN cases.
|
2042 |
|
|
|
2043 |
|
|
//Initialize (allocate space) for integer.
|
2044 |
|
|
GMP_INTS_mpz_init(&i);
|
2045 |
|
|
|
2046 |
|
|
//Test how the error conditions are output.
|
2047 |
|
|
i.flags = GMP_INTS_EF_INTOVF_POS;
|
2048 |
|
|
GMP_INTS_mpz_long_int_format_to_stream(stdout, &i, "+ Overflow");
|
2049 |
|
|
FCMIOF_hline();
|
2050 |
|
|
i.flags = GMP_INTS_EF_INTOVF_NEG;
|
2051 |
|
|
GMP_INTS_mpz_long_int_format_to_stream(stdout, &i, "- Overflow");
|
2052 |
|
|
FCMIOF_hline();
|
2053 |
|
|
i.flags = GMP_INTS_EF_INTOVF_TAINT_POS;
|
2054 |
|
|
GMP_INTS_mpz_long_int_format_to_stream(stdout, &i, "+ Overflow");
|
2055 |
|
|
FCMIOF_hline();
|
2056 |
|
|
i.flags = GMP_INTS_EF_INTOVF_TAINT_NEG;
|
2057 |
|
|
GMP_INTS_mpz_long_int_format_to_stream(stdout, &i, "- Overflow");
|
2058 |
|
|
FCMIOF_hline();
|
2059 |
|
|
|
2060 |
|
|
|
2061 |
|
|
//Zero test.
|
2062 |
|
|
GMP_INTS_mpz_set_si(&i, 0);
|
2063 |
|
|
GMP_INTS_mpz_long_int_format_to_stream(stdout, &i, "Should Be 0");
|
2064 |
|
|
FCMIOF_hline();
|
2065 |
|
|
|
2066 |
|
|
//Now, walk from -100 to 100.
|
2067 |
|
|
|
2068 |
|
|
for (j=-100; j<=100; j++)
|
2069 |
|
|
{
|
2070 |
|
|
GMP_INTS_mpz_set_si(&i, j);
|
2071 |
|
|
GMP_INTS_mpz_long_int_format_to_stream(stdout, &i, "Should Be [-100,100]");
|
2072 |
|
|
FCMIOF_hline();
|
2073 |
|
|
}
|
2074 |
|
|
|
2075 |
|
|
//Now, start with 1 and multiply by -371 repeatedly until about 500
|
2076 |
|
|
//digits. 500 digits is about 50 limbs.
|
2077 |
|
|
GMP_INTS_mpz_set_si(&i, 1);
|
2078 |
|
|
|
2079 |
|
|
do
|
2080 |
|
|
{
|
2081 |
|
|
GMP_INTS_mpz_long_int_format_to_stream(stdout, &i, "Longer Test");
|
2082 |
|
|
FCMIOF_hline();
|
2083 |
|
|
GMP_INTS_mpz_mul_si(&i, &i, -371);
|
2084 |
|
|
}
|
2085 |
|
|
while (i.size < 55);
|
2086 |
|
|
|
2087 |
|
|
//Destroy the space.
|
2088 |
|
|
GMP_INTS_mpz_clear(&i);
|
2089 |
|
|
|
2090 |
|
|
return(rv);
|
2091 |
|
|
}
|
2092 |
|
|
|
2093 |
|
|
|
2094 |
|
|
int GINTTEST_mpz_fac_ui_test(void)
|
2095 |
|
|
{
|
2096 |
|
|
int rv=0;
|
2097 |
|
|
unsigned long j;
|
2098 |
|
|
GMP_INTS_mpz_struct i;
|
2099 |
|
|
|
2100 |
|
|
printf("Testing GMP_INTS_mpz_fac_ui() function.\n");
|
2101 |
|
|
FCMIOF_hline();
|
2102 |
|
|
|
2103 |
|
|
GMP_INTS_mpz_init(&i);
|
2104 |
|
|
|
2105 |
|
|
j = 0;
|
2106 |
|
|
|
2107 |
|
|
|
2108 |
|
|
do
|
2109 |
|
|
{
|
2110 |
|
|
printf("Calculating the factorial of %lu ... ", j);
|
2111 |
|
|
GMP_INTS_mpz_fac_ui(&i, j);
|
2112 |
|
|
printf("Done.\n");
|
2113 |
|
|
GMP_INTS_mpz_long_int_format_to_stream(stdout, &i, "Factorial");
|
2114 |
|
|
FCMIOF_hline();
|
2115 |
|
|
j++;
|
2116 |
|
|
}
|
2117 |
|
|
while (i.size < 55);
|
2118 |
|
|
|
2119 |
|
|
//Destroy the space.
|
2120 |
|
|
GMP_INTS_mpz_clear(&i);
|
2121 |
|
|
|
2122 |
|
|
return(rv);
|
2123 |
|
|
}
|
2124 |
|
|
|
2125 |
|
|
|
2126 |
|
|
int GINTTEST_mpz_pow_ui_test(void)
|
2127 |
|
|
{
|
2128 |
|
|
int rv=0;
|
2129 |
|
|
int i;
|
2130 |
|
|
char *p;
|
2131 |
|
|
int chars_reqd;
|
2132 |
|
|
|
2133 |
|
|
GMP_INTS_mpz_struct arb_base, arb_result;
|
2134 |
|
|
|
2135 |
|
|
//These are the test vectors for testing exponentiation.
|
2136 |
|
|
struct
|
2137 |
|
|
{
|
2138 |
|
|
char *base;
|
2139 |
|
|
unsigned exp;
|
2140 |
|
|
char *result;
|
2141 |
|
|
} tvs[] =
|
2142 |
|
|
{
|
2143 |
|
|
{
|
2144 |
|
|
"0",
|
2145 |
|
|
0,
|
2146 |
|
|
"1"
|
2147 |
|
|
},
|
2148 |
|
|
{
|
2149 |
|
|
"93274374615",
|
2150 |
|
|
0,
|
2151 |
|
|
"1"
|
2152 |
|
|
},
|
2153 |
|
|
{
|
2154 |
|
|
"2",
|
2155 |
|
|
32,
|
2156 |
|
|
"4294967296"
|
2157 |
|
|
},
|
2158 |
|
|
{
|
2159 |
|
|
"10",
|
2160 |
|
|
99,
|
2161 |
|
|
"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
2162 |
|
|
},
|
2163 |
|
|
};
|
2164 |
|
|
|
2165 |
|
|
|
2166 |
|
|
printf("Testing GMP_INTS_mpz_pow_ui() function.\n");
|
2167 |
|
|
FCMIOF_hline();
|
2168 |
|
|
|
2169 |
|
|
//Allocate space for the base and result.
|
2170 |
|
|
GMP_INTS_mpz_init(&arb_base);
|
2171 |
|
|
GMP_INTS_mpz_init(&arb_result);
|
2172 |
|
|
|
2173 |
|
|
for (i=0; i<sizeof(tvs)/sizeof(tvs[0]); i++)
|
2174 |
|
|
{
|
2175 |
|
|
//Assign the base to be the value in the test vectors.
|
2176 |
|
|
GMP_INTS_mpz_set_simple_char_str(&arb_base, tvs[i].base);
|
2177 |
|
|
|
2178 |
|
|
//Calculate the exponential.
|
2179 |
|
|
GMP_INTS_mpz_pow_ui(&arb_result, &arb_base, tvs[i].exp);
|
2180 |
|
|
|
2181 |
|
|
//Figure out how much string space will be required
|
2182 |
|
|
//for the result.
|
2183 |
|
|
chars_reqd = GMP_INTS_mpz_size_in_base_10(&arb_result);
|
2184 |
|
|
|
2185 |
|
|
//Allocate the string space.
|
2186 |
|
|
p = malloc(chars_reqd * sizeof(char));
|
2187 |
|
|
|
2188 |
|
|
//Convert from the arbitary integer to a string.
|
2189 |
|
|
GMP_INTS_mpz_to_string(p, &arb_result);
|
2190 |
|
|
|
2191 |
|
|
//Compare the result of that conversion with the
|
2192 |
|
|
//expected value. If they are different, throw an error.
|
2193 |
|
|
if (strcmp(p, tvs[i].result))
|
2194 |
|
|
rv = 1;
|
2195 |
|
|
|
2196 |
|
|
//Deallocate the string space.
|
2197 |
|
|
free(p);
|
2198 |
|
|
|
2199 |
|
|
//If an error ...
|
2200 |
|
|
if (rv)
|
2201 |
|
|
break;
|
2202 |
|
|
}
|
2203 |
|
|
|
2204 |
|
|
//Deallocate the variables.
|
2205 |
|
|
GMP_INTS_mpz_clear(&arb_base);
|
2206 |
|
|
GMP_INTS_mpz_clear(&arb_result);
|
2207 |
|
|
|
2208 |
|
|
return(rv);
|
2209 |
|
|
}
|
2210 |
|
|
|
2211 |
|
|
|
2212 |
|
|
int GINTTEST_main(void)
|
2213 |
|
|
{
|
2214 |
|
|
int rv;
|
2215 |
|
|
rv = 0;
|
2216 |
|
|
|
2217 |
|
|
printf("Beginning unit testing of GMP_INTS module.\n");
|
2218 |
|
|
|
2219 |
|
|
FCMIOF_hline();
|
2220 |
|
|
|
2221 |
|
|
rv = GINTTEST_mpz_pow_ui_test();
|
2222 |
|
|
if (rv) return(rv);
|
2223 |
|
|
|
2224 |
|
|
rv = GINTTEST_mpz_fac_ui_test();
|
2225 |
|
|
if (rv) return(rv);
|
2226 |
|
|
|
2227 |
|
|
rv = GMP_long_int_format_to_stream_test();
|
2228 |
|
|
if (rv) return(rv);
|
2229 |
|
|
|
2230 |
|
|
rv = GINTTEST_to_string_test();
|
2231 |
|
|
if (rv) return(rv);
|
2232 |
|
|
|
2233 |
|
|
rv = GINTTEST_mpz_tdiv_qr_test();
|
2234 |
|
|
if (rv) return(rv);
|
2235 |
|
|
|
2236 |
|
|
rv = GINTTEST_data_sizes_wrong_test();
|
2237 |
|
|
if (rv) return(rv);
|
2238 |
|
|
|
2239 |
|
|
rv = GINTTEST_alloca_test();
|
2240 |
|
|
if (rv) return(rv);
|
2241 |
|
|
|
2242 |
|
|
rv = GINTTEST_mpn_add_1_test();
|
2243 |
|
|
if (rv) return(rv);
|
2244 |
|
|
|
2245 |
|
|
rv = GINTTEST_mpn_sub_1_test();
|
2246 |
|
|
if (rv) return(rv);
|
2247 |
|
|
|
2248 |
|
|
rv = GINTTEST_mpn_mul_1_test();
|
2249 |
|
|
if (rv) return(rv);
|
2250 |
|
|
|
2251 |
|
|
rv = GINTTEST_mpz_mul_test();
|
2252 |
|
|
if (rv) return(rv);
|
2253 |
|
|
|
2254 |
|
|
rv = GINTTEST_mpz_add_test();
|
2255 |
|
|
if (rv) return(rv);
|
2256 |
|
|
|
2257 |
|
|
rv = GINTTEST_mpz_set_simple_char_str_test();
|
2258 |
|
|
if (rv) return(rv);
|
2259 |
|
|
|
2260 |
|
|
rv = GINTTEST_speed_tests();
|
2261 |
|
|
if (rv) return(rv);
|
2262 |
|
|
|
2263 |
|
|
printf("Ending unit testing of GMP_INTS module.\n");
|
2264 |
|
|
|
2265 |
|
|
FCMIOF_hline();
|
2266 |
|
|
|
2267 |
|
|
return(rv);
|
2268 |
|
|
}
|
2269 |
|
|
|
2270 |
|
|
|
2271 |
|
|
const char *GINTTEST_cvcinfo(void)
|
2272 |
|
|
{
|
2273 |
|
|
return("$Header: /cvsroot/esrg/sfesrg/esrgpcpj/unittest/ginttest.c,v 1.14 2002/05/16 04:21:50 dtashley Exp $");
|
2274 |
|
|
}
|
2275 |
|
|
|
2276 |
|
|
|
2277 |
|
|
const char *GINTTEST_hvcinfo(void)
|
2278 |
|
|
{
|
2279 |
|
|
return(GINTTEST_H_VERSION);
|
2280 |
|
|
}
|
2281 |
|
|
|
2282 |
|
|
|
2283 |
|
|
//**************************************************************************
|
2284 |
|
|
// $Log: ginttest.c,v $
|
2285 |
|
|
// Revision 1.14 2002/05/16 04:21:50 dtashley
|
2286 |
|
|
// Substantial progress on unit test functionality.
|
2287 |
|
|
//
|
2288 |
|
|
// Revision 1.13 2001/07/25 23:40:02 dtashley
|
2289 |
|
|
// Completion of INTFAC program, many changes to handling of large
|
2290 |
|
|
// integers.
|
2291 |
|
|
//
|
2292 |
|
|
// Revision 1.12 2001/07/21 03:32:44 dtashley
|
2293 |
|
|
// Addition of several files.
|
2294 |
|
|
//
|
2295 |
|
|
// Revision 1.11 2001/07/21 01:39:02 dtashley
|
2296 |
|
|
// Safety check-in. Major function to output an integer as rows of digits
|
2297 |
|
|
// has been completed. This was the last major function that needed to be
|
2298 |
|
|
// completed before useful command-line utilities can be constructed.
|
2299 |
|
|
//
|
2300 |
|
|
// Revision 1.10 2001/07/19 20:06:05 dtashley
|
2301 |
|
|
// Division finished. String formatting functions underway. Safety check-in.
|
2302 |
|
|
//
|
2303 |
|
|
// Revision 1.9 2001/07/18 21:53:10 dtashley
|
2304 |
|
|
// Division function finished and passes preliminary tests. Safety check-in.
|
2305 |
|
|
//
|
2306 |
|
|
// Revision 1.8 2001/07/17 22:30:15 dtashley
|
2307 |
|
|
// Safety check-in. Division function under construction.
|
2308 |
|
|
//
|
2309 |
|
|
// Revision 1.7 2001/07/16 17:46:48 dtashley
|
2310 |
|
|
// Multiplication finished, and only indirectly unit-tested. More detailed unit
|
2311 |
|
|
// test must follow, but expect no problems.
|
2312 |
|
|
//
|
2313 |
|
|
// Revision 1.6 2001/07/16 00:28:22 dtashley
|
2314 |
|
|
// Safety check-in. Addition and subtraction functions finished.
|
2315 |
|
|
//
|
2316 |
|
|
// Revision 1.5 2001/07/14 07:03:41 dtashley
|
2317 |
|
|
// Safety check-in. Modifications and progress.
|
2318 |
|
|
//
|
2319 |
|
|
// Revision 1.4 2001/07/14 02:05:03 dtashley
|
2320 |
|
|
// Safety check-in. Almost ready for first unit-testing.
|
2321 |
|
|
//
|
2322 |
|
|
// Revision 1.3 2001/07/13 21:02:20 dtashley
|
2323 |
|
|
// Version control reporting changes.
|
2324 |
|
|
//
|
2325 |
|
|
// Revision 1.2 2001/07/13 19:04:06 dtashley
|
2326 |
|
|
// New files added, plus safety check-in.
|
2327 |
|
|
//
|
2328 |
|
|
// Revision 1.1 2001/07/13 18:17:18 dtashley
|
2329 |
|
|
// Safety check-in. Additionally, new files added.
|
2330 |
|
|
//
|
2331 |
|
|
//**************************************************************************
|
2332 |
|
|
// End of GINTTEST.C. |