diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..53f546d --- /dev/null +++ b/AUTHORS @@ -0,0 +1,6 @@ +Nathalie Revol Nathalie.Revol@ens-lyon.fr +Fabrice Rouillier Fabrice.Rouillier@inria.fr +Sylvain Chevillard Sylvain.Chevillard@ens-lyon.org +Christoph Lauter Christoph.Lauter@ens-lyon.org +Hong Diep Nguyen Hong.Diep.Nguyen@ens-lyon.org +Philippe Theveny Philippe.Theveny@ens-lyon.org diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/COPYING.LESSER b/COPYING.LESSER new file mode 100644 index 0000000..65c5ca8 --- /dev/null +++ b/COPYING.LESSER @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..5303d1c --- /dev/null +++ b/ChangeLog @@ -0,0 +1,364 @@ +2009-04-28 03:00 clauter + + * configure.ac, doc/mpfi.info, doc/mpfi.texi: Changed version + number to something greater than all different version numbers in + the doc etc. Adapted documentation. + +2009-04-28 02:04 clauter + + * ChangeLog, NEWS, README: Some history editing for releasing + +2009-04-22 19:07 schevill + + * README: reverted nothing + +2009-04-22 19:05 schevill + + * README: nothing + +2009-04-22 19:02 schevill + + * configure.ac: + +2009-04-22 19:00 schevill + + * configure.ac: temporary situation with configure.ac + +2009-04-22 17:42 schevill + + * LinSys: Initial repository, after having created the branch for + Diep + +2009-04-22 17:22 schevill + + * AUTHORS: back to a clean situation + +2009-04-22 17:18 schevill + + * AUTHORS: + +2009-04-22 17:11 schevill + + * testFile: + +2009-04-22 17:08 schevill + + * testFile: + +2009-04-22 17:00 schevill + + * testFile: + +2009-04-22 16:58 schevill + + * testFile: + +2009-04-22 16:53 schevill + + * testFile: + +2009-04-22 16:19 schevill + + * testFile: removed testFile + +2009-04-22 16:16 schevill + + * testFile: added a file just for testing purpose + +2009-04-22 16:15 schevill + + * AUTHORS: True list of authors + +2009-04-22 15:47 schevill + + * AUTHORS: + +2009-04-22 15:47 schevill + + * AUTHORS: + +2009-04-22 15:46 schevill + + * AUTHORS: + +2009-04-22 14:48 schevill + + * AUTHORS: + +2009-04-22 14:48 schevill + + * AUTHORS: + +2009-04-22 14:46 schevill + + * AUTHORS: + +2009-04-22 14:46 schevill + + * AUTHORS: + +2009-04-22 14:41 schevill + + * AUTHORS: + +2009-04-22 14:36 schevill + + * AUTHORS: Back to something clean + +2009-04-22 14:17 schevill + + * AUTHORS: + +2009-04-22 13:58 schevill + + * AUTHORS: Another try + +2009-04-22 13:57 schevill + + * AUTHORS: Back to a clean version + +2009-04-22 13:48 schevill + + * AUTHORS: + +2009-04-22 13:43 schevill + + * AUTHORS: + +2009-04-22 13:41 schevill + + * AUTHORS: Another try + +2009-04-22 13:24 schevill + + * AUTHORS: Added Christoph as an author + +2009-04-22 13:08 schevill + + * AUTHORS: Added myself as an author for testing purpose + +2008-07-15 11:13 hnguyen + + * LinSys/src/mpfr_mat.c: change the cancellation test of all the + mpfr matrix operations. Return if encounter nan flag or overflow + flag. The result returned is the flags + +2008-07-07 08:52 hnguyen + + * LinSys/src/matrix_generator.c: read matrix from file + +2008-07-07 08:39 hnguyen + + * LinSys/src/mpfr_mat.c: test initialisation status + +2008-07-07 08:37 hnguyen + + * LinSys/src/mpfr_mat.c, LinSys/src/mpfr_mat.h: test initialisation + status + +2008-06-06 11:04 schevill + + * LinSys/tests/test_mpfi_mat.c, LinSys/tests/test_mpfr_mat.c: + corrected the address of the FSF + +2008-06-06 10:52 schevill + + * COPYING, NEWS, depcomp, missing, src/mpfi-impl.h, src/mpfi.c, + src/mpfi.h, src/mpfi_io.c, src/mpfi_io.h, src/mpfi_trigo.c, + tests/test_mpfi.c, tests/test_trigo.c: corrected the address of + the FSF + +2008-05-30 11:19 hnguyen + + * configure.ac: add LinSys to the compile source + +2008-05-26 14:07 hnguyen + + * LinSys/tests, LinSys/tests/Makefile.am, + LinSys/tests/test_mpfi_mat.c, LinSys/tests/test_mpfr_mat.c: + initial commit for the LinSys module's test + +2008-05-26 14:05 hnguyen + + * LinSys, LinSys/src, LinSys/src/Makefile.am, + LinSys/src/matrix_generator.c, LinSys/src/matrix_generator.h, + LinSys/src/mpfi_mat.c, LinSys/src/mpfi_mat.h, + LinSys/src/mpfi_mat_io.c, LinSys/src/mpfi_mat_lss.c, + LinSys/src/mpfi_mat_norm.c, LinSys/src/mpfr_mat.c, + LinSys/src/mpfr_mat.h: initial commit for the LinSys module + +2007-11-27 11:42 schevill + + * src/mpfi.c: Put back the previous version of functions modified + by C. Q. Lauter + (modifications were useless). + +2007-11-27 09:30 schevill + + * tests/test_mpfi, tests/test_trigo: Removed binary files that + should not be in the CVS repository. + +2007-11-26 17:04 clauter + + * src/mpfi.c, tests/test_mpfi, tests/test_trigo: Corrected + precision issues in si and d. Todo: z and q. + +2007-11-23 16:49 clauter + + * src/mpfi.c, tests/test_mpfi, tests/test_trigo: Corrected three + bugs in ui - functions. + +2007-11-23 15:57 clauter + + * src/mpfi.c, tests/test_mpfi, tests/test_trigo: Added a / in + beginning of mpfi.c for making compilation possible + +2007-11-23 15:17 schevill + + * src/mpfi.c: In mpfi_diam_rel, replaced an assignment in variable + diam by an + assignment in a temporary variable to avoid possible conflict + between + input and output variables. + +2007-11-23 13:12 schevill + + * src/mpfi_io.c, tests/test_mpfi, tests/test_trigo: Added + suggestion of Carl Witty for mpfi_set_str (strlen is now computed + only once ; a test asserts that the input string is not too long + for the + buffer). + +2007-11-22 16:31 schevill + + * README: Added an instruction about LD_LIBRARY_PATH in README. + I personnally did not know that I had to add /usr/local/lib to my + LD_LIBRARY_PATH in order for mpfi to run. + + Note that this concerns shared library only. Since we now compile + both + shared and static library, the error may happen for former users + when + upgrading their installation. That is why I think it is important + to + inform users in README. + +2007-11-22 15:33 schevill + + * Makefile.in, aclocal.m4, config.guess, config.sub, configure, + doc/Makefile.in, src/Makefile.in, tests/Makefile.in: Removing + files that should not be in a CVS repository: this files are + automatically generated and their content depends on the + configuration + of each user. + +2007-11-22 15:08 schevill + + * src/mpfi_io.c, tests/test_mpfi, tests/test_trigo: Fixed bug 1847 + submitted by Julien Clement concerning mpfi_set_str when + a single number was passed as argument. I am not totally + convinced that + this function is correct when a number is stored in an interval + with + more precision at its left endpoint than at its right endpoint. + Should + be checked. + +2007-11-21 18:26 schevill + + * src/mpfi.c, tests/test_mpfi, tests/test_trigo: Fixed bug 2004: + mpfi_diam_rel used to compute an absolute diameter. + There remain mysteries about this function. + +2007-11-21 17:48 schevill + + * src/mpfi.c, tests/test_mpfi, tests/test_trigo: mpfi.c: fixed a + bug in mpfi_ui_sub in the case a-0. + +2007-11-21 09:38 schevill + + * src/mpfi.c: Fixed bug number 4219 about incorrect bounds in + mpfi_ui_sub. + +2007-11-16 10:21 schevill + + * src/mpfi-impl.h, src/mpfi.c, src/mpfi.h, src/mpfi_trigo.c, + tests/test_mpfi, tests/test_trigo: Corrected a bug reported by + Carl Witty: MPFR_SIGN and mpfr_sgn do not have the same behavior + on 0. The right function to use was mpfr_sgn + Replaced mpfi_mpz_exact_set_fr by mpfr_get_z that have exactly + the same semantic. + +2007-10-29 13:18 schevill + + * Makefile.in, aclocal.m4, autogen.sh, config.guess, config.sub, + configure, configure.ac, doc/Makefile.in, mpfi_config.h.in, + src/Makefile.am, src/Makefile.in, src/mpfi_trigo.c, + tests/Makefile.am, tests/Makefile.in, tests/test_mpfi, + tests/test_trigo: Added autogen.sh: just run ./autogen.sh to + generate a new configure file after having + modified a Makefile.am or configure.ac + + The configure file in CVS is now up to date + + Patched a bug in mpfi_trigo.c affecting mpfi_sin when called on a + symetrical + interval + + Patched an old bug in mpfi_trigo.c in function + mpfi_mpz_exact_set_fr + This bug had already been patched once since the RC available as + a tgz on mpfi's + web page is correct. + It is quite surprising to find this bug in the CVS... + + Corrected the version number in configure.ac + + Patched configure.ac and some Makefile.am in order to use libtool + to + generate a dynamic library. + + Warning: the libraries are now compiled in src/.libs/ + +2006-06-07 21:21 rouillie + + * src/mpfi.h, src/mpfi_io.h: *** empty log message *** + +2006-01-03 09:09 rouillie + + * configure, configure.ac, doc/mpfi.info, doc/mpfi.texi, + src/mpfi-impl.h, src/mpfi.c, src/mpfi.h: *configure.ac : modify + the help for --with-mpfr-dir option + *mpfi-impl.h/mpfi.h : put the flags return by mpfi function into + mpfi.h + *modify the documentation of mpfi_cmp + *add the function char * mpfi_get_version() + +2005-11-22 16:23 rouillie + + * configure, configure.ac, doc/mpfi.info, src/mpfi.c, + src/mpfi_io.c, src/mpfi_trigo.c: Some *_ui* functions have been + upgraded + +2005-11-20 06:55 rouillie + + * AUTHORS, Makefile.in, aclocal.m4, configure, configure.ac, + doc/Makefile.in, src/Makefile.in, src/mpfi-impl.h, src/mpfi.c, + src/mpfi_io.c, src/mpfi_io.h, tests/Makefile.in, + tests/test_mpfi.c, tests/test_trigo.c: Modifications suggested by + the SPACES project. + MPFI is now compatible with mpfr-2.2.0 + +2005-11-08 17:24 rouillie + + * ., AUTHORS, COPYING, ChangeLog, INSTALL, Makefile.am, + Makefile.in, NEWS, README, aclocal.m4, config.guess, config.sub, + configure, configure.ac, depcomp, doc, doc/Makefile.am, + doc/Makefile.in, doc/mpfi.info, doc/mpfi.texi, install-sh, + missing, mkinstalldirs, mpfi_config.h.in, src, src/Makefile.am, + src/Makefile.in, src/mpfi-impl.h, src/mpfi.c, src/mpfi.h, + src/mpfi_io.c, src/mpfi_io.h, src/mpfi_trigo.c, tests, + tests/Makefile.am, tests/Makefile.in, tests/test_mpfi, + tests/test_mpfi.c, tests/test_trigo, tests/test_trigo.c: Initial + Release + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..b7fb1b6 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,5 @@ +ACLOCAL_AMFLAGS = -I m4 +SUBDIRS = src tests doc + +include_HEADERS = src/mpfi.h src/mpfi_io.h +EXTRA_DIST = mpfi_config.h.in diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..c615dd3 --- /dev/null +++ b/NEWS @@ -0,0 +1,91 @@ +Copyright 1999, 2000, 2001, 2002 - 2009, 2010, 2018 + OURAGAN project, Inria Paris, France + and ARIC project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA + +Changes between MPFI version 1.5.3 and 1.5.4 +* MPFI now requires MPFR 3.0 or higher +* mp_exp_t replaced by mpfr_exp_t, mp_prec_t replaced by mpfr_prec_t, mp_rnd_t replaced by mpfr_rnd_t + GMP_RNDx replaced by MPFR_RNDx +* incorporation of "new" functionalities offered by MPFR since MPFR version 2.4.2: + +Changes between MPFI version 1.5.2 and 1.5.3 +* compatible with MPFR version 4.0.0 +* minor warnings removed + +Changes between MPFI version 1.5 and 1.5.2 +* allow compilation as a DLL with Cygwin and Mingw on windows platforms + (reported by Jean-Pierre Flori) +* fix documentation of comparison functions (reported by Keith BRIGGS) +* fix bug in mpfi_sub_fr (reported by Takayuki YAMAGUCHI) +* now require at least GMP version 4.1.0 and MPFR version 2.4.2 +* new symbols MPFI_VERSION_MAJOR, MPFI_VERSION_MINOR, MPFI_VERSION_PATCHLEVEL, + and MPFI_VERSION_STRING in mpfi.h +* detect availability of mpfr_z_sub, mpfr_z_div, and mpfr_q_sub and use a + custom implementation for the ones not provided by MPFR (mpfr_z_sub appeared + in MPFR 3.1.0, the other ones are used in tests only) +* code cleanup (unused variables) +* tadd_q does no more check overflow by default (required too much memory) +* sign of zeros choice documented + +Changes between MPFI version 1.4 and 1.5 + +* new functions : Catalan's constant, cubic root, secant, cosecant, cotangent + and hyperbolic counterparts, atan2, hypot, get_version, urandom +* new test suite (99.7% LOC) +* can now be compiled outside the source directory +* change configure options to be consistent with the ones in MPFR and MPC: + --with-gmp-dir=DIR changed to --with-gmp=DIR + --with-gmp-libpath=DIR changed to --with-gmp-lib=DIR + --with-gmp-incpath=DIR changed to --with-gmp-include=DIR + --with-mpfr-dir=DIR changed to --with-mpfr=DIR + --with-mpfr-libpath=DIR changed to --with-mpfr-lib=DIR + --with-mpfr-incpath=DIR changed to --with-mpfr-include=DIR +* now require at least GMP version 4.1.0 and MPFR version 2.4.0 +* each function is in its own file (compile_time *= 8;) +* limitation to 1000 characters in mpfi_set_str removed. +* fix documentation for functions mpfi_blow, mpfi_is_inside at least. +* fix bug in mpfi_ui_sub when reusing a variable (bug reported by + Sisyphus 2010-01-19). +* fix bug in mpfi_blow: the result could be underestimated when the factor was + small compared to 1. +* fix double rounding error in basic arithmetic functions with a non-interval + parameter (like mpfi_add_si). +* the following functions now return 0 (false) if one or more of their + operands is NaN or has a NaN as an endpoint : mpfi_is_inside, + mpfi_is_inside_d, mpfi_is_inside_ui, mpfi_is_inside_si, mpfi_is_inside_z, + mpfi_is_inside_q, mpfi_is_inside_fr, mpfi_is_pos, mpfi_is_strictly_pos, + mpfi_is_nonneg, mpfi_is_neg, mpfi_is_strictly_neg, mpfi_is_nonpos, + mpfi_inf_p, mpfi_bounded_p + +Changes between MPFI 1.3.4-RC3 and 1.4 + +* bugfixes for trigonometric functions +* add compilation for a shared library + +Changes between MPFI version 1.1 and 1.3.4-RC3 + +* mainly, keep on par with new developments in MPFR during these years + +Changes between MPFI version 1.0 and 1.1 + +* GNU autoconf/automake standards +* mpfi-impl.h (non exported internal macros) diff --git a/README b/README new file mode 100644 index 0000000..658ecef --- /dev/null +++ b/README @@ -0,0 +1,41 @@ +To install MPFI library : + +For the impatient user, type in the source directory: + +./configure +make +make install + +This will install shared and static versions of libmpfi in the default install +directory. Read INSTALL in the source directory for details. + + +CONFIGURE EXTRA OPTIONS +(read INSTALL for general options) +You can specify the GMP and MPFR installation directories with the following +configure options: +--with-gmp= +--with-mpfr= + + +TEST FAILURE +With GMP 5.0.x, you may experience a failure in tcbrt like the following: + +rootrem.c:339: GNU MP assertion failed: bn>= qn +/bin/sh: line 5: 27307 Aborted ${dir}$tst +FAIL: tcbrt + +This is probably due to the fact that gcc version 4.3.2 miscompiles GMP +5.0.x. There is nothing to do but to recompile GMP with another version of gcc. + + +IMPORTANT: +Note that default installation path is /usr/local/lib. +If you configured MPFI with --prefix=some/path or if you are using a distribution +like Debian, the library may not be found at running time. + +If you compile a soft using mpfi and have an error at execution time such as: + +error while loading shared libraries: libmpfi.so.0: cannot open shared object file: No such file or directory + +try adding /some/path (or /usr/local/lib in the case of Debian) to LD_LIBRARY_PATH diff --git a/README.dev b/README.dev new file mode 100644 index 0000000..18e7e4c --- /dev/null +++ b/README.dev @@ -0,0 +1,40 @@ + +to compile MPFI from the repository, type the following commands: +$ autoreconf -i +$ ./configure --with-gmp=/path/to/gmp --with-mpfr=/path/to/mpfr +$ make +$ make check + + +to make a new release: +1) create a new branch in the repository +$ svn copy \ + svn+ssh://username@scm.gforge.inria.fr/svn/mpfi/trunk/mpfi \ + svn+ssh://username@scm.gforge.inria.fr/svn/mpfi/branches/1.5 \ + -m "Create branch 1.5" +2) Update version number in configure.ac, in doc/mpfi.texi, and in src/mpfi.h + in the new branch. Update the date in doc/mpfi.texi. +3) Update the NEWS file. +4) Build new packages for the release version in three formats (tar.gz, + tar.bz2 and zip): +$ make dist + or to build and check new packages +$ make distcheck +5) Check the release version on different machines. +6) For the release, create a tag: +$ svn copy \ + svn+ssh://username@scm.gforge.inria.fr/svn/mpfi/branches/1.5 \ + svn+ssh://username@scm.gforge.inria.fr/svn/mpfi/tags/1.5 + -m "Tag release 1.5" +7) Update version in the trunk. + + +to build HTML pages containing the source code annotated with LOC coverage of + the test suite, you need the MPFI sources from the subversion repository + (the coverage utility is not distributed in release packages), a gcc + compatible compiler, and you need to install the lcov tool + (http://ltp.sourceforge.net/coverage/lcov.php). + Then type in the MPFI source directory: +$ ./coverage . +This will generate the coverage report and print the location of the HTML + pages (a /tmp subdirectory). diff --git a/README.md b/README.md deleted file mode 100644 index 9ebb840..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# template-repository \ No newline at end of file diff --git a/TODO b/TODO new file mode 100644 index 0000000..b7ca5f0 --- /dev/null +++ b/TODO @@ -0,0 +1,58 @@ +* set_sj and set_uj + 2018-31-07 +I tried... and failed, to add mpfi_set_sj and mpfi_set_uj: +setting an interval from a huge interval. Pb with compilation: apparently I did not get how to test whether +the corresponding types (intmax_t and uintmax_t) are known, or not, by the compiler. +Everything is ready: the code for these functions, some tests (actually, the same as for set_si and set_ui, +thus more cases, and especially cornercases, should be added) and the lines in the Makefile.am. Makefile.in +are already written. But it does not compile... so far. + +* Fix predicates +From: "Sisyphus" +To: "philippe theveny" , + +Subject: mpfi-1.4: Some surprises wrt nans +Date: Mon, 1 Feb 2010 21:26:01 +1100 + +Hi, + +Here's the demo prog: + +############################### +#include +#include +#include + +int main(void) { +mpfi_t x; + +mpfi_init(x); +mpfi_out_str(stdout, 10, 0, x); + +printf("\n%d %d %d %d %d %d\n", + mpfi_is_pos(x), + mpfi_is_strictly_pos(x), + mpfi_is_nonneg(x), + mpfi_is_neg(x), + mpfi_is_strictly_neg(x), + mpfi_is_nonpos(x)); + +return 0; +} + +############################### + +It shows that mpfi_is_pos(), mpfi_is_strictly_pos(), mpfi_is_nonneg(), +mpfi_is_neg(), mpfi_is_strictly_neg() and mpfi_is_nonpos() all return true +for nans. + +I expected that they all would return false .... though there might be some +room for debate on that as regards nonpos and nonneg. + +(Btw, there's no need for any patches - I can wait for the next release. +Main purpose of this post is just to make sure you're aware of this +behaviour.) + +Cheers, +Rob +------ diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..80f01ad --- /dev/null +++ b/configure.ac @@ -0,0 +1,131 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.65) +AC_INIT([mpfi],[1.5.4],[mpfi-users@lists.gforge.inria.fr],[mpfi],[https://gforge.inria.fr/projects/mpfi/]) +AC_CONFIG_SRCDIR([src/mpfi.h]) +AC_CONFIG_HEADERS([mpfi_config.h]) + +AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_AUX_DIR([build-aux]) +AC_USE_SYSTEM_EXTENSIONS +AM_INIT_AUTOMAKE([1.9 -Wall -Werror dist-bzip2 dist-zip]) +AM_SILENT_RULES([no]) +AM_MAINTAINER_MODE([]) + +dnl Extra arguments to configure +AC_ARG_WITH([mpfr_include], + [AS_HELP_STRING([--with-mpfr-include=DIR],[MPFR include directory])], + [CPPFLAGS="-I$withval $CPPFLAGS"]) +AC_ARG_WITH([mpfr_lib], + [AS_HELP_STRING([--with-mpfr-lib=DIR],[MPFR lib directory])], + [LDFLAGS="-L$withval $LDFLAGS"]) +AC_ARG_WITH([mpfr], + [AS_HELP_STRING([--with-mpfr=DIR],[MPFR install directory])], + [ + if test -z "$with_mpfr_include" -a -z "$with_mpfr_lib" ; then + CPPFLAGS="-I$withval/include $CPPFLAGS" + LDFLAGS="-L$withval/lib $LDFLAGS" + else + AC_MSG_FAILURE([Do not use --with-mpfr and --with-mpfr-include/--with-mpfr-lib options simultaneously.]) + fi + ]) +AC_ARG_WITH([gmp_include], + [AS_HELP_STRING([--with-gmp-include=DIR],[GMP include directory])], + [CPPFLAGS="-I$withval $CPPFLAGS"]) +AC_ARG_WITH([gmp_lib], + [AS_HELP_STRING([--with-gmp-lib=DIR],[GMP lib directory])], + [LDFLAGS="-L$withval $LDFLAGS"]) +AC_ARG_WITH([gmp], + [AS_HELP_STRING([--with-gmp=DIR],[GMP install directory])], + [ + if test -z "$with_gmp_lib" -a -z "$with_gmp_include" ; then + CPPFLAGS="-I$withval/include $CPPFLAGS" + LDFLAGS="-L$withval/lib $LDFLAGS" + else + AC_MSG_FAILURE([Do not use --with-gmp and --with-gmp-include/--with-gmp-lib options simultaneously.]) + fi + ]) + +# Checks for programs. +AC_PROG_CC +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +AM_PROG_AR +LT_INIT + +# Checks for libraries. +dnl Check GMP Header +AC_MSG_CHECKING(for gmp.h) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ +#include "gmp.h" +]])],[AC_MSG_RESULT(yes)],[ + AC_MSG_RESULT(no) + AC_MSG_ERROR([gmp.h can't be found, or is unusable.]) +]) + +AC_CHECK_LIB([gmp], [__gmpz_init], + [LIBS="-lgmp $LIBS"], + [AC_MSG_ERROR([libgmp not found.])]) + +AC_MSG_CHECKING(for valid GMP) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include "gmp.h" +#if (__GNU_MP_VERSION*100+__GNU_MP_VERSION_MINOR*10 < 410) +# error "min: GMP 4.1.0" +#endif +]], [[]])],[AC_MSG_RESULT(yes)],[ + AC_MSG_RESULT(no) + AC_MSG_ERROR([GMP 4.1.0 min required]) +]) + +dnl Check MPFR Header +AC_MSG_CHECKING(for mpfr.h) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ +#include "mpfr.h" +]])],[AC_MSG_RESULT(yes)],[ + AC_MSG_RESULT(no) + AC_MSG_ERROR([mpfr.h can't be found, or is unusable.]) +]) + +AC_CHECK_LIB([mpfr], [mpfr_init], + [LIBS="-lmpfr $LIBS"], + [AC_MSG_ERROR([libmpfr not found.])]) + +AC_MSG_CHECKING(for valid MPFR) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include "mpfr.h" +#if (MPFR_VERSION < MPFR_VERSION_NUM(2,4,2)) +# error "min: MPFR 2.4.2" +#endif +]], [[]])],[AC_MSG_RESULT(yes)],[ + AC_MSG_RESULT(no) + AC_MSG_ERROR([MPFR 2.4.2 min required]) +]) + +# Checks for header files. +AC_CHECK_HEADERS([float.h limits.h stdlib.h string.h sys/time.h unistd.h]) +AC_CHECK_HEADER([stdarg.h],[AC_DEFINE([HAVE_STDARG],1,[Define if stdarg])], + [AC_CHECK_HEADER([varargs.h],, + AC_MSG_ERROR([stdarg.h or varargs.h not found]))]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_SIZE_T + +# Checks for library functions. +AC_CHECK_FUNCS([dup2 gettimeofday]) +AC_CHECK_FUNCS([mpfr_q_sub mpfr_z_sub mpfr_z_div]) + +case $AC_PACKAGE_VERSION in + *-dev) + AC_DEFINE([WARN_IF_REVERTED_ENDPOINTS], 1, + [Define to 1 if it is a development version.]);; +esac + +AC_CONFIG_FILES([Makefile + doc/Makefile + src/Makefile + tests/Makefile]) +AC_OUTPUT diff --git a/debian/README.source b/debian/README.source new file mode 100644 index 0000000..ff62706 --- /dev/null +++ b/debian/README.source @@ -0,0 +1,6 @@ +The upstream source tarball of version 1.5.4 is actually inadequately archived. +The upstream team corrected the issue a month ago. For all theses reasons the +debian-source tarball was exceptionally created by hand. The d/watch file was +not modified and (2) that the Files-Excluded list was respected. + + -- Jerome Benoit Tue, 19 Mar 2024 20:49:07 +0000 diff --git a/debian/adhoc/examples/Makefile b/debian/adhoc/examples/Makefile new file mode 100644 index 0000000..d8cc7d8 --- /dev/null +++ b/debian/adhoc/examples/Makefile @@ -0,0 +1,39 @@ +# /usr/share/doc/libmpfi-doc/examples/Makefile +# +# Ad hoc Makefile for building and playing with the sample sources +# distributed within the debian package libmpfi-doc. +# +# Recommended usage: +# create a dedicated folder somewhere in your HOME directory; +# link all the files in /usr/share/doc/libmpfi-doc/examples in the dedicated folder; +# launch this Makefile in the dedicated folder: +# $ make ; +# for a basic cleanup, consider the clean target: +# $ make clean ; +# for an entire cleanup, the maintainer-clean target: +# $ make maintainer-clean ; +# for other targets, just read the Makefile. +# +# written for Debian by Jerome Benoit +# on behalf of the Debian Science Team +# copyright: 2016-2024 Jerome Benoit +# distributed under the terms and conditions of GPL version 2 or later +# + +PROGRAMS = $(patsubst %.c,%,$(wildcard *.c)) + +default: all + +LDLIBS = -lmpfi -lmpfr -lgmp -lm + +all: build + +build: $(PROGRAMS) + +check: build + @$(foreach eg, $(PROGRAMS), echo "*** $(eg) ***" ; ./$(eg) ; ) + +clean: + $(RM) $(PROGRAMS) + +maintainer-clean: clean diff --git a/debian/adhoc/examples/mpfi_example_pi.c b/debian/adhoc/examples/mpfi_example_pi.c new file mode 100644 index 0000000..d077cfe --- /dev/null +++ b/debian/adhoc/examples/mpfi_example_pi.c @@ -0,0 +1,44 @@ +/* /usr/share/doc/libmpfi-doc/examples/mpfi_example_pi.c */ + +/* + * Ad hoc source sample for illustrating the use of the library mpfi + * + * Build and launch: + * $ gcc -o mpfi_example_pi mpfi_example_pi.c -lmpfi -lmpfr -lgmp -lm + * $ ./mpfi_example_pi + * + * Written for Debian by Jerome Benoit on behalf of the Debian Science Team + * Copyright: 2016-2024 Jerome Benoit + * Distributed under the terms and conditions of GPL version 2 or later + */ + +#include + +#include +#include + +#define ADHOC_DEFAULT_PRECISION 512 + +int main(void) { + mpfi_t one; + mpfi_t four_atan_one; + + mpfr_set_default_prec(ADHOC_DEFAULT_PRECISION); + + mpfi_init(one); + mpfi_init(four_atan_one); + + mpfi_set_ui(one,1UL); + + mpfi_atan(four_atan_one,one); + mpfi_mul_ui(four_atan_one,four_atan_one,4UL); + + fprintf(stdout,"4 atan(1): "); + mpfi_out_str(stdout,10,0,four_atan_one); + fprintf(stdout,"\n"); + + + mpfi_clear(four_atan_one); + mpfi_clear(one); + + return 0; } diff --git a/debian/adhoc/examples/mpfi_version.c b/debian/adhoc/examples/mpfi_version.c new file mode 100644 index 0000000..9fc5740 --- /dev/null +++ b/debian/adhoc/examples/mpfi_version.c @@ -0,0 +1,39 @@ +/* /usr/share/doc/libmpfi-doc/examples/mpfi_version.c */ + +/* + * Ad hoc source sample for illustrating the use of the library mpfi + * + * Build and launch: + * $ gcc -o mpfi_version mpfi_version.c -lmpfi -lmpfr -lgmp -lm + * $ ./mpfi_version + * + * Written for Debian by Jerome Benoit on behalf of the Debian Science Team + * Copyright: 2016-2024 Jerome Benoit + * Distributed under the terms and conditions of GPL version 2 or later + */ + +#include +#include + +#include + +int main(void) { + const char *adhoc_mpfi_lib_version=mpfi_get_version(); + int status=0; + + if (strcmp(MPFI_VERSION_STRING,adhoc_mpfi_lib_version)) { + fprintf(stderr, + "header and library version mismatch: " MPFI_VERSION_STRING " vs %s\n", + adhoc_mpfi_lib_version + ); + status=1; + } +#if 1 + else { + fprintf(stdout, + "header and library version match: " MPFI_VERSION_STRING "\n" + ); + } +#endif + + return (status); } diff --git a/debian/changelog b/debian/changelog index bad88e2..4796366 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,354 @@ -template-repository (1.0-1) unstable; urgency=medium +mpfi (1.5.4+ds-4) unstable; urgency=medium - * Initial release + * FTBFS fix release, technical typo in test/type_js introduced type mismatch + (Closes: #1086340). + * Debianization: + - d/patches/*: + - d/p/upstream-fix-tests-gcc14-technical_typo.patch, introduced. - -- Tsic404 Sat, 28 Jan 2023 13:46:49 +0800 + -- Jerome Benoit Sun, 10 Nov 2024 19:59:30 +0000 + +mpfi (1.5.4+ds-3) unstable; urgency=medium + + * Debianization: + - d/watch, correct; + - d/control: + - Standards-Version, bump to version 4.7.0 (no change); + + -- Jerome Benoit Sat, 18 May 2024 11:20:38 +0000 + +mpfi (1.5.4+ds-2) unstable; urgency=medium + + * Debianization: + - d/patches/*: + - d/p/upstream-tests-set_ld-not64bits-SKIP.patch, introduce. + + -- Jerome Benoit Thu, 21 Mar 2024 01:40:56 +0000 + +mpfi (1.5.4+ds-1) unstable; urgency=medium + + * New upstream nano release (Closes: #1067068). + * Debianization: + - d/libmpfi0.symbols, refresh; + - d/p/upstream-source-cleanup.patch, introduce; + - d/a/examples, copyright year-tuples, update; + - d/README.source, introduce. + + -- Jerome Benoit Tue, 19 Mar 2024 20:50:48 +0000 + +mpfi (1.5.3+ds-7) unstable; urgency=medium + + [ Debian Janitor ] + * Remove constraints unnecessary since buster (oldstable): + + Build-Depends: Drop versioned constraint on cproto, libgmp-dev and + libmpfr-dev. + + libmpfi-dev: Drop versioned constraint on libmpfi-dev and libmpfi0-dev in + Conflicts. + + libmpfi-dev: Drop versioned constraint on libmpfi0-dev in Replaces. + + libmpfi-dev-common: Drop versioned constraint on libmpfi-dev in Replaces. + + libmpfi-dev-common: Drop versioned constraint on libmpfi-dev in Breaks. + + libmpfi-doc: Drop versioned constraint on libmpfi-dev in Replaces. + + libmpfi-doc: Drop versioned constraint on libmpfi-dev in Breaks. + * Remove an obsolete maintscript entry. + * Update renamed lintian tag names in lintian overrides. + + [ Jerome Benoit ] + * Update standards version to 4.6.2, no changes needed. + * libmpfi-dev{,-common}: Discard lintian-overrides. + * Update copyright year-tuples. + + libmpfi-dev-common: move to Replaces/Conflicts scheme + without versioned constraint. + + -- Jerome Benoit Mon, 18 Mar 2024 10:40:59 +0000 + +mpfi (1.5.3+ds-6) unstable; urgency=medium + + * Debianization: + - d/control: + - Homepage field, update; + - debhelper, migrate to version 13 (discar d/compat); + - Standards-Version, bump to version 4.6.0 (no change); + - d/rules: + - override_dh_missing target, provide; + - d/copyright: + - Upstream-Contact field, refresh; + - Source field, update; + - copyright year tuples, update; + - d/patches: + - d/p/debianization-examples.patch, provide Forwarded field; + - d/watch, migration to gitlab.inria.fr. + + -- Jerome Benoit Fri, 15 Oct 2021 08:03:28 +0000 + +mpfi (1.5.3+ds-5) unstable; urgency=medium + + * SBF: correct Maintainer address (Closes: #970758). + * Debianization: + - debian/control: + - Maintainer address, correct; + - Homepage URI, secure; + - debian/copyright: + - Format URI, correct. + + -- Jerome Benoit Mon, 02 Nov 2020 20:52:39 +0000 + +mpfi (1.5.3+ds-4) unstable; urgency=medium + + * Debianization: + - debian/copyright: + - copyright year tuples, update; + - debian/control: + - Maintainer address, update; + - Rules-Requires-Root, introduce and set to no; + - Standards Version, bump to 4.5.0 (no change); + - debian/tests: + - d/t/build-examples, use AUTOPKGTEST_TMP ; + - debian/rules: + - override_dh_auto_build-indep target, compose; + - override_dh_auto_install-indep target, fix; + - debian/patches: + - d/p/debianization.patch, introduce (Closes: #959697). + + -- Jerome Benoit Tue, 05 May 2020 20:12:00 +0000 + +mpfi (1.5.3+ds-3) unstable; urgency=medium + + * Debianization: + - debian/control: + - debhelper, bump to 12; + - Standards Version, bump to 4.4.0 (no change); + - libmpfi0-dev, discard (Closes: #940733); + - Vcs-* fields, migration to Salsa; + - debian/libmpfi0.symbols: + - Build-Depends-Package, introduce; + - debian/rules: + - get-orig-source target, discard. + + -- Jerome Benoit Thu, 26 Sep 2019 20:13:03 +0000 + +mpfi (1.5.3+ds-2) unstable; urgency=medium + + * RC bug fix release (Closes: #888560), harden d/control. + * Debianization: + - debian/control: see above; + - debian/source/lintian-overrides, tag, rename. + + -- Jerome Benoit Sat, 27 Jan 2018 13:25:14 +0000 + +mpfi (1.5.3+ds-1) unstable; urgency=medium + + * New upstream release. + * Debianization: + - debian/copyright: + - Files-Excluded field, update; + - format URI, secure; + - debian/patches/*: + - d/p/upstream-autotools-refresh.patch , + - d/p/upstream-libtoolization-version_script.patch , update; + - d/p/upstream-fix-version_mismatch.patch , + d/p/upstream-source-warnings-silence.patch , + d/p/upstream-source-system_wide_includes.patch , integrated, + thanks to the upstream team. + + -- Jerome Benoit Thu, 18 Jan 2018 19:18:11 +0000 + +mpfi (1.5.2+ds-1) unstable; urgency=medium + + * New upstream release. + * Debianization: + - debian/copyright: + - Sources field, URI, secure; + - Files-Excluded field, refresh; + - copyright date, refresh; + - debian/control: + - debhelper, bump to 11; + - Standards Version, bump to 4.1.3 (no change); + - Priority field, reset from extra to optional; + - debian/watch, bump to version 4; + - debian/rules: + - debhelper, bump to 11; + - get-orig-source target, simplify; + - override_dh_install(doc|example)s: + --doc-main-package set up to libmpfi-doc; + - debian/patches/*: + - d/p/upstream-autotools-refresh.patch, update; + - d/p/upstream-libtoolization-version_script.patch, update; + - d/p/upstream-fix-version_mismatch.patch, introduce; + - debian/adhoc/*, correct and refresh. + + -- Jerome Benoit Sat, 13 Jan 2018 06:06:29 +0000 + +mpfi (1.5.1+ds-4) unstable; urgency=medium + + * RC bug fix release (Closes: #825600), harden libdev transition. + + -- Jerome Benoit Sat, 04 Jun 2016 12:01:08 +0000 + +mpfi (1.5.1+ds-3) unstable; urgency=medium + + * Debianization: + - debian/copyright, refresh; + - debian/control: + - Standards Version, bump to 3.9.8 (no change); + - Vcs-*, secure; + - debug symbol package, drop off in favour of automatic generation; + - SONNAME/SOINDEX being removed from libdev package names, initiate; + - debian/rules: + - dpkg-buildflags, add hardening=+all; + - debug symbol package, drop off (see above); + - symlink policy for documentation directories, set; + - debian/adhoc/examples, introduce; + - debian/tests/*, introduce. + + -- Jerome Benoit Mon, 09 May 2016 23:22:08 +0000 + +mpfi (1.5.1+ds-2) unstable; urgency=medium + + * RC bug fix release (Closes: #790509), stabilize libdev transition. + + -- Jerome Benoit Tue, 30 Jun 2015 11:40:07 +0000 + +mpfi (1.5.1+ds-1) unstable; urgency=medium + + * New maintainer (Closes: #771883). + * Debianization: + - debian/copyright: + - in DEP-5 format, bump; + - Files-Excluded field, introduce; + - refresh; + - debian/control: + - debhelper build-dep to >= 9, bump; + - Standards Version 3.9.6, bump; + - Build-Depends field, refresh; + - Multi-Arch support, achieve (Closes: 737387); + - Vcs-* headers, refresh; + - debian/watch, provide; + - debian/rules: + - full dh integration, refresh; + - build-arch/build-indep scheme, introduce; + - get-orig-source uscan based target which downloads the currently + packaged upstream tarball and repacks it wrt Files-Excluded; + - default target which basically queries package status with uscan + -- output in DEHS format; + - debian/patches/: + - patches in DEP-3 format; + - autotoolization, refresh; + - libtoolization: + - script-version, create on fly; + - library versionning, introduce; + - minor and cosmetic fixes; + - gpg-signature check support, neutralize. + + -- Jerome Benoit Wed, 17 Jun 2015 12:22:05 +0000 + +mpfi (1.5.1-3) unstable; urgency=medium + + * Apply patch by Logan Rosen to fix FTBFS on ppc64el (closes: #734570). + + -- Laurent Fousse Sun, 09 Feb 2014 14:03:28 -0800 + +mpfi (1.5.1-2) unstable; urgency=low + + * Apply patch from Ubuntu fixing build for AArch64 + (closes: #727466). + + -- Laurent Fousse Wed, 13 Nov 2013 20:38:39 -0800 + +mpfi (1.5.1-1) unstable; urgency=low + + * New upstream release: + + Fixes bug in sub_fr (closes: #674341). + + Remove patch already applied upstream. + + -- Laurent Fousse Sat, 26 May 2012 01:55:23 +0000 + +mpfi (1.5-5) unstable; urgency=low + + * Properly switch to quilt format (closes: #643220). + + -- Laurent Fousse Tue, 27 Sep 2011 22:05:52 +0200 + +mpfi (1.5-4) unstable; urgency=low + + * Build-depends on the new libgmp-dev package. + + -- Laurent Fousse Sun, 06 Mar 2011 22:23:11 +0100 + +mpfi (1.5-3) unstable; urgency=low + + * Apply patch by Nobuhiro Iwamatsu, fixing build on sh4 + (closes: #593420). + + -- Laurent Fousse Wed, 18 Aug 2010 21:52:37 +0200 + +mpfi (1.5-2) unstable; urgency=low + + * Apply patch by Philippe Theveny to fix tis_zero. + + -- Laurent Fousse Fri, 13 Aug 2010 16:11:44 +0200 + +mpfi (1.5-1) unstable; urgency=low + + * New upstream version. + * Added Vcs-* links. + + -- Laurent Fousse Fri, 13 Aug 2010 14:09:16 +0200 + +mpfi (1.5~r525-1) unstable; urgency=low + + * New upstream snapshot. + + -- Laurent Fousse Tue, 27 Jul 2010 21:34:37 +0200 + +mpfi (1.4-1) unstable; urgency=low + + * New upstream version. + * Switch to quilt format. + * Remove references to mpfr_random (closes: #590355). + * Upgrade Standard-Version to 3.9.0 (no change needed). + + -- Laurent Fousse Mon, 26 Jul 2010 14:11:18 +0200 + +mpfi (1.3.4~rc4~cvs20080519-1) unstable; urgency=low + + * Package current CVS version. + * Add new dynamic library package (closes: #474080). + * Upgrade Standard-Version to 3.7.3 (no change needed). + * Drop cdbs. + + -- Laurent Fousse Fri, 23 May 2008 16:18:30 +0200 + +mpfi (1.3.4~rc3-1) unstable; urgency=low + + * New upstream release candidate. + * Upgrade Standard-Version to 3.7.2 (no change needed). + + -- Laurent Fousse Mon, 22 Oct 2007 14:40:41 +0200 + +mpfi (1.3.3-4) unstable; urgency=low + + * Apply patch submitted by Sylvain Chevillard to fix + a bug in trigonometric functions (closes: #400909). + + -- Laurent Fousse Thu, 4 Jan 2007 16:48:22 +0100 + +mpfi (1.3.3-3) unstable; urgency=low + + * Apply mpfr-2.2.0 compatibility patch supplied by Patrick Pelissier + (closes: #336703). + + -- Laurent Fousse Tue, 1 Nov 2005 11:13:48 +0100 + +mpfi (1.3.3-2) unstable; urgency=low + + * Changed packaging to use cdbs. + * Applied patch by Guillaume Melquiond to make mpfi usable with C++ code. + * The description is now more explicit on the fact it is a library. + + -- Laurent Fousse Mon, 5 Sep 2005 11:26:05 +0200 + +mpfi (1.3.3-1) unstable; urgency=low + + * Initial release (closes: #322534). + + -- Laurent Fousse Wed, 10 Aug 2005 15:47:28 +0200 diff --git a/debian/clean b/debian/clean new file mode 100644 index 0000000..8eed217 --- /dev/null +++ b/debian/clean @@ -0,0 +1 @@ +doc/mpfi.info diff --git a/debian/compat b/debian/compat deleted file mode 100644 index b4de394..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -11 diff --git a/debian/control b/debian/control index cb7c4a0..3aed934 100644 --- a/debian/control +++ b/debian/control @@ -1,15 +1,134 @@ -Source: template-repository -Section: unknown +Source: mpfi +Section: math Priority: optional -Maintainer: Tsic404 -Build-Depends: debhelper (>= 11) -Standards-Version: 4.1.3 -Homepage: https://github.com/deepin-community/template-repository -#Vcs-Browser: https://salsa.debian.org/debian/deepin-community-template-repository -#Vcs-Git: https://salsa.debian.org/debian/deepin-community-template-repository.git - -Package: template-repository +Maintainer: Debian Science Maintainers +Uploaders: Jerome Benoit +Rules-Requires-Root: no +Build-Depends: + debhelper-compat (= 13), + gnulib, libtool, cproto, + libmpfr-dev, libgmp-dev +Build-Depends-Indep: + texinfo, texlive-latex-base +Standards-Version: 4.7.0 +Homepage: https://gitlab.inria.fr/mpfi/mpfi +Vcs-Git: https://salsa.debian.org/science-team/mpfi.git +Vcs-Browser: https://salsa.debian.org/science-team/mpfi + +Package: libmpfi0 +Provides: libmpfi +Replaces: libmpfi (<< 1.5.1+ds-1) +Section: libs Architecture: any +Pre-Depends: ${misc:Pre-Depends} Depends: ${shlibs:Depends}, ${misc:Depends} -Description: - +Conflicts: libmpfi +Suggests: libmpfi-doc (= ${source:Version}) +Multi-Arch: same +Description: multiple precision floating-point interval computation library -- lib + This package provides a C library of functions for interval arithmetic + computations with arbitrary precision. + . + The basic principle of interval arithmetic consists in enclosing every number + by an interval containing it and being representable by machine numbers: for + instance it can be stored as its lower and upper endpoints and these bounds + are machine numbers, or as a centre and a radius which are machine numbers. + . + The arithmetic operations are extended for interval operands in such a way + that the exact result of the operation belongs to the computed interval. + . + The purpose of an arbitrary precision interval arithmetic is on the one hand + to get guaranteed results, thanks to interval computation, and on the other + hand to obtain accurate results, thanks to multiple precision arithmetic. The + MPFI library is built upon MPFR in order to benefit from the correct roundings + provided by MPFR. Further advantages of using MPFR are its portability and + compliance with the IEEE 754 standard for floating-point arithmetic. + . + This package provides the dynamic library. + +Package: libmpfi-dev +Section: libdevel +Architecture: any +Pre-Depends: ${misc:Pre-Depends} +Depends: + libmpfi0 (= ${binary:Version}), libmpfi-dev-common (= ${source:Version}), + libmpfr-dev, libgmp-dev, ${misc:Depends} +Multi-Arch: same +Description: multiple precision floating-point interval computation library -- libdev + This package provides a C library of functions for interval arithmetic + computations with arbitrary precision. + . + The basic principle of interval arithmetic consists in enclosing every number + by an interval containing it and being representable by machine numbers: for + instance it can be stored as its lower and upper endpoints and these bounds + are machine numbers, or as a centre and a radius which are machine numbers. + . + The arithmetic operations are extended for interval operands in such a way + that the exact result of the operation belongs to the computed interval. + . + The purpose of an arbitrary precision interval arithmetic is on the one hand + to get guaranteed results, thanks to interval computation, and on the other + hand to obtain accurate results, thanks to multiple precision arithmetic. The + MPFI library is built upon MPFR in order to benefit from the correct roundings + provided by MPFR. Further advantages of using MPFR are its portability and + compliance with the IEEE 754 standard for floating-point arithmetic. + . + This package provides the static library and symbolic links needed for + development. + +Package: libmpfi-dev-common +Section: libdevel +Architecture: all +Replaces: libmpfi0-dev-common +Breaks: libmpfi0-dev-common +Pre-Depends: ${misc:Pre-Depends} +Depends: ${misc:Depends} +Suggests: libmpfi-dev +Multi-Arch: foreign +Description: multiple precision floating-point interval computation library -- headers + This package provides a C library of functions for interval arithmetic + computations with arbitrary precision. + . + The basic principle of interval arithmetic consists in enclosing every number + by an interval containing it and being representable by machine numbers: for + instance it can be stored as its lower and upper endpoints and these bounds + are machine numbers, or as a centre and a radius which are machine numbers. + . + The arithmetic operations are extended for interval operands in such a way + that the exact result of the operation belongs to the computed interval. + . + The purpose of an arbitrary precision interval arithmetic is on the one hand + to get guaranteed results, thanks to interval computation, and on the other + hand to obtain accurate results, thanks to multiple precision arithmetic. The + MPFI library is built upon MPFR in order to benefit from the correct roundings + provided by MPFR. Further advantages of using MPFR are its portability and + compliance with the IEEE 754 standard for floating-point arithmetic. + . + This package provides the headers needed by developers. + +Package: libmpfi-doc +Section: doc +Architecture: all +Depends: ${misc:Depends} +Suggests: libmpfi-dev, pdf-viewer +Multi-Arch: foreign +Description: multiple precision floating-point interval computation library -- doc + This package provides a C library of functions for interval arithmetic + computations with arbitrary precision. + . + The basic principle of interval arithmetic consists in enclosing every number + by an interval containing it and being representable by machine numbers: for + instance it can be stored as its lower and upper endpoints and these bounds + are machine numbers, or as a centre and a radius which are machine numbers. + . + The arithmetic operations are extended for interval operands in such a way + that the exact result of the operation belongs to the computed interval. + . + The purpose of an arbitrary precision interval arithmetic is on the one hand + to get guaranteed results, thanks to interval computation, and on the other + hand to obtain accurate results, thanks to multiple precision arithmetic. The + MPFI library is built upon MPFR in order to benefit from the correct roundings + provided by MPFR. Further advantages of using MPFR are its portability and + compliance with the IEEE 754 standard for floating-point arithmetic. + . + This package provides the user manual. diff --git a/debian/copyright b/debian/copyright index f5c805e..87b5d08 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,9 +1,90 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: template-repository -Source: https://github.com/deepin-community/template-repository +Upstream-Name: mpfi +Upstream-Contact: + Nathalie Revol + Fabrice Rouillier +Source: https://gitlab.inria.fr/mpfi/mpfi +Files-Excluded: + doc/mpfi.info + doc/Makefile.in + tests/Makefile.in + src/Makefile.in + m4/ltversion.m4 + m4/ltoptions.m4 + m4/libtool.m4 + m4/ltsugar.m4 + m4/lt~obsolete.m4 + aclocal.m4 + mpfi_config.h.in + Makefile.in + build-aux/missing + build-aux/ltmain.sh + build-aux/test-driver + build-aux/install-sh + build-aux/ar-lib + build-aux/compile + build-aux/depcomp + build-aux/config.sub + build-aux/config.guess + configure + INSTALL Files: * -Copyright: 2023 Tsic404 +Copyright: + 1999-2024 Spaces and Arenaire INRIA projects, Lab. ANO - USTL +License: LGPL-2.1+ + +Files: + tests/random.c + tests/mpfi-tests.c +Copyright: + 1999-2021 Spaces and Arenaire INRIA projects, Lab. ANO - USTL +License: LGPL-2+ + +Files: debian/* +Copyright: + 2015-2024 Jerome Benoit + 2005-2014 Laurent Fousse +License: GPL-2+ +Comment: + This package was originally debianized by Laurent Fousse + on Wed 2005-08-10. + +License: LGPL-2+ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + . + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + . + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . + . + On Debian system, the complete text of the GNU Lesser General Public + License version 2 can be found in "/usr/share/common-licenses/LGPL-2". + +License: LGPL-2.1+ + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1, or (at your option) + any later version. + . + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + . + You should have received a copy of the GNU Lesser General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + . + On Debian systems, the complete text of the GNU Lesser General Public + License version 2.1 can be found in "/usr/share/common-licenses/LGPL-2.1". + License: GPL-2+ This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -12,11 +93,11 @@ License: GPL-2+ . This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . You should have received a copy of the GNU General Public License - along with this program. If not, see + along with this package. If not, see . . On Debian systems, the complete text of the GNU General Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". diff --git a/debian/libmpfi-dev-common.install b/debian/libmpfi-dev-common.install new file mode 100644 index 0000000..e5c00da --- /dev/null +++ b/debian/libmpfi-dev-common.install @@ -0,0 +1 @@ +usr/include/*.h diff --git a/debian/libmpfi-dev.install b/debian/libmpfi-dev.install new file mode 100644 index 0000000..e8d5488 --- /dev/null +++ b/debian/libmpfi-dev.install @@ -0,0 +1,3 @@ +usr/lib/*/libmpfi.so +usr/lib/*/libmpfi.a +#usr/lib/*/pkgconfig/* diff --git a/debian/libmpfi-doc.doc-base b/debian/libmpfi-doc.doc-base new file mode 100644 index 0000000..f478214 --- /dev/null +++ b/debian/libmpfi-doc.doc-base @@ -0,0 +1,30 @@ +Document: mpfi +Title: MPFI: Multiple Precision Floating-Point Interval Library +Author: + Nathalie Revol + Fabrice Rouillier + Sylvain Chevillard + Christoph Lauter + Hong Diep Nguyen + Philippe Theveny +Section: Science/Mathematics +Abstract: + The basic principle of interval arithmetic consists in enclosing every number + by an interval containing it and being representable by machine numbers: for + instance it can be stored as its lower and upper endpoints and these bounds + are machine numbers, or as a centre and a radius which are machine numbers. + . + The arithmetic operations are extended for interval operands in such a way + that the exact result of the operation belongs to the computed interval. + . + MPFI is intended to be a portable library written in C for arbitrary precision + interval arithmetic with intervals represented using MPFR reliable floating-point + numbers. It is based on the GNU MP library and on the MPFR library. The purpose of + an arbitrary precision interval arithmetic is on the one hand to get guaranteed + results, thanks to interval computation, and on the other hand to obtain accurate + results, thanks to multiple precision arithmetic. The MPFI library is built upon MPFR + in order to benefit from the correct rounding provided, for each operation or function, + by MPFR. + +Format: PDF +Files: /usr/share/doc/libmpfi-doc/mpfi.pdf diff --git a/debian/libmpfi-doc.docs b/debian/libmpfi-doc.docs new file mode 100644 index 0000000..17fce66 --- /dev/null +++ b/debian/libmpfi-doc.docs @@ -0,0 +1,2 @@ +NEWS +debian/tmp/usr/share/doc/mpfi/mpfi.pdf diff --git a/debian/libmpfi-doc.examples b/debian/libmpfi-doc.examples new file mode 100644 index 0000000..8c0890a --- /dev/null +++ b/debian/libmpfi-doc.examples @@ -0,0 +1 @@ +debian/adhoc/examples/* diff --git a/debian/libmpfi-doc.info b/debian/libmpfi-doc.info new file mode 100644 index 0000000..f740e12 --- /dev/null +++ b/debian/libmpfi-doc.info @@ -0,0 +1 @@ +debian/tmp/usr/share/info/mpfi.info diff --git a/debian/libmpfi0.install b/debian/libmpfi0.install new file mode 100644 index 0000000..fe882d5 --- /dev/null +++ b/debian/libmpfi0.install @@ -0,0 +1 @@ +usr/lib/*/libmpfi.so.* diff --git a/debian/libmpfi0.symbols b/debian/libmpfi0.symbols new file mode 100644 index 0000000..1a1f50e --- /dev/null +++ b/debian/libmpfi0.symbols @@ -0,0 +1,184 @@ +libmpfi.so.0 libmpfi0 #MINVER# +* Build-Depends-Package: libmpfi-dev + LIBMPFI_0.0.0@LIBMPFI_0.0.0 1.5.1 + mpfi_abs@LIBMPFI_0.0.0 1.5.1 + mpfi_acos@LIBMPFI_0.0.0 1.5.1 + mpfi_acosh@LIBMPFI_0.0.0 1.5.1 + mpfi_add@LIBMPFI_0.0.0 1.5.1 + mpfi_add_d@LIBMPFI_0.0.0 1.5.1 + mpfi_add_fr@LIBMPFI_0.0.0 1.5.1 + mpfi_add_q@LIBMPFI_0.0.0 1.5.1 + mpfi_add_si@LIBMPFI_0.0.0 1.5.1 + mpfi_add_ui@LIBMPFI_0.0.0 1.5.1 + mpfi_add_z@LIBMPFI_0.0.0 1.5.1 + mpfi_alea@LIBMPFI_0.0.0 1.5.1 + mpfi_asin@LIBMPFI_0.0.0 1.5.1 + mpfi_asinh@LIBMPFI_0.0.0 1.5.1 + mpfi_atan2@LIBMPFI_0.0.0 1.5.1 + mpfi_atan@LIBMPFI_0.0.0 1.5.1 + mpfi_atanh@LIBMPFI_0.0.0 1.5.1 + mpfi_bisect@LIBMPFI_0.0.0 1.5.1 + mpfi_blow@LIBMPFI_0.0.0 1.5.1 + mpfi_bounded_p@LIBMPFI_0.0.0 1.5.1 + mpfi_cbrt@LIBMPFI_0.0.0 1.5.1 + mpfi_clear@LIBMPFI_0.0.0 1.5.1 + mpfi_clears@LIBMPFI_0.0.0 1.5.4 + mpfi_cmp@LIBMPFI_0.0.0 1.5.1 + mpfi_cmp_d@LIBMPFI_0.0.0 1.5.1 + mpfi_cmp_fr@LIBMPFI_0.0.0 1.5.1 + mpfi_cmp_q@LIBMPFI_0.0.0 1.5.1 + mpfi_cmp_si@LIBMPFI_0.0.0 1.5.1 + mpfi_cmp_ui@LIBMPFI_0.0.0 1.5.1 + mpfi_cmp_z@LIBMPFI_0.0.0 1.5.1 + mpfi_const_catalan@LIBMPFI_0.0.0 1.5.1 + mpfi_const_euler@LIBMPFI_0.0.0 1.5.1 + mpfi_const_log2@LIBMPFI_0.0.0 1.5.1 + mpfi_const_pi@LIBMPFI_0.0.0 1.5.1 + mpfi_cos@LIBMPFI_0.0.0 1.5.1 + mpfi_cosh@LIBMPFI_0.0.0 1.5.1 + mpfi_cot@LIBMPFI_0.0.0 1.5.1 + mpfi_coth@LIBMPFI_0.0.0 1.5.1 + mpfi_csc@LIBMPFI_0.0.0 1.5.1 + mpfi_csch@LIBMPFI_0.0.0 1.5.1 + mpfi_d_div@LIBMPFI_0.0.0 1.5.1 + mpfi_d_sub@LIBMPFI_0.0.0 1.5.1 + mpfi_diam@LIBMPFI_0.0.0 1.5.1 + mpfi_diam_abs@LIBMPFI_0.0.0 1.5.1 + mpfi_diam_rel@LIBMPFI_0.0.0 1.5.1 + mpfi_div@LIBMPFI_0.0.0 1.5.1 + mpfi_div_2exp@LIBMPFI_0.0.0 1.5.1 + mpfi_div_2si@LIBMPFI_0.0.0 1.5.1 + mpfi_div_2ui@LIBMPFI_0.0.0 1.5.1 + mpfi_div_d@LIBMPFI_0.0.0 1.5.1 + mpfi_div_fr@LIBMPFI_0.0.0 1.5.1 + mpfi_div_q@LIBMPFI_0.0.0 1.5.1 + mpfi_div_si@LIBMPFI_0.0.0 1.5.1 + mpfi_div_ui@LIBMPFI_0.0.0 1.5.1 + mpfi_div_z@LIBMPFI_0.0.0 1.5.1 + mpfi_erandom@LIBMPFI_0.0.0 1.5.4 + mpfi_error@LIBMPFI_0.0.0 1.5.1 + mpfi_exp2@LIBMPFI_0.0.0 1.5.1 + mpfi_exp@LIBMPFI_0.0.0 1.5.1 + mpfi_expm1@LIBMPFI_0.0.0 1.5.1 + mpfi_fr_div@LIBMPFI_0.0.0 1.5.1 + mpfi_fr_sub@LIBMPFI_0.0.0 1.5.1 + mpfi_get_d@LIBMPFI_0.0.0 1.5.1 + mpfi_get_fr@LIBMPFI_0.0.0 1.5.1 + mpfi_get_left@LIBMPFI_0.0.0 1.5.1 + mpfi_get_prec@LIBMPFI_0.0.0 1.5.1 + mpfi_get_right@LIBMPFI_0.0.0 1.5.1 + mpfi_get_version@LIBMPFI_0.0.0 1.5.1 + mpfi_has_zero@LIBMPFI_0.0.0 1.5.1 + mpfi_hypot@LIBMPFI_0.0.0 1.5.1 + mpfi_increase@LIBMPFI_0.0.0 1.5.1 + mpfi_inf_p@LIBMPFI_0.0.0 1.5.1 + mpfi_init2@LIBMPFI_0.0.0 1.5.1 + mpfi_init@LIBMPFI_0.0.0 1.5.1 + mpfi_init_set@LIBMPFI_0.0.0 1.5.1 + mpfi_init_set_d@LIBMPFI_0.0.0 1.5.1 + mpfi_init_set_flt@LIBMPFI_0.0.0 1.5.4 + mpfi_init_set_fr@LIBMPFI_0.0.0 1.5.1 + mpfi_init_set_ld@LIBMPFI_0.0.0 1.5.4 + mpfi_init_set_q@LIBMPFI_0.0.0 1.5.1 + mpfi_init_set_si@LIBMPFI_0.0.0 1.5.1 + mpfi_init_set_str@LIBMPFI_0.0.0 1.5.1 + mpfi_init_set_ui@LIBMPFI_0.0.0 1.5.1 + mpfi_init_set_z@LIBMPFI_0.0.0 1.5.1 + mpfi_inits2@LIBMPFI_0.0.0 1.5.4 + mpfi_inits@LIBMPFI_0.0.0 1.5.4 + mpfi_inp_str@LIBMPFI_0.0.0 1.5.1 + mpfi_intersect@LIBMPFI_0.0.0 1.5.1 + mpfi_interv_d@LIBMPFI_0.0.0 1.5.1 + mpfi_interv_fr@LIBMPFI_0.0.0 1.5.1 + mpfi_interv_q@LIBMPFI_0.0.0 1.5.1 + mpfi_interv_si@LIBMPFI_0.0.0 1.5.1 + mpfi_interv_ui@LIBMPFI_0.0.0 1.5.1 + mpfi_interv_z@LIBMPFI_0.0.0 1.5.1 + mpfi_inv@LIBMPFI_0.0.0 1.5.1 + mpfi_is_empty@LIBMPFI_0.0.0 1.5.1 + mpfi_is_error@LIBMPFI_0.0.0 1.5.1 + mpfi_is_inside@LIBMPFI_0.0.0 1.5.1 + mpfi_is_inside_d@LIBMPFI_0.0.0 1.5.1 + mpfi_is_inside_fr@LIBMPFI_0.0.0 1.5.1 + mpfi_is_inside_q@LIBMPFI_0.0.0 1.5.1 + mpfi_is_inside_si@LIBMPFI_0.0.0 1.5.1 + mpfi_is_inside_ui@LIBMPFI_0.0.0 1.5.1 + mpfi_is_inside_z@LIBMPFI_0.0.0 1.5.1 + mpfi_is_neg@LIBMPFI_0.0.0 1.5.1 + mpfi_is_nonneg@LIBMPFI_0.0.0 1.5.1 + mpfi_is_nonpos@LIBMPFI_0.0.0 1.5.1 + mpfi_is_pos@LIBMPFI_0.0.0 1.5.1 + mpfi_is_strictly_inside@LIBMPFI_0.0.0 1.5.1 + mpfi_is_strictly_neg@LIBMPFI_0.0.0 1.5.1 + mpfi_is_strictly_pos@LIBMPFI_0.0.0 1.5.1 + mpfi_is_zero@LIBMPFI_0.0.0 1.5.1 + mpfi_log10@LIBMPFI_0.0.0 1.5.1 + mpfi_log1p@LIBMPFI_0.0.0 1.5.1 + mpfi_log2@LIBMPFI_0.0.0 1.5.1 + mpfi_log@LIBMPFI_0.0.0 1.5.1 + mpfi_mag@LIBMPFI_0.0.0 1.5.1 + mpfi_mid@LIBMPFI_0.0.0 1.5.1 + mpfi_mig@LIBMPFI_0.0.0 1.5.1 + mpfi_mul@LIBMPFI_0.0.0 1.5.1 + mpfi_mul_2exp@LIBMPFI_0.0.0 1.5.1 + mpfi_mul_2si@LIBMPFI_0.0.0 1.5.1 + mpfi_mul_2ui@LIBMPFI_0.0.0 1.5.1 + mpfi_mul_d@LIBMPFI_0.0.0 1.5.1 + mpfi_mul_fr@LIBMPFI_0.0.0 1.5.1 + mpfi_mul_q@LIBMPFI_0.0.0 1.5.1 + mpfi_mul_si@LIBMPFI_0.0.0 1.5.1 + mpfi_mul_ui@LIBMPFI_0.0.0 1.5.1 + mpfi_mul_z@LIBMPFI_0.0.0 1.5.1 + mpfi_nan_p@LIBMPFI_0.0.0 1.5.1 + mpfi_neg@LIBMPFI_0.0.0 1.5.1 + mpfi_nrandom@LIBMPFI_0.0.0 1.5.4 + mpfi_out_str@LIBMPFI_0.0.0 1.5.1 + mpfi_print_binary@LIBMPFI_0.0.0 1.5.1 + mpfi_put@LIBMPFI_0.0.0 1.5.1 + mpfi_put_d@LIBMPFI_0.0.0 1.5.1 + mpfi_put_fr@LIBMPFI_0.0.0 1.5.1 + mpfi_put_q@LIBMPFI_0.0.0 1.5.1 + mpfi_put_si@LIBMPFI_0.0.0 1.5.1 + mpfi_put_ui@LIBMPFI_0.0.0 1.5.1 + mpfi_put_z@LIBMPFI_0.0.0 1.5.1 + mpfi_q_div@LIBMPFI_0.0.0 1.5.1 + mpfi_q_sub@LIBMPFI_0.0.0 1.5.1 + mpfi_reset_error@LIBMPFI_0.0.0 1.5.1 + mpfi_revert_if_needed@LIBMPFI_0.0.0 1.5.1 + mpfi_round_prec@LIBMPFI_0.0.0 1.5.1 + mpfi_sec@LIBMPFI_0.0.0 1.5.1 + mpfi_sech@LIBMPFI_0.0.0 1.5.1 + mpfi_set@LIBMPFI_0.0.0 1.5.1 + mpfi_set_d@LIBMPFI_0.0.0 1.5.1 + mpfi_set_error@LIBMPFI_0.0.0 1.5.1 + mpfi_set_flt@LIBMPFI_0.0.0 1.5.4 + mpfi_set_fr@LIBMPFI_0.0.0 1.5.1 + mpfi_set_ld@LIBMPFI_0.0.0 1.5.4 + mpfi_set_prec@LIBMPFI_0.0.0 1.5.1 + mpfi_set_q@LIBMPFI_0.0.0 1.5.1 + mpfi_set_si@LIBMPFI_0.0.0 1.5.1 + mpfi_set_str@LIBMPFI_0.0.0 1.5.1 + mpfi_set_ui@LIBMPFI_0.0.0 1.5.1 + mpfi_set_z@LIBMPFI_0.0.0 1.5.1 + mpfi_si_div@LIBMPFI_0.0.0 1.5.1 + mpfi_si_sub@LIBMPFI_0.0.0 1.5.1 + mpfi_sin@LIBMPFI_0.0.0 1.5.1 + mpfi_sinh@LIBMPFI_0.0.0 1.5.1 + mpfi_sqr@LIBMPFI_0.0.0 1.5.1 + mpfi_sqrt@LIBMPFI_0.0.0 1.5.1 + mpfi_sub@LIBMPFI_0.0.0 1.5.1 + mpfi_sub_d@LIBMPFI_0.0.0 1.5.1 + mpfi_sub_fr@LIBMPFI_0.0.0 1.5.1 + mpfi_sub_q@LIBMPFI_0.0.0 1.5.1 + mpfi_sub_si@LIBMPFI_0.0.0 1.5.1 + mpfi_sub_ui@LIBMPFI_0.0.0 1.5.1 + mpfi_sub_z@LIBMPFI_0.0.0 1.5.1 + mpfi_swap@LIBMPFI_0.0.0 1.5.1 + mpfi_tan@LIBMPFI_0.0.0 1.5.1 + mpfi_tanh@LIBMPFI_0.0.0 1.5.1 + mpfi_ui_div@LIBMPFI_0.0.0 1.5.1 + mpfi_ui_sub@LIBMPFI_0.0.0 1.5.1 + mpfi_union@LIBMPFI_0.0.0 1.5.1 + mpfi_urandom@LIBMPFI_0.0.0 1.5.1 + mpfi_z_div@LIBMPFI_0.0.0 1.5.1 + mpfi_z_sub@LIBMPFI_0.0.0 1.5.1 diff --git a/debian/patches/debianization.patch b/debian/patches/debianization.patch new file mode 100644 index 0000000..0384daa --- /dev/null +++ b/debian/patches/debianization.patch @@ -0,0 +1,18 @@ +Description: debianization + Meant to maintain a minimal debian/rules, to fix warnings, + to address Debian specific stuff in general. +Origin: debian +Forwarded: not-needed +Author: Jerome Benoit +Last-Update: 2020-05-06 + +--- a/Makefile.am ++++ b/Makefile.am +@@ -4,6 +4,6 @@ + + ACLOCAL_AMFLAGS = -I m4 + +-SUBDIRS = src tests doc ++SUBDIRS = src tests #doc + + EXTRA_DIST = mpfi_config.h.in diff --git a/debian/patches/series b/debian/patches/series new file mode 100644 index 0000000..e6c7daa --- /dev/null +++ b/debian/patches/series @@ -0,0 +1,6 @@ +upstream-fix-tests-gcc14-technical_typo.patch +upstream-source-cleanup.patch +upstream-tests-set_ld-not64bits-SKIP.patch +upstream-autotools-refresh.patch +upstream-libtoolization-version_script.patch +debianization.patch diff --git a/debian/patches/upstream-autotools-refresh.patch b/debian/patches/upstream-autotools-refresh.patch new file mode 100644 index 0000000..b0bccbf --- /dev/null +++ b/debian/patches/upstream-autotools-refresh.patch @@ -0,0 +1,46 @@ +Description: upstream -- autotoolization: refresh + Attempt to refresh and rationalize further the autotools machinery; + meant to be submitted to the upstream maintainer team. +Origin: debian +Author: Jerome Benoit +Last-Update: 2018-01-17 + +--- a/configure.ac ++++ b/configure.ac +@@ -9,10 +9,13 @@ + AC_CONFIG_MACRO_DIR([m4]) + AC_CONFIG_AUX_DIR([build-aux]) + AC_USE_SYSTEM_EXTENSIONS +-AM_INIT_AUTOMAKE([1.9 -Wall -Werror dist-bzip2 dist-zip]) ++AM_INIT_AUTOMAKE([1.9 -Wall dist-bzip2 dist-zip]) + AM_SILENT_RULES([no]) + AM_MAINTAINER_MODE([]) + ++# Check for which system. ++AC_CANONICAL_HOST ++ + dnl Extra arguments to configure + AC_ARG_WITH([mpfr_include], + [AS_HELP_STRING([--with-mpfr-include=DIR],[MPFR include directory])], +--- a/doc/Makefile.am ++++ b/doc/Makefile.am +@@ -1,2 +1 @@ + info_TEXINFOS = mpfi.texi +-TEXINFO_TEX = ../texinfo.tex +--- a/Makefile.am ++++ b/Makefile.am +@@ -1,5 +1,5 @@ + ACLOCAL_AMFLAGS = -I m4 ++ + SUBDIRS = src tests doc + +-include_HEADERS = src/mpfi.h src/mpfi_io.h + EXTRA_DIST = mpfi_config.h.in +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -1,3 +1,5 @@ ++include_HEADERS = mpfi.h mpfi_io.h ++ + lib_LTLIBRARIES = libmpfi.la + + # apparently the type "intmax_t" s not always known diff --git a/debian/patches/upstream-fix-tests-gcc14-technical_typo.patch b/debian/patches/upstream-fix-tests-gcc14-technical_typo.patch new file mode 100644 index 0000000..b9c2e59 --- /dev/null +++ b/debian/patches/upstream-fix-tests-gcc14-technical_typo.patch @@ -0,0 +1,20 @@ +Description: upstream: fix: tests: type_js: technical typo + Correct a technical typo that, on some 32bits architectures, + introduces a type mismatch. This issue was detected with gcc 14 + (see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1086340). +Origin: debian +Forwarded: by-email +Author: Jerome Benoit +Last-Update: 2024-10-10 + +--- a/tests/type_js.c ++++ b/tests/type_js.c +@@ -42,7 +42,7 @@ + /* [2] expected value */ + read_mpfi (fp, expected); + /* [3] integral operand */ +- read_sj (fp, &(MPFI_FUN_ARG (*this, 3, si))); ++ read_sj (fp, &(MPFI_FUN_ARG (*this, 3, sj))); + + /* data validation */ + if (mpfi_get_prec (got) != mpfi_get_prec (expected)) { diff --git a/debian/patches/upstream-libtoolization-version_script.patch b/debian/patches/upstream-libtoolization-version_script.patch new file mode 100644 index 0000000..0e90509 --- /dev/null +++ b/debian/patches/upstream-libtoolization-version_script.patch @@ -0,0 +1,71 @@ +Description: upstream -- libtoolization -- version script support + Provides version scripts [1] for the shipped libraries. The map + (or version script) is basically generated from the package headers + with the help of cproto(1). The version scripts are generated on the + fly thought the [auto]make machinery (in maintainer-mode). + Meant to be submitted to the upstream maintainer team. + [1] https://www.gnu.org/software/gnulib/manual/html_node/LD-Version-Scripts.html +Origin: debian +Author: Jerome Benoit +Last-Update: 2018-01-17 + +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -1,3 +1,5 @@ ++CPROTO = cproto ++ + include_HEADERS = mpfi.h mpfi_io.h + + lib_LTLIBRARIES = libmpfi.la +@@ -56,3 +58,29 @@ + libmpfi_la_LDFLAGS = -no-undefined + + AM_CPPFLAGS =-I$(top_srcdir) ++ ++libmpfi_la_LD_VERSION_SCRIPT= ++if HAVE_LD_VERSION_SCRIPT ++libmpfi_la_LD_VERSION_SCRIPT+= -Wl,--version-script=mpfi.map ++endif ++ ++libmpfi_la_LDFLAGS += -version-info $(LIBMPFI_LT_VERSION) $(libmpfi_la_LD_VERSION_SCRIPT) ++ ++if MAINTAINER_MODE ++ ++BUILT_SOURCES = mpfi.map ++ ++mpfi.map: $(include_HEADERS) ++ ++endif ++ ++EXTRA_DIST = $(BUILT_SOURCES) ++MAINTAINERCLEANFILES = $(BUILT_SOURCES) ++ ++%.map : ++ _MAPNAME=$$(echo $(patsubst %.map,%,$@) | tr '[a-z]' '[A-Z]') ; \ ++ printf "LIB%s_%d.%d.%d {\nglobal:\n" $$_MAPNAME $(subst :, ,$(LIBMPFI_LT_VERSION)) > $@ ; ++ $(CPROTO) -I$(top_srcdir)/src -X 1 -f 0 $^ | \ ++ sed '/^\/\*/d;s/(\*\([_a-z0-9]*\))/\1/g;s/()//g;s/\*//g' | rev | cut -d ' ' -f1 | rev | sort -u \ ++ >> $@ ++ printf "\nlocal: *;\n};\n" >> $@ +--- a/Makefile.am ++++ b/Makefile.am +@@ -1,3 +1,7 @@ ++## Library versioning (C:R:A == current:revision:age) ++export LIBMPFI_LT_VERSION = 0:0:0 ++ ++ + ACLOCAL_AMFLAGS = -I m4 + + SUBDIRS = src tests doc +--- a/configure.ac ++++ b/configure.ac +@@ -16,6 +16,9 @@ + # Check for which system. + AC_CANONICAL_HOST + ++# check linker script support ++gl_LD_VERSION_SCRIPT ++ + dnl Extra arguments to configure + AC_ARG_WITH([mpfr_include], + [AS_HELP_STRING([--with-mpfr-include=DIR],[MPFR include directory])], diff --git a/debian/patches/upstream-source-cleanup.patch b/debian/patches/upstream-source-cleanup.patch new file mode 100644 index 0000000..9d3f4e2 --- /dev/null +++ b/debian/patches/upstream-source-cleanup.patch @@ -0,0 +1,48 @@ +Description: upstream -- source: clean up + Discard obsoleted bit of codes. +Origin: debian +Forwarded: no needed +Author: Jerome Benoit +Last-Update: 2024-03-19 + +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -32,7 +32,7 @@ + asin.c asinh.c atan2.c atan.c atanh.c bisect.c blow.c \ + cbrt.c clear.c clears.c cmp.c cmp_sym_pi.c constants.c cos.c \ + cosh.c csc.c csch.c cot.c coth.c d_div.c d_sub.c diam.c \ +- div.c div_2exp.c div_2si.c div_2ui.c div_d.c div_ext.c div_fr.c \ ++ div.c div_2exp.c div_2si.c div_2ui.c div_d.c div_fr.c \ + div_q.c div_si.c div_ui.c div_z.c erandom.c error.c exp.c \ + exp2.c expm1.c fr_div.c fr_sub.c get_endpoints.c get_fr.c \ + get_d.c get_prec.c get_version.c has_zero.c hypot.c \ +--- a/tests/Makefile.am ++++ b/tests/Makefile.am +@@ -3,7 +3,7 @@ + + check_LTLIBRARIES = libmpfi-tests.la + libmpfi_tests_la_SOURCES = mpfi-tests.h read_data.c random.c \ +- type_i.c type_ii.c type_iii.c type_iiii.c type_iu.c type_is.c \ ++ type_i.c type_ii.c type_iii.c type_iu.c type_is.c \ + type_id.c type_if.c type_il.c type_iz.c type_iq.c type_ir.c type_iiu.c \ + type_iis.c type_iid.c type_iiz.c type_iiq.c type_iir.c \ + type_iui.c type_isi.c type_idi.c type_izi.c type_iqi.c \ +@@ -40,7 +40,7 @@ + tcmp_fr tcmp_q tcmp_si tcmp_ui tcmp_z tconst_catalan \ + tconst_euler tconst_log2 tconst_pi tcos tcosh tcot tcoth \ + tcsc tcsch td_div td_sub tdiam tdiam_abs tdiam_rel tdiv \ +- tdiv_2exp tdiv_2si tdiv_2ui tdiv_d tdiv_ext tdiv_fr tdiv_q \ ++ tdiv_2exp tdiv_2si tdiv_2ui tdiv_d tdiv_fr tdiv_q \ + tdiv_si tdiv_ui tdiv_z terror texp texp2 texpm1 tfr_div \ + tfr_sub tget_d tget_endpoints tget_fr thas_zero thypot \ + tincrease tinf_p tinit tinits tinit_set tintersect tinterv_d \ +--- a/tests/mpfi-tests.h ++++ b/tests/mpfi-tests.h +@@ -28,6 +28,7 @@ + #define __MPFI_TESTS_H__ + + #include ++#include + + #include "mpfi_io.h" + #include "mpfi-impl.h" diff --git a/debian/patches/upstream-tests-set_ld-not64bits-SKIP.patch b/debian/patches/upstream-tests-set_ld-not64bits-SKIP.patch new file mode 100644 index 0000000..4a7bb4b --- /dev/null +++ b/debian/patches/upstream-tests-set_ld-not64bits-SKIP.patch @@ -0,0 +1,32 @@ +Description: upstream -- tests: set_ld: SKIP + Implement for the set_ld test a SKIP-exit for long doubles + that are not of 64 bits precision. +Origin: debian +Forwarded: by email +Author: Jerome Benoit +Last-Update: 2024-03-21 + +--- a/tests/type_il.c ++++ b/tests/type_il.c +@@ -66,16 +66,19 @@ + + inex = f_IL (got, op); + if (inex != expected_inex || !same_value (got, expected)) { ++ int skipflag = 0; + printf ("Failed line %lu.\nop = %La", test_line_number, op); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); +- if (inex != expected_inex) ++ if (inex != expected_inex) { + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); ++ skipflag = 1; ++ } + +- exit (1); ++ exit (skipflag?77:1); + } + } + diff --git a/debian/rules b/debian/rules index 2d33f6a..f785c2c 100755 --- a/debian/rules +++ b/debian/rules @@ -1,4 +1,52 @@ #!/usr/bin/make -f +include /usr/share/dpkg/pkg-info.mk + +export DEB_BUILD_MAINT_OPTIONS=hardening=+all + +export ACLOCAL_PATH=/usr/share/gnulib/m4 + +## inspired from mpfr material +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else ifeq ($(DEB_HOST_ARCH),alpha) + CFLAGS += -mieee +else ifeq ($(DEB_HOST_ARCH),sha4) + CFLAGS += -mieee +else + CFLAGS := $(subst -O2,-O3,$(CFLAGS)) +endif + +default: + @uscan --no-conf --dehs --report || true %: - dh $@ + dh $@ --builddirectory=_build + +override_dh_auto_configure: + dh_auto_configure -- --enable-maintainer-mode + +override_dh_auto_build-indep: + $(MAKE) -C _build/doc info pdf + +override_dh_auto_build-arch: + dh_auto_build -a + +override_dh_auto_test-indep: + +override_dh_auto_install-indep: + $(MAKE) -C _build/src install-data-am DESTDIR=$(CURDIR)/debian/tmp + $(MAKE) -C _build/doc install-info install-pdf DESTDIR=$(CURDIR)/debian/tmp + +override_dh_installdocs: + dh_installdocs -plibmpfi-dev --link-doc=libmpfi0 + dh_installdocs -plibmpfi-doc --doc-main-package=libmpfi-doc + dh_installdocs --remaining-packages + +override_dh_installexamples: + dh_installexamples -plibmpfi-doc --doc-main-package=libmpfi-doc + +override_dh_compress-indep: + dh_compress -X.pdf -Xexamples + +override_dh_missing: + dh_missing -X.la diff --git a/debian/source/lintian-overrides b/debian/source/lintian-overrides new file mode 100644 index 0000000..9184880 --- /dev/null +++ b/debian/source/lintian-overrides @@ -0,0 +1,3 @@ +# Upstream source ball is not (yet) signed: request to the upstream team +# was sent -- Jerome Benoit +debian-watch-does-not-check-openpgp-signature diff --git a/debian/tests/build-examples b/debian/tests/build-examples new file mode 100755 index 0000000..3531725 --- /dev/null +++ b/debian/tests/build-examples @@ -0,0 +1,11 @@ +#!/bin/sh +# autopkgtest check: build and launch program examples +set -ue +cd $AUTOPKGTEST_TMP + +cp -prd /usr/share/doc/libmpfi-doc/examples . +cd examples + +make check + +exit 0 diff --git a/debian/tests/control b/debian/tests/control new file mode 100644 index 0000000..4c65ab2 --- /dev/null +++ b/debian/tests/control @@ -0,0 +1,2 @@ +Tests: build-examples +Depends: libmpfi-doc, libmpfi-dev, build-essential diff --git a/debian/watch b/debian/watch new file mode 100644 index 0000000..01d0622 --- /dev/null +++ b/debian/watch @@ -0,0 +1,3 @@ +version=4 +opts=repack,repacksuffix=+ds,compression=xz,dversionmangle=s/\+ds//,uversionmangle=s/-(rc\d*)$/~$1/,searchmode=plain \ +https://gitlab.inria.fr/mpfi/mpfi/tags?sort=updated_desc -/archive/\d[\d.]+/mpfi-(\d[\d.]+)\.tar\.bz2 diff --git a/doc/Makefile.am b/doc/Makefile.am new file mode 100644 index 0000000..7180b65 --- /dev/null +++ b/doc/Makefile.am @@ -0,0 +1,2 @@ +info_TEXINFOS = mpfi.texi +TEXINFO_TEX = ../texinfo.tex diff --git a/doc/mpfi.texi b/doc/mpfi.texi new file mode 100644 index 0000000..b400d5e --- /dev/null +++ b/doc/mpfi.texi @@ -0,0 +1,1744 @@ +\input texinfo @c -*-texinfo-*- +@c %**start of header +@setfilename mpfi.info +@settitle MPFI 1.5.4. +@synindex tp fn +@iftex +@afourpaper +@end iftex +@comment %**end of header + +@dircategory Software libraries +@direntry +* mpfi: (mpfi.info). Multiple Precision Floating-Point Interval Library. +@end direntry + +@c smallbook + +@iftex +@finalout +@end iftex + +@c Note: the edition number is listed in *three* places; please update +@c all three. Also, update the month and year where appropriate. + +@c ==> Update edition number for settitle and subtitle, and in the +@c ==> following paragraph; update date, too. + + +@ifinfo +This file documents MPFI, a library for interval arithmetic, +which is built upon the MPFR multiple precision floating-point +arithmetic library + +Copyright (C) 2002-2018, Ouragan team, Inria Paris, France, +Arenaire team and AriC team, INRIA Rhone-Alpes and LIP, ENS Lyon, France, +and Lab. ANO, University of Sciences and Technologies of Lille, France. + +Permission is granted to make and distribute verbatim copies of +this manual provided the copyright notice and this permission notice +are preserved on all copies. + +@ignore +Permission is granted to process this file through TeX and print the +results, provided the printed document carries copying permission +notice identical to this one except for the removal of this paragraph +(this paragraph not being relevant to the printed manual). + +@end ignore +Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided that the entire +resulting derived work is distributed under the terms of a permission +notice identical to this one. + +Permission is granted to copy and distribute translations of this manual +into another language, under the above conditions for modified versions, +except that this permission notice may be stated in a translation approved +by the Free Software Foundation. +@end ifinfo + +@setchapternewpage on +@titlepage +@c use the new format for titles + +@title MPFI 1.5.4. +@subtitle Multiple Precision Floating-Point Interval Library +@subtitle August 2018 + +@author AriC, INRIA Grenoble - Rhone-Alpes, +@author Spaces, INRIA Lorraine, +@author Arenaire, INRIA Rhone-Alpes, +@author Lab. ANO, USTL (Univ. of Lille) + +@c Include the Distribution inside the titlepage so +@c that headings are turned off. + +@tex +\global\parindent=0pt +\global\parskip=8pt +\global\baselineskip=13pt +@end tex + +@page +@vskip 0pt plus 1filll +@c Copyright @copyright{} 2002-2018 Spaces, Arenaire and AriC INRIA projects, Lab. ANO - USTL + +@sp 2 + +Permission is granted to make and distribute verbatim copies of +this manual provided the copyright notice and this permission notice +are preserved on all copies. + +Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided that the entire +resulting derived work is distributed under the terms of a permission +notice identical to this one. + +Permission is granted to copy and distribute translations of this manual +into another language, under the above conditions for modified versions, +except that this permission notice may be stated in a translation approved +by the Free Software Foundation. +@end titlepage +@headings double + +@ifinfo +@node Top, Copying, (dir), (dir) + +@top MPFI 1.5.4. + +This manual documents how to install and use the Multiple Precision +Floating-Point Interval Library + +@end ifinfo + +@menu +* Copying:: +* Introduction to MPFI:: +* Installing MPFI:: +* Reporting Bugs:: +* MPFI Basics:: +* Interval Functions:: +* Contributors:: +* References:: +* Concept Index:: +* Function Index:: + +Interval Functions + + +Initialization and Assignment Functions + +* Initializing Intervals:: +* Assigning Intervals:: +* Simultaneous Interval Init & Assign:: + +@detailmenu + --- The Detailed Node Listing --- + +Interval Functions + +* Return Values:: +* Precision Handling:: +* Initializing and Assigning Intervals:: +* Floating-point Quantities:: +* Converting Intervals:: +* Interval Arithmetic:: +* Special Functions:: +* Interval Comparison:: +* I/O of Intervals:: +* Operating on the Endpoints:: +* Set Operations:: +* Miscellaneous Interval Functions:: +* Error Handling:: + +Initialization and Assignment Functions + +* Initializing Intervals:: +* Assigning Intervals:: +* Simultaneous Interval Init & Assign:: + +@end detailmenu +@end menu + +@node Copying, Introduction to MPFI, Top, Top +@comment node-name, next, previous, up +@unnumbered MPFI Copying Conditions +@cindex Copying conditions +@cindex Conditions for copying MPFI + +This library is @dfn{free}; this means that everyone is free to use it and +free to redistribute it on a free basis. The library is not in the public +domain; it is copyrighted and there are restrictions on its distribution, but +these restrictions are designed to permit everything that a good cooperating +citizen would want to do. What is not allowed is to try to prevent others +from further sharing any version of this library that they might get from +you.@refill + +Specifically, we want to make sure that you have the right to give away copies +of the library, that you receive source code or else can get it if you want +it, that you can change this library or use pieces of it in new free programs, +and that you know you can do these things.@refill + +To make sure that everyone has such rights, we have to forbid you to deprive +anyone else of these rights. For example, if you distribute copies of the +MPFI library, you must give the recipients all the rights that you have. You +must make sure that they, too, receive or can get the source code. And you +must tell them their rights.@refill + +Also, for our own protection, we must make certain that everyone finds out +that there is no warranty for the MPFI library. If it is modified by +someone else and passed on, we want their recipients to know that what they +have is not what we distributed, so that any problems introduced by others +will not reflect on our reputation.@refill + +The precise conditions of the license for the MPFI library are found in the +Lesser General Public License that accompany the source code. +As MPFI is built upon MPFR and share its license, +see the file COPYING.LESSER in the main MPFR directory.@refill + +@node Introduction to MPFI, Installing MPFI, Copying, Top +@comment node-name, next, previous, up +@chapter Introduction to MPFI + + +MPFI is intended to be a portable library written in C for arbitrary precision +interval arithmetic with intervals represented using MPFR reliable +floating-point numbers. It is based on the GNU MP library and on the MPFR +library. The purpose of an arbitrary precision interval arithmetic is on the +one hand to get @dfn{guaranteed} results, thanks to interval computation, and +on the other hand to obtain accurate results, thanks to multiple precision +arithmetic. The MPFI library is built upon MPFR in order to benefit from the +correct rounding provided, for each operation or function, by MPFR. Further +advantages of using MPFR are its portability and compliance with the IEEE 754 +standard for floating-point arithmetic. + + +This version of MPFI is released under the GNU Lesser General Public +License. +It is permitted to link MPFI to non-free programs, as long as when +distributing them the MPFI source code and a means to re-link with a +modified MPFI is provided. + +As interval arithmetic currently undergoes standardization, through +the work of the IEEE-1788 working group, future versions of MPFI +may evolve in order to reflect the standardized definitions and behaviours. + + +@c @section How to use this Manual +@c +@c Everyone should read @ref{MPFI Basics}. If you need to install the library +@c yourself, you need to read @ref{Installing MPFI}, too. +@c +@c The rest of the manual can be used for later reference, although it is +@c probably a good idea to glance through it. + + +@node Installing MPFI, Reporting Bugs, Introduction to MPFI, Top +@comment node-name, next, previous, up +@chapter Installing MPFI +@cindex Installation + +To build MPFI, you first have to install MPFR (version 4.0.1 or above) +on your computer. +You need a C compiler, preferably GCC, but any reasonable compiler +should work. +And you need a standard Unix @samp{make} program, plus some other +standard Unix utility programs. + +@section How to Install + +Here are the steps needed to install the MPFI library on Unix systems. +In the MPFI source directory, type the following commands. + +@enumerate +@item +@samp{./configure} + +This will prepare the build and setup the options according to your system. +You can give options to specify the install directories (instead of the +default @file{/usr/local}), and so on. + +You can specify the path to GMP and MPFR libraries with configure +options: @samp{--with-gmp=DIR} assumes that GMP is installed in the +@samp{DIR} directory. +Alternatively, you can use the @samp{--with-gmp-lib=DIR} and +@samp{--with-gmp-include=DIR} to specify respectively the GMP lib and GMP +include directories. +Options @samp{--with-mpfr=DIR}, @samp{--with-mpfr-include=DIR}, and +@samp{--with-mpfr-lib=DIR} have the same usage for the MPFR library. + +See the @file{INSTALL} file and the output of @samp{./configure +--help} for a description of standard options. + +@item +@samp{make} + +This will compile MPFI, and create a library archive file @file{libmpfi.a}. +On most platforms, a dynamic library will be produced too. + +@item +@samp{make check} + +This will make sure MPFI was built correctly. +If any test fails, information about this failure can be found in the +@file{tests/test-suite.log} file. If you want the contents of this file to +be automatically output in case of failure, you can set the @samp{VERBOSE} +environment variable to 1 before running @samp{make check}, for instance +by typing: + +@samp{VERBOSE=1 make check} + +If you get error messages from the test program, please +report this to +@samp{mpfi-users@@lists.gforge.inria.fr}. +(See @xref{Reporting Bugs}, for information on what to include in useful +bug reports.) + +@item +@samp{make install} + +This will copy +the file @file{mpfi.h} to the directory @file{/usr/local/include}, +the library files (@file{libmpfi.a} and possibly others) to the directory +@file{/usr/local/lib}, +the file @file{mpfi.info} to the directory @file{/usr/local/share/info}, +and some other documentation files to the directory +@file{/usr/local/share/doc/mpfi} +(or if you passed the @samp{--prefix} option to @file{configure}, +using the prefix directory given as argument to @samp{--prefix} +instead of @file{/usr/local}). +@end enumerate + +@section Other `make' targets + +There are some other useful make targets: + +@itemize @bullet +@item +@samp{info} + +Create an info version of the manual, in @file{mpfi.info}. + +This file is already provided in the MPFI archives. + +@item +@samp{pdf} + +Create a PDF version of the manual, in @file{mpfi.pdf}. + +@item +@samp{dvi} + +Create a DVI version of the manual, in @file{mpfi.dvi}. + +@item +@samp{ps} + +Create a Postscript version of the manual, in @file{mpfi.ps}. + +@item +@samp{html} +Create a HTML version of the manual, in @file{mpfi.html}. + +@item +@samp{clean} + +Delete all object files and archive files, but not the configuration files. + +@item +@samp{uninstall} +Delete all files copied by @samp{make install}. +@end itemize + + +@section Known Build Problems + +The installation procedure and MPFI itself have been tested +only on some Linux distributions. +Since it has not been intensively tested, +you may discover that +MPFI suffers from all bugs of the underlying libraries, plus many many more. + +Please report any problem to @samp{mpfi-users@@lists.gforge.inria.fr}. +@xref{Reporting Bugs}. + +@section Getting the Latest Version of MPFI + +The latest version of MPFI is available from +@url{https://gforge.inria.fr/frs/?group_id=157}. + + +@node Reporting Bugs, MPFI Basics, Installing MPFI, Top +@comment node-name, next, previous, up +@chapter Reporting Bugs +@cindex Reporting bugs + +If you think you have found a bug in the MPFI library, please investigate it +and report it. We have made this library available to you, and we expect +you will report the bugs that you find. + +There are a few things you should think about when you put your bug report +together. + +You have to send us a test case that makes it possible for us to reproduce the +bug. Include instructions on how to run the test case. + +You also have to explain what is wrong; if you get a crash, or if the results +printed are incorrect and in that case, in what way. + +Please include compiler version information +in your bug report. This can be extracted using @samp{cc -V} on some machines or, +if you're using gcc, @samp{gcc -v}. Also, include the output from @samp{uname +-a}, along with the version of GMP and of MPFR you use. + +If your bug report is good, we will do our best to help you to get a corrected +version of the library; if the bug report is poor, we won't do anything about +it (except kidding you for sending poor bug reports). + +Send your bug report to: @samp{mpfi-users@@lists.gforge.inria.fr}. + +If you think something in this manual is unclear, or downright incorrect, or if +the language needs to be improved, please send a note to the same address. + + +@node MPFI Basics, Interval Functions, Reporting Bugs, Top +@comment node-name, next, previous, up +@chapter MPFI Basics + + +@cindex @file{mpfi.h} +All declarations needed to use MPFI are collected in the include file +@file{mpfi.h}. The declarations useful for inputs and outputs are to be found +in @file{mpfi_io.h}. It is designed to work with both C and C++ compilers. +You should include these files in any program using the MPFI library: + +@example +#include "mpfi.h" +#include "mpfi_io.h" +@end example + +@section Nomenclature and Types + +As MPFI is built upon MPFR, it is advisable to read MPFR's manual first. + +@cindex Interval +@tindex @code{mpfi_t} +@noindent +An @dfn{interval} is a closed connected set of real numbers, it is represented +in MPFI by its endpoints which are MPFR floating-point numbers. +The C data type for these objects is @code{mpfi_t}. + +MPFI functions operate on valid intervals (defined below), their behavior with +non-valid intervals as input is undefined. +@itemize +@item +A @dfn{valid interval} can have finite or infinite endpoints, but its left +endpoint is not larger than its right endpoint and cannot be +infinity or -0 +(respectively, the right endpoint cannot be -infinity or +0). @footnote{The +restriction on the infinite values follows the definition of interval, and the +sign of the zero bounds allows a simple implementation of the four arithmetic +operations as explained in the paper of T. Hickey, Q. Ju, and M. H. Van Emden, +@cite{Interval arithmetic: From principles to implementation} +(@xref{References}).} As a consequence, the unique representation of the zero +singleton is @math{[+0, -0]}. +@end itemize + +MPFI functions may return intervals that are not valid as input value. Their +semantic defined as follows: +@itemize +@item +One (or both) NaN endpoint(s) indicates that an invalid operation has been +performed and that the resulting interval has no mathematical meaning. +@item +An @dfn{empty interval} has its left endpoint larger than its right endpoint. +@end itemize + +Both the meaning of "invalid operation", the representation of the empty set +and its handling may change in future versions of MPFI, according to the +standardization of interval arithmetic in IEEE-1788. + +Some functions on intervals return a floating-point value: among such +functions are @code{mpfi_get_left} that returns the left endpoint of +an interval and @code{mpfi_diam_abs} that gets the width of the +input interval. + +@cindex Floating-point number +@tindex @code{mpfr_t} +@noindent +A @dfn{Floating point number} or @dfn{Float} for short, is an arbitrary precision +significand (aslso called mantissa) with a limited precision exponent. The C data type for such objects +is @code{mpfr_t}. + +@cindex Precision +@tindex @code{mpfr_prec_t} +@comment a changer en mpfr_prec_t quand on demandera MPFR 3.0.0 ou plus +@noindent +The @dfn{Precision} is the number of bits used to represent the significand +of a floating-point number; +the corresponding C data type is @code{mpfr_prec_t} (renamed +@code{mpfr_prec_t} since MPFR version 3.0.0, both types are +compatible). + +MPFI assumes that both endpoints of an interval use the same precision. +@c The behaviour is undefined if this is not the case. +However when this does not hold, the largest precision is considered. + + +@section Function Classes + +There is only one class of functions in the MPFI library: + +@enumerate +@item +@tindex @code{mpfi_t} +Functions for interval arithmetic based on floating-point numbers, +with names beginning with +@code{mpfi_}. The associated type is @code{mpfi_t}. There are around 170 +functions in this class. +@end enumerate + + +@section MPFI Variable Conventions + +As a general rule, all MPFI functions expect output arguments before input +arguments. This notation is based on an analogy with the assignment operator. + +MPFI allows you to use the same variable for both input and output in the same +expression. For example, the function for the exponential, +@code{mpfi_exp}, can be used like this: @code{mpfi_exp (x, x)}. +This +computes the set of exponentials of every real belonging to @var{x} +and puts the result back in @var{x}. + +Before you can give a value to an MPFI variable, you need to initialize it by calling +one of the special initialization functions. When you're done with a +variable, you need to clear it out, using one of the appropriate +functions. + +A variable should be initialized only once, or at least be cleared out between +different initializations. After a variable has been initialized, it can be +assigned any number of times. + +For efficiency reasons, avoid to initialize and clear out a variable in loops. +Instead, initialize it before entering the loop, and clear it out after +exiting the loop. + +You don't need to be concerned about allocating additional space for MPFI +variables, since any variable uses a memory space of fixed size. +Hence unless you change its precision, or clear and reinitialize it, +an interval variable will have the same allocated space during all its +lifetime. + +@c TO DO later: a section on "Special values and exceptions" and possibly a section on "Memory handling / Multithreading" + +@node Interval Functions, Contributors, MPFI Basics, Top +@comment node-name, next, previous, up +@chapter Interval Functions +@cindex Interval functions + +The interval functions expect arguments of type @code{mpfi_t}. + +The MPFI interval functions have an interface that is close to the +corresponding MPFR +functions. The function prefix for interval operations is +@code{mpfi_}. + +MPFI intervals are represented by their endpoints; this representation +should be invisible to the user, unfortunately it is not... +@c An alternative representation could be to store the center and the +@c radius of the interval. +It is assumed that both endpoints have the +same precision; however when this does not hold, the largest precision +is considered. The user has +to specify the precision of each variable. A computation that assigns a +variable will take place with the precision of the assigned variable. +@cindex User-defined precision +For more information on precision (precision of a variable, +precision of a calculation), see the MPFR documentation. + + +@menu +* Return Values:: +* Precision Handling:: +* Initializing and Assigning Intervals:: +* Floating-point Quantities:: +* Converting Intervals:: +* Interval Arithmetic:: +* Special Functions:: +* Interval Comparison:: +* I/O of Intervals:: +* Operating on the Endpoints:: +* Set Operations:: +* Miscellaneous Interval Functions:: +* Error Handling:: +@end menu + +@comment @node Return Values, Rounding Modes and Precision Handling, Interval Functions, Interval Functions +@node Return Values, Precision Handling, Interval Functions, Interval Functions +@comment node-name, next, previous, up +@cindex Return values +@section Return Values + +Four integer values (of C type @code{int}) +can be returned by a typical @code{mpfi} function. These values +indicate whether none, one or two endpoints of the computed interval are +exact: since they are rounded values, they can differ from the exact +result. Here are their names: +@itemize @bullet +@tindex @code{MPFI_FLAGS_BOTH_ENDPOINTS_EXACT} +@item @code{MPFI_FLAGS_BOTH_ENDPOINTS_EXACT} +@tindex @code{MPFI_FLAGS_LEFT_ENDPOINT_INEXACT} +@item @code{MPFI_FLAGS_LEFT_ENDPOINT_INEXACT}: the left endpoint is inexact +whereas the right endpoint is exact; +@tindex @code{MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT} +@item @code{MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT}: the right endpoint is inexact +whereas the left endpoint is exact; +@tindex @code{MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT} +@item @code{MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT} +@end itemize +To test the exactness of one endpoint, the following functions are available +(their names are self-explanatory): +@itemize @bullet +@tindex @code{MPFI_BOTH_ARE_EXACT} +@item @code{MPFI_BOTH_ARE_EXACT} +@tindex @code{MPFI_LEFT_IS_INEXACT} +@item @code{MPFI_LEFT_IS_INEXACT} +@tindex @code{MPFI_RIGHT_IS_INEXACT} +@item @code{MPFI_RIGHT_IS_INEXACT} +@tindex @code{MPFI_BOTH_ARE_INEXACT} +@item @code{MPFI_BOTH_ARE_INEXACT} +@end itemize + + +@comment @node Rounding Modes and Precision Handling, Initializing and Assigning Intervals, Return Values, Interval Functions +@node Precision Handling, Initializing and Assigning Intervals, Return Values, Interval Functions +@comment node-name, next, previous, up +@comment @cindex Rounding modes +@cindex Precision +@section Precision Handling + +@comment Only two rounding modes are useful when computing with intervals +@comment represented by their endpoints, namely downward and upward roundings +@comment used for outward rounding: +@comment @itemize @bullet +@comment @item @code{MPFI_RNDU}: round towards plus infinity +@comment @item @code{MPFI_RNDD}: round towards minus infinity +@comment @end itemize +@comment The four rounding modes provided by MPFR are still available, +@comment see MPFR documentation to get their names and information on how +@comment to modify them. + +The default computing precision is handled by MPFR, getting or setting +its value is performed using the following MPFR functions +(cf. MPFR documentation): + +@deftypefn Macro void mpfr_set_default_prec (mpfr_prec_t @var{prec}) +Sets the default precision to be @strong{exactly} @var{prec} bits. The +precision of a variable means the number of bits used to store the significands +of its endpoints. +All +subsequent calls to @code{mpfi_init} will use this precision, but previously +initialized variables are unaffected. +This default precision is set to 53 bits initially. +The precision @var{prec} can be any integer between @code{MPFR_PREC_MIN} and +@code{MPFR_PREC_MAX}. + +Note: when MPFR is built with the @samp{--enable-thread-safe} configure option, +the default precision is local to each thread. See MPFR documentation for more information. +@end deftypefn + +@deftypefn Macro mpfr_prec_t mpfr_get_default_prec () +Returns the default MPFR/MPFI precision in bits. +@end deftypefn + +The following two functions are useful for changing the precision during a +calculation. A typical use would be for adjusting the precision gradually in +iterative algorithms like Newton-Raphson, making the computation precision +closely match the actual accurate part of the numbers. + +@deftypefun void mpfi_set_prec (mpfi_t @var{x}, mpfr_prec_t @var{prec}) +Resets the precision of @var{x} to be @strong{exactly} @var{prec} bits. +The previous value stored in @var{x} is lost. It is equivalent to +a call to @code{mpfi_clear(x)} followed by a call to +@code{mpfi_init2(x, prec)}, but more efficient as no allocation is done in +case the current allocated space for the significands of the endpoints +of @var{x} is enough. +The precision @var{prec} can be any integer between @code{MPFR_PREC_MIN} and +@code{MPFR_PREC_MAX}. +In case you want to keep the previous value stored in @var{x}, +use @code{mpfi_round_prec} instead. +@end deftypefun + +@deftypefun mpfr_prec_t mpfi_get_prec (mpfi_t @var{x}) +Return the largest precision actually used for assignments of @var{x}, i.e.\ +the number of bits used to store the significands of its endpoints. +Should the two endpoints have different precisions, the largest one is returned. +@end deftypefun + +@deftypefun int mpfi_round_prec (mpfi_t @var{x}, mpfr_prec_t @var{prec}) +Rounds @var{x} with precision @var{prec}, which +may be different from that of @var{x}. +If @var{prec} is greater or equal to the precision of @var{x}, then new +space is allocated for the endpoints' significands, and they are filled with zeroes. +Otherwise, the significands are rounded outwards to precision @var{prec}. +In both cases, the precision of @var{x} is changed to @var{prec}. +It returns a value indicating whether the possibly rounded endpoints are exact or not, +cf. @ref{Return Values}. +@end deftypefun + +@comment @node Initializing and Assigning Intervals, Floating-point Quantities, Rounding Modes and Precision Handling, Interval Functions +@node Initializing and Assigning Intervals, Floating-point Quantities, Precision Handling, Interval Functions +@comment node-name, next, previous, up +@section Initialization and Assignment Functions + +@menu +* Initializing Intervals:: +* Assigning Intervals:: +* Simultaneous Interval Init & Assign:: +@end menu + +@node Initializing Intervals, Assigning Intervals, Initializing and Assigning Intervals, Initializing and Assigning Intervals +@comment node-name, next, previous, up +@subsection Initialization Functions +@cindex Interval initialization functions + +An @code{mpfi_t} object must be initialized before storing the first value in +it. The functions @code{mpfi_init} and @code{mpfi_init2} are used for that +purpose. + +@deftypefun void mpfi_init (mpfi_t @var{x}) +Initializes @var{x}, and sets its value to NaN, to prevent from using +an unassigned variable inadvertently. +Normally, a variable should be initialized once only +or at least be cleared, using @code{mpfi_clear}, between consecutive +initializations. The +precision of @var{x} is the default precision, which can be changed +by a call to @code{mpfr_set_default_prec}. + +Warning! In a given program, some other libraries might change the default +precision and not restore it. Thus it is safer to use @code{mpfi_init2}. +@end deftypefun + +@deftypefun void mpfi_init2 (mpfi_t @var{x}, mpfr_prec_t @var{prec}) +Initializes @var{x}, sets its precision (or more precisely the precision +of its endpoints) to be @strong{exactly} +@var{prec} bits, and sets its endpoints to NaN. +Normally, a variable should be initialized once only or at +least be cleared, using @code{mpfi_clear}, between consecutive initializations. +To change the precision of a variable which has already been initialized, +use @code{mpfi_set_prec} instead, or @code{mpfi_round_prec} if you want to keep its value. +@end deftypefun + +@deftypefun void mpfi_clear (mpfi_t @var{x}) +Frees the space occupied by the significands of the endpoints of @var{x}. Make sure to call this function for all +@code{mpfi_t} variables when you are done with them. +@end deftypefun + + +@need 2000 +Here is an example on how to initialize interval variables: +@example +@{ + mpfi_t x, y; + mpfi_init (x); /* use default precision */ + mpfi_init2 (y, 256); /* precision @emph{exactly} 256 bits */ + @dots{} + /* Unless the program is about to exit, do ... */ + mpfi_clear (x); + mpfi_clear (y); +@} +@end example + +@deftypefun void mpfi_inits (mpfi_t @var{x}, ...) +Initialize all the @code{mpfi_t} variables of the given @code{va_list}, +set their precision to the default precision and their value to NaN@. +See @code{mpfi_init} for more details. +The @code{va_list} is assumed to be composed only of type @code{mpfi_t} +(or equivalently @code{mpfi_ptr}). +It begins from @var{x}, and ends when it encounters a null pointer (whose +type must also be @code{mpfi_ptr}). + +Warning! In a given program, some other libraries might change the default +precision and not restore it. Thus it is safer to use @code{mpfi_inits2}. +@end deftypefun + +@deftypefun void mpfi_inits2 (mpfr_prec_t @var{prec}, mpfi_t @var{x}, ...) +Initialize all the @code{mpfi_t} variables of the given variable +argument @code{va_list}, set their precision to be @strong{exactly} +@var{prec} bits and their value to NaN@. +See @code{mpfi_init2} for more details. +The @code{va_list} is assumed to be composed only of type @code{mpfi_t} +(or equivalently @code{mpfi_ptr}). +It begins from @var{x}, and ends when it encounters a null pointer (whose +type must also be @code{mpfi_ptr}). +@end deftypefun + +@deftypefun void mpfi_clears (mpfi_t @var{x}, ...) +Free the space occupied by all the @code{mpfi_t} variables of the given +@code{va_list}. See @code{mpfi_clear} for more details. +The @code{va_list} is assumed to be composed only of type @code{mpfi_t} +(or equivalently @code{mpfi_ptr}). +It begins from @var{x}, and ends when it encounters a null pointer (whose +type must also be @code{mpfi_ptr}). +@end deftypefun + +Here is an example of how to use multiple initialization functions +(since @code{NULL} is not necessarily defined in this context, we use +@code{(mpfi_ptr) 0} instead, but @code{(mpfi_ptr) NULL} is also correct). + +@example +@{ + mpfi_t a, b, c; + + mpfi_inits (a, b, c, (mpfi_ptr) 0); /* Use default precision */ + @dots{} + mpfi_clears (a, b, c, (mpfi_ptr) 0); + + /* Another possibility is to specify the precision */ + mpfi_inits2 (200, a, b, c, (mpfi_ptr) 0); /* Use @emph{exactly} 200 bits */ + @dots{} + mpfi_clears (a, b, c, (mpfi_ptr) 0); +@} +@end example + + +@node Assigning Intervals, Simultaneous Interval Init & Assign, Initializing Intervals, Initializing and Assigning Intervals +@comment node-name, next, previous, up +@subsection Assignment Functions +@cindex Interval assignment functions + +These functions assign new values to already initialized intervals +(@pxref{Initializing Intervals}). + +@deftypefun int mpfi_set (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_set_ui (mpfi_t @var{rop}, unsigned long int @var{op}) +@deftypefunx int mpfi_set_si (mpfi_t @var{rop}, long int @var{op}) +@deftypefunx int mpfi_set_d (mpfi_t @var{rop}, double @var{op}) +@deftypefunx int mpfi_set_flt (mpfi_t @var{rop}, float @var{op}) +@deftypefunx int mpfi_set_ld (mpfi_t @var{rop}, long double @var{op}) +@deftypefunx int mpfi_set_z (mpfi_t @var{rop}, mpz_t @var{op}) +@deftypefunx int mpfi_set_q (mpfi_t @var{rop}, mpq_t @var{op}) +@deftypefunx int mpfi_set_fr (mpfi_t @var{rop}, mpfr_t @var{op}) +Sets the value of @var{rop} from @var{op}, rounded outward to the precision of @var{rop}: +@var{op} then belongs to @var{rop}. +The returned value indicates whether none, one or both endpoints are exact. +Please note that even a @code{long int} may have to be rounded, +if the destination precision is less than the machine word width. + +No support (yet) for huge (signed or unsigned) integer, nor for float128, nor for decimal64. +@end deftypefun + +@deftypefun int mpfi_set_str (mpfi_t @var{rop}, char *@var{s}, int @var{base}) +Sets @var{rop} to the value of the string @var{s}, in base @var{base} (between +2 and 36), outward rounded to the precision of @var{rop}: +@var{op} then belongs to @var{rop}. +The exponent is read in decimal. +The string is of the form @samp{number} or +@samp{[ number1 , number 2 ]}. +@c where the spaces around the floating-point endpoints are mandatory. +Each endpoint has the form @samp{M@@N} or, if the +base is 10 or less, alternatively @samp{MeN} or @samp{MEN}. +@samp{M} is the significand and +@samp{N} is the exponent. The significand is always in the specified base. The +exponent is +@c either in the specified base or, if @var{base} is negative, +in decimal. +The argument @var{base} may be in the ranges 2 to 36. + +This function returns 1 if the input is incorrect, and 0 otherwise. +@end deftypefun + +@deftypefun void mpfi_swap (mpfi_t @var{x}, mpfi_t @var{y}) +Swaps the values @var{x} and @var{y} efficiently. Warning: the +precisions are exchanged too; in case the precisions are different, +@code{mpfi_swap} is thus not equivalent to three @code{mpfi_set} calls +using a third auxiliary variable. +@end deftypefun + +@node Simultaneous Interval Init & Assign, , Assigning Intervals, Initializing and Assigning Intervals +@comment node-name, next, previous, up +@subsection Combined Initialization and Assignment Functions +@cindex Initialization and assignment functions + +@deftypefun int mpfi_init_set (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_init_set_ui (mpfi_t @var{rop}, unsigned long int @var{op}) +@deftypefunx int mpfi_init_set_si (mpfi_t @var{rop}, long int @var{op}) +@deftypefunx int mpfi_init_set_d (mpfi_t @var{rop}, double @var{op}) +@deftypefunx int mpfi_init_set_z (mpfi_t @var{rop}, mpz_t @var{op}) +@deftypefunx int mpfi_init_set_q (mpfi_t @var{rop}, mpq_t @var{op}) +@deftypefunx int mpfi_init_set_fr (mpfi_t @var{rop}, mpfr_t @var{op}) +Initializes @var{rop} and sets its value from @var{op}, outward rounded so +that @var{op} belongs to @var{rop}. +The precision of @var{rop} will be taken from the active default precision, +as set by @code{mpfr_set_default_prec}. +The returned value indicates whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_init_set_str (mpfi_t @var{rop}, char *@var{s}, int @var{base}) +Initializes @var{rop} and sets its value +to the value of the string @var{s}, in base @var{base} (between +2 and 36), outward rounded to the precision of @var{rop}: +@var{op} then belongs to @var{rop}. The exponent is read in decimal. +See @code{mpfi_set_str}. +@end deftypefun + + +@node Floating-point Quantities, Converting Intervals, Initializing and Assigning Intervals, Interval Functions +@comment node-name, next, previous, up +@section Interval Functions with Floating-point Results +@cindex Interval functions with floating-point results + +Some functions on intervals return floating-point results, +such as the center or the width, also called diameter, of an interval. + +@deftypefun int mpfi_diam_abs (mpfr_t @var{rop}, mpfi_t @var{op}) +Sets the value of @var{rop} to the upward rounded diameter of @var{op}, +or in other words to the upward rounded difference between the right endpoint +of @var{op} and its left endpoint. +Returns 0 if the diameter is exact and a positive value if the rounded +value is greater than the exact diameter. +@end deftypefun + +@deftypefun int mpfi_diam_rel (mpfr_t @var{rop}, mpfi_t @var{op}) +Sets the value of @var{rop} to the upward rounded relative diameter of @var{op}, +or in other words to the upward rounded difference between the right endpoint +of @var{op} and its left endpoint, divided by the absolute value +of the center of @var{op} if it is not zero. +Returns 0 if the result is exact and a positive value if the returned value +is an overestimation, in this case the returned value may not be the correct +rounding of the exact value. +@end deftypefun + +@deftypefun int mpfi_diam (mpfr_t @var{rop}, mpfi_t @var{op}) +Sets the value of @var{rop} to the relative diameter of @var{op} +if @var{op} does not contain zero and to its absolute diameter otherwise. +Returns 0 if the result is exact and a positive value if the returned value +is an overestimation, it may not be the correct rounding of the exact value +in the latter case. +@end deftypefun + +@deftypefun int mpfi_mag (mpfr_t rop, mpfi_t op) +Sets the value of @var{rop} to the magnitude of @var{op}, +i.e.\ to the largest absolute value of the elements of @var{op}. +Returns 0 if the result is exact and a positive value if the returned value +is an overestimation. +@end deftypefun + +@deftypefun int mpfi_mig (mpfr_t rop, mpfi_t op) +Sets the value of @var{rop} to the mignitude of @var{op}, +i.e.\ to the smallest absolute value of the elements of @var{op}. +Returns 0 if the result is exact and a negative value if the returned value +is an underestimation. +@end deftypefun + +@deftypefun int mpfi_mid (mpfr_t rop, mpfi_t op) +Sets @var{rop} to the middle of @var{op}. +Returns 0 if the result is exact, a positive value if @var{rop} > the +middle of @var{op} and a negative value if @var{rop} < the middle of @var{op}. +@end deftypefun + +@deftypefun void mpfi_alea (mpfr_t rop, mpfi_t op) +Sets @var{rop} to a floating-point number +picked up at random in @var{op}, according to a uniform distribution. + +This function is deprecated and may disappear in future versions of MPFI; +@code{mpfi_urandom} should be used instead. +@end deftypefun + +@deftypefun void mpfi_urandom (mpfr_t rop, mpfi_t op, gmp_randstate_t state) +Sets @var{rop} to a floating-point number picked up at random in +@var{op}, according to a uniform distribution. + +The argument @var{state} should be initialized with one of the GMP +random state initialization functions +@ifinfo +(@pxref{Random State Initialization,,, gmp.info,GNU MP}). +@end ifinfo +@ifnotinfo +(see Section ``Random State Initialization'' in @cite{GNU MP} manual). +@end ifnotinfo +@end deftypefun + +@deftypefun void mpfi_nrandom (mpfr_t rop, mpfi_t op, gmp_randstate_t state) +Sets @var{rop} to a floating-point number picked up at random in +@var{op}, according to a normal distribution. + +The argument @var{state} should be initialized as for @code{mpfi_urandom}. + +Caveat: the normal distribution on the set of floating-point numbers is different from the normal distribution on the set of real numbers. No guarantee is given on the quality of the distribution. +@end deftypefun + +@deftypefun void mpfi_erandom (mpfr_t rop, mpfi_t op, gmp_randstate_t state) +Sets @var{rop} to a floating-point number picked up at random in +@var{op}, according to an exponential distribution. + +The argument @var{state} should be initialized as for @code{mpfi_urandom}. + +Caveat: the exponential distribution on the set of floating-point numbers is different from the exponential distribution on the set of real numbers. No guarantee is given on the quality of the distribution. +@end deftypefun + + +@node Converting Intervals, Interval Arithmetic, Floating-point Quantities, Interval Functions +@comment node-name, next, previous, up +@section Conversion Functions +@cindex Conversion functions + +@deftypefun double mpfi_get_d (mpfi_t @var{op}) +Converts @var{op} to a double, which is the center of @var{op} rounded to the +nearest double. +@end deftypefun + +@deftypefun void mpfi_get_fr (mpfr_t @var{rop}, mpfi_t @var{op}) +Converts @var{op} to a floating-point number, which is the center of @var{op} +rounded to nearest. +@end deftypefun + + +@node Interval Arithmetic, Special Functions, Converting Intervals, Interval Functions +@comment node-name, next, previous, up +@section Basic Arithmetic Functions +@cindex Interval arithmetic functions +@cindex Arithmetic functions + +@deftypefun int mpfi_add (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_add_d (mpfi_t @var{rop}, mpfi_t @var{op1}, double @var{op2}) +@deftypefunx int mpfi_add_ui (mpfi_t @var{rop}, mpfi_t @var{op1}, unsigned long int @var{op2}) +@deftypefunx int mpfi_add_si (mpfi_t @var{rop}, mpfi_t @var{op1}, long int @var{op2}) +@deftypefunx int mpfi_add_z (mpfi_t @var{rop}, mpfi_t @var{op1}, mpz_t @var{op2}) +@deftypefunx int mpfi_add_q (mpfi_t @var{rop}, mpfi_t @var{op1}, mpq_t @var{op2}) +@deftypefunx int mpfi_add_fr (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfr_t @var{op2}) +Sets @var{rop} to @var{op1} + @var{op2}. +Returns a value indicating whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_sub (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_sub_d (mpfi_t @var{rop}, mpfi_t @var{op1}, double @var{op2}) +@deftypefunx int mpfi_d_sub (mpfi_t @var{rop}, double @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_sub_ui (mpfi_t @var{rop}, mpfi_t @var{op1}, unsigned long int @var{op2}) +@deftypefunx int mpfi_ui_sub (mpfi_t @var{rop}, unsigned long int @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_sub_si (mpfi_t @var{rop}, mpfi_t @var{op1}, long int @var{op2}) +@deftypefunx int mpfi_si_sub (mpfi_t @var{rop}, long int @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_sub_z (mpfi_t @var{rop}, mpfi_t @var{op1}, mpz_t @var{op2}) +@deftypefunx int mpfi_z_sub (mpfi_t @var{rop}, mpz_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_sub_q (mpfi_t @var{rop}, mpfi_t @var{op1}, mpq_t @var{op2}) +@deftypefunx int mpfi_q_sub (mpfi_t @var{rop}, mpq_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_sub_fr (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfr_t @var{op2}) +@deftypefunx int mpfi_fr_sub (mpfi_t @var{rop}, mpfr_t @var{op1}, mpfi_t @var{op2}) +Sets @var{rop} to @var{op1} @minus{} @var{op2}. +Returns a value indicating whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_mul (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_mul_d (mpfi_t @var{rop}, mpfi_t @var{op1}, double @var{op2}) +@deftypefunx int mpfi_mul_ui (mpfi_t @var{rop}, mpfi_t @var{op1}, unsigned long int @var{op2}) +@deftypefunx int mpfi_mul_si (mpfi_t @var{rop}, mpfi_t @var{op1}, long int @var{op2}) +@deftypefunx int mpfi_mul_z (mpfi_t @var{rop}, mpfi_t @var{op1}, mpz_t @var{op2}) +@deftypefunx int mpfi_mul_q (mpfi_t @var{rop}, mpfi_t @var{op1}, mpq_t @var{op2}) +@deftypefunx int mpfi_mul_fr (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfr_t @var{op2}) +@c @ifinfo +Sets @var{rop} to @var{op1} * @var{op2}. +@c @end ifinfo +@c @iftex +@c @tex +@c Set @var{rop} to $@var{op1} \times @var{op2}$. +@c @end tex +@c @end iftex +Multiplication by an interval containing only zero results in 0. +Returns a value indicating whether none, one or both endpoints are exact. +@end deftypefun + + +@ifinfo +Division is defined even if the divisor contains zero: when the divisor +contains zero in its interior, the result is the whole real interval [-Inf, Inf]. +When the divisor has one of its endpoints equal to 0, +@c the rules defined by the IEEE 754 norm for the division by signed zeroes apply: +for instance, [1,2]/[+0,1] results in [1, Inf]. +It is not guaranteed in the current version that everything behaves properly +if the divisor contains only 0. +@end ifinfo +@iftex +@tex +Division is defined even if the divisor contains zero: when the divisor +contains zero in its interior, the result is the whole real interval $[-\infty, \infty]$. +When the divisor has one of its endpoints equal to 0, +the rules defined by the IEEE 754 norm for the division by signed zeroes +apply: for instance, $[1,2]/[0^+,1]$ results in $[1, \infty]$. +@end tex +@end iftex +In this example, both endpoints are exact. + +The extended interval division, returning two semi-infinite intervals when +the divisor contains 0, should be available soon. + +@deftypefun int mpfi_div (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_div_d (mpfi_t @var{rop}, mpfi_t @var{op1}, double @var{op2}) +@deftypefunx int mpfi_d_div (mpfi_t @var{rop}, double @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_div_ui (mpfi_t @var{rop}, mpfi_t @var{op1}, unsigned long int @var{op2}) +@deftypefunx int mpfi_ui_div (mpfi_t @var{rop}, unsigned long int @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_div_si (mpfi_t @var{rop}, mpfi_t @var{op1}, long int @var{op2}) +@deftypefunx int mpfi_si_div (mpfi_t @var{rop}, long int @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_div_z (mpfi_t @var{rop}, mpfi_t @var{op1}, mpz_t @var{op2}) +@deftypefunx int mpfi_z_div (mpfi_t @var{rop}, mpz_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_div_q (mpfi_t @var{rop}, mpfi_t @var{op1}, mpq_t @var{op2}) +@deftypefunx int mpfi_q_div (mpfi_t @var{rop}, mpq_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_div_fr (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfr_t @var{op2}) +@deftypefunx int mpfi_fr_div (mpfi_t @var{rop}, mpfr_t @var{op1}, mpfi_t @var{op2}) +Sets @var{rop} to @var{op1}/@var{op2}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_neg (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to @minus{}@var{op}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_sqr (mpfi_t @var{rop}, mpfi_t @var{op}) +@ifinfo +Sets @var{rop} to the nonnegative square of @var{op}. +@end ifinfo +@iftex +@tex +Sets @var{rop} to $@var{op} ^2$. +@end tex +@end iftex +Returns an indication of whether none, one or both endpoints are exact. +Indeed, in interval arithmetic, the square of an interval is a nonnegative interval +whereas the product of an interval by itself can contain negative values. +@end deftypefun + +@deftypefun int mpfi_inv (mpfi_t @var{rop}, mpfi_t @var{op}) +@ifinfo +Sets @var{rop} to 1/@var{op}. +Inverse is defined even if the interval contains zero: when the denominator +contains zero, the result is the whole real interval ]-Inf, Inf[. +@end ifinfo +@iftex +@tex +Sets @var{rop} to $1/@var{op}$. +Inversion is defined even if the interval contains zero: when the denominator +contains zero, the result is the whole real interval $[-\infty, \infty]$. +@end tex +@end iftex +Returns an indication of whether none, one or both endpoints are exact. +@c Signed zeroes, introduced in the IEEE 754 norm for +@c interval arithmetic, are not yet taken into account. +@end deftypefun + +@deftypefun int mpfi_sqrt (mpfi_t @var{rop}, mpfi_t @var{op}) +@ifinfo +Sets @var{rop} to the square root of @var{op}. +@end ifinfo +@iftex +@tex +Sets @var{rop} to $\sqrt{@var{op}}$. +@end tex +@end iftex +Sets @var{rop} to NaN if @var{op} is negative. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_cbrt (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the cubic root of @var{op}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_abs (mpfi_t @var{rop}, mpfi_t @var{op}) +@ifinfo +Sets @var{rop} to the interval containing the absolute value of every element of @var{op}. +@end ifinfo +@iftex +@tex +Sets @var{rop} to $|@var{op} |$, the absolute value of @var{op}. +@end tex +@end iftex +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_mul_2exp (mpfi_t @var{rop}, mpfi_t @var{op1}, unsigned long int @var{op2}) +@deftypefunx int mpfi_mul_2ui (mpfi_t @var{rop}, mpfi_t @var{op1}, unsigned long int @var{op2}) +@deftypefunx int mpfi_mul_2si (mpfi_t @var{rop}, mpfi_t @var{op1}, long int @var{op2}) +@ifinfo +Sets @var{rop} to @var{op1} times 2 raised to @var{op2}. + +@code{mpfi_mul_2exp} is identical to @code{mpfi_mul_2ui} and is kept for compatibility +with former versions of MPFI only. It is deprecated and could disappear in future versions of MPFI. +@end ifinfo +@iftex +@tex +Sets @var{rop} to $@var{op1} \times 2^{op2}$. +@end tex +@end iftex +Returns an indication of whether none, one or both endpoints are exact. +Just increases the exponents of the endpoints by @var{op2} +when @var{rop} and @var{op1} are identical. +@end deftypefun + +@deftypefun int mpfi_div_2exp (mpfi_t @var{rop}, mpfi_t @var{op1}, unsigned long int @var{op2}) +@deftypefunx int mpfi_div_2ui (mpfi_t @var{rop}, mpfi_t @var{op1}, unsigned long int @var{op2}) +@deftypefunx int mpfi_div_2si (mpfi_t @var{rop}, mpfi_t @var{op1}, long int @var{op2}) +@ifinfo +Sets @var{rop} to @var{op1} divided by 2 raised to @var{op2}. +@end ifinfo +@iftex +@tex +Sets @var{rop} to $@var{op1}/2^{op2}$. +@end tex +@end iftex +Returns an indication of whether none, one or both endpoints are exact. +Just decreases the exponents of the endpoints by @var{op2} +when @var{rop} and @var{op1} are identical. +@end deftypefun + +@node Special Functions, Interval Comparison, Interval Arithmetic, Interval Functions +@comment node-name, next, previous, up +@section Special Functions +@cindex Special functions + +These functions are based on their MPFR counterparts. For more information, +see the MPFR documentation or related bibliography. + +@deftypefun int mpfi_log (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the natural logarithm of @var{op}, +with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +If @var{op} contains negative numbers, then @var{rop} has at least one +NaN endpoint. +@end deftypefun + +@deftypefun int mpfi_exp (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the exponential of @var{op}, +with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_exp2 (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to 2 to the power @var{op}, with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_cos (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_sin (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_tan (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the cosine, sine or tangent of @var{op}, +with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + + +@deftypefun int mpfi_sec (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_csc (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_cot (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the secant, cosecant or cotangent of @var{op}, +with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + + +@c @deftypefun void mpfi_sin_cos (mpfi_t @var{sop}, mpfi_t @var{cop}, mpfi_t @var{op}) +@c Sets @var{sop} to the sine of @var{op}, @var{cop} to the cosine of @var{op}, +@c with the precision of the result (@var{sop} and @var{cop}). +@c @var{sop} and @var{cop} must be different variables. +@c If one of @var{sop} or @var{cop} is NULL, only the other value is returned. +@c @end deftypefun + +@deftypefun int mpfi_acos (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_asin (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_atan (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the arc-cosine, arc-sine or arc-tangent of @var{op}, +with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_atan2 (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfi_t @var{op2}) +Sets @var{rop} to the arc-tangent2 of @var{op1} and @var{op2}, +with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_cosh (mpfi_t @var{cop}, mpfi_t @var{op}) +@deftypefunx int mpfi_sinh (mpfi_t @var{sop}, mpfi_t @var{op}) +@deftypefunx int mpfi_tanh (mpfi_t @var{top}, mpfi_t @var{op}) +Sets @var{cop} to the hyperbolic cosine of @var{op}, +@var{sop} to the hyperbolic sine of @var{op}, +@var{top} to the hyperbolic tangent of @var{op}, +with the precision of the result. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_sech (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_csch (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_coth (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the hyperbolic secant, cosecant or cotangent of @var{op}, +with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + + +@deftypefun int mpfi_acosh (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_asinh (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_atanh (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the inverse hyperbolic cosine, sine or tangent of @var{op}, +with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_log1p (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the natural logarithm of one plus @var{op}, +with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +If @var{op} contains negative numbers, then @var{rop} has at least one +NaN endpoint. +@end deftypefun + +@deftypefun int mpfi_expm1 (mpfi_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the exponential of @var{op}, minus one, +with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_log2 (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_log10 (mpfi_t @var{rop}, mpfi_t @var{op}) +@ifinfo +Sets @var{rop} to log[t] @var{op} with t=2 or 10 the base for the +logarithm, with the precision of @var{rop}. +@end ifinfo +@iftex +@tex +Sets @var{rop} to $\log _t @var{op}$, with $t=2$ or 10 the base for +the logarithm, with the precision of @var{rop}. +@end tex +@end iftex +Returns an indication of whether none, one or both endpoints are exact. +If @var{op} contains negative numbers, then @var{rop} has at least one +NaN endpoint. +@end deftypefun + +@deftypefun int mpfi_hypot (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfi_t @var{op2}) +Sets @var{rop} to the euclidean distance between points in @var{op1} and points in @var{op2}, +with the precision of @var{rop}. +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@deftypefun int mpfi_const_log2 (mpfi_t @var{rop}) +@deftypefunx int mpfi_const_pi (mpfi_t @var{rop}) +@deftypefunx int mpfi_const_euler (mpfi_t @var{rop}) +@deftypefunx int mpfi_const_catalan (mpfi_t @var{rop}) +@ifinfo +Sets @var{rop} respectively to the logarithm of 2, to the value of Pi, +to the Euler's constant, and to the Catalan's constant, with the +precision of @var{rop}. +@end ifinfo +@iftex +@tex +Sets @var{rop} respectively to the logarithm of 2, to the value of +$\pi$, to the Euler's constant, and to the Catalan's constant, with +the precision of @var{rop}. +@end tex +@end iftex + +Returns an indication of whether none, one or both endpoints are exact. +@end deftypefun + +@node Interval Comparison, I/O of Intervals, Special Functions, Interval Functions +@comment node-name, next, previous, up +@section Comparison Functions +@cindex Interval comparisons functions +@cindex Comparison functions + +The comparison of two intervals is not clearly defined when they overlap. +MPFI proposes default comparison functions, but they can easily be customized +according to the user's needs. +The default comparison functions return a positive value if the first interval +has all its elements strictly greater than all elements of the second one, a +negative value if the first interval has all its elements strictly lower than +all elements of the second one and 0 otherwise, i.e.\ if they overlap or if one +is contained in the other. + +@deftypefun int mpfi_cmp (mpfi_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_cmp_d (mpfi_t @var{op1}, double @var{op2}) +@deftypefunx int mpfi_cmp_ui (mpfi_t @var{op1}, unsigned long int @var{op2}) +@deftypefunx int mpfi_cmp_si (mpfi_t @var{op1}, long int @var{op2}) +@deftypefunx int mpfi_cmp_z (mpfi_t @var{op1}, mpz_t @var{op2}) +@deftypefunx int mpfi_cmp_q (mpfi_t @var{op1}, mpq_t @var{op2}) +@deftypefunx int mpfi_cmp_fr (mpfi_t @var{op1}, mpfr_t @var{op2}) +@ifinfo +Compares @var{op1} and @var{op2}. Return a positive value if @var{op1} > +@var{op2}, zero if @var{op1} overlaps or contains @var{op2}, and a negative value if @var{op1} < +@var{op2}. +@end ifinfo +@iftex +@tex +Compares @var{op1} and @var{op2}. Return a positive value if $@var{op1} > +@var{op2}$, zero if @var{op1} overlaps, contains or is contained in @var{op2}, and a negative value if $@var{op1} +< @var{op2}$. +@end tex +@end iftex +In case one of the operands is invalid (which is represented by at least one NaN endpoint), it returns 1, even if +both are invalid. +@end deftypefun + +@deftypefun int mpfi_is_pos (mpfi_t @var{op}) +Returns a positive value if @var{op} contains only positive numbers, +the left endpoint can be zero. +@end deftypefun + +@deftypefun int mpfi_is_strictly_pos (mpfi_t @var{op}) +Returns a positive value if @var{op} contains only positive numbers. +@end deftypefun + +@deftypefun int mpfi_is_nonneg (mpfi_t @var{op}) +Returns a positive value if @var{op} contains only nonnegative numbers. +@end deftypefun + +@deftypefun int mpfi_is_neg (mpfi_t @var{op}) +Returns a positive value if @var{op} contains only negative numbers, +the right endpoint can be zero. +@end deftypefun + +@deftypefun int mpfi_is_strictly_neg (mpfi_t @var{op}) +Returns a positive value if @var{op} contains only negative numbers. +@end deftypefun + +@deftypefun int mpfi_is_nonpos (mpfi_t @var{op}) +Returns a positive value if @var{op} contains only nonpositive numbers. +@end deftypefun + +@deftypefun int mpfi_is_zero (mpfi_t @var{op}) +Returns a positive value if @var{op} contains only 0. +@end deftypefun + +@deftypefun int mpfi_has_zero (mpfi_t @var{op}) +Returns a positive value if @var{op} contains 0 (and possibly other numbers). +@end deftypefun + +@deftypefun int mpfi_nan_p (mpfi_t @var{op}) +Returns non-zero if @var{op} is invalid, i.e.\ at least one of its +endpoints is a Not-a-Number (NaN), zero otherwise. +@end deftypefun + +@deftypefun int mpfi_inf_p (mpfi_t @var{op}) +Returns non-zero if at least one of the endpoints of @var{op} is +plus or minus infinity, zero otherwise. +@end deftypefun + +@deftypefun int mpfi_bounded_p (mpfi_t @var{op}) +Returns non-zero if @var{op} is a bounded interval, i.e.\ neither invalid +nor (semi-)infinite. +@end deftypefun + + +@node I/O of Intervals, Operating on the Endpoints, Interval Comparison, Interval Functions +@comment node-name, next, previous, up +@section Input and Output Functions +@cindex Interval input and output functions +@cindex Input functions +@cindex Output functions +@cindex I/O functions + +Functions that perform input from a stdio stream, and functions that output to +a stdio stream. Passing a NULL pointer for a @var{stream} argument to any of +these functions will make them read from @code{stdin} and write to +@code{stdout}, respectively. + +When using any of these functions, it is a good idea to include @file{stdio.h} +before @file{mpfr.h}, since that will allow @file{mpfr.h} to define prototypes +for these functions. + +The input and output functions are based on the representation by endpoints. +The input function has to be improved. For the time being, it is +mandatory to insert spaces between the interval brackets and the +endpoints and also around the comma separating the endpoints. + +@deftypefun size_t mpfi_out_str (FILE *@var{stream}, int @var{base}, size_t @var{n_digits}, mpfi_t @var{op}) +Outputs @var{op} on stdio stream @var{stream}, as a string of digits in +base @var{base}. The output is an opening square bracket "[", followed by the lower +endpoint, a separating comma, the upper endpoint and a closing square bracket "]". + +For each endpoint, the output is performed by @code{mpfr_out_str}. +The following piece of information is taken from MPFR documentation. +The base may vary from 2 to 36. For each endpoint, it prints at most +@var{n_digits} significant digits, or if @var{n_digits} is 0, the maximum +number of digits accurately representable by @var{op}. +In addition to the significant digits, a decimal point at the right of the +first digit and a +trailing exponent, in the form @samp{eNNN}, are printed. If @var{base} +is greater than 10, @samp{@@} will be used instead of @samp{e} as +exponent delimiter. + +Returns the number of bytes written, or if an error occurred, return 0. + +As @code{mpfi_out_str} outputs an enclosure of the input interval, and as +@code{mpfi_inp_str} provides an enclosure of the interval it reads, these +functions are not reciprocal. More precisely, when they are called one after +the other, the resulting interval contains the initial one, and this inclusion +may be strict. +@end deftypefun + +@deftypefun size_t mpfi_inp_str (mpfi_t @var{rop}, FILE *@var{stream}, int @var{base}) +Inputs a string in base @var{base} from stdio stream @var{stream}, +and puts the +read float in @var{rop}. The string is of the form @samp{number} or +@samp{[ number1 , number 2 ]}. +@c where the spaces around the floating-point endpoints are mandatory. +Each endpoint has the form @samp{M@@N} or, if the +base is 10 or less, alternatively @samp{MeN} or @samp{MEN}. +@samp{M} is the significand and +@samp{N} is the exponent. The significand is always in the specified base. The +exponent is +@c either in the specified base or, if @var{base} is negative, +in decimal. + +The argument @var{base} may be in the ranges 2 to 36. +@c , or @minus{}36 to +@c @minus{}2. Negative values are used to specify that the exponent is in +@c decimal. + +Unlike the corresponding @code{mpz} function, the base will not be determined +from the leading characters of the string if @var{base} is 0. This is so that +numbers like @samp{0.23} are not interpreted as octal. + +Returns the number of bytes read, or if an error occurred, return 0. +@end deftypefun + +@deftypefun void mpfi_print_binary (mpfi_t @var{op}) +Outputs @var{op} on stdout +in raw binary format for each endpoint (the exponent is in decimal, yet). +The last bits from the least significant limb which do not belong to +the significand are printed between square brackets; +they should always be zero. +@end deftypefun + + +@node Operating on the Endpoints, Set Operations, I/O of Intervals, Interval Functions +@comment node-name, next, previous, up +@section Functions Operating on Endpoints +@cindex Functions operating on endpoints + +@deftypefun int mpfi_get_left (mpfr_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the left endpoint of @var{op}, rounded toward minus infinity. +It returns a negative value if @var{rop} differs from the left endpoint +of @var{op} (due to rounding) and 0 otherwise. +@end deftypefun + +@deftypefun int mpfi_get_right (mpfr_t @var{rop}, mpfi_t @var{op}) +Sets @var{rop} to the right endpoint of @var{op}, rounded toward plus infinity. +It returns a positive value if @var{rop} differs from the right endpoint +of @var{op} (due to rounding) and 0 otherwise. +@end deftypefun + +The following function should never be used... but it helps to return correct +intervals when there is a bug. + +@deftypefun int mpfi_revert_if_needed (mpfi_t @var{rop}) +Swaps the endpoints of @var{rop} if they are not properly ordered, +i.e.\ if the lower endpoint is greater than the right one. +It returns a non-zero value if the endpoints have been swapped, zero otherwise. +@end deftypefun + +@deftypefun int mpfi_put (mpfi_t @var{rop}, mpfi_t @var{op}) +@deftypefunx int mpfi_put_d (mpfi_t @var{rop}, double @var{op}) +@deftypefunx int mpfi_put_ui (mpfi_t @var{rop}, unsigned long int @var{op}) +@deftypefunx int mpfi_put_si (mpfi_t @var{rop}, long int @var{op}) +@deftypefunx int mpfi_put_z (mpfi_t @var{rop}, mpz_t @var{op}) +@deftypefunx int mpfi_put_q (mpfi_t @var{rop}, mpq_t @var{op}) +@deftypefunx int mpfi_put_fr (mpfi_t @var{rop}, mpfr_t @var{op}) +Extends the interval @var{rop} so that it contains @var{op}. +In other words, @var{rop} is set to the convex hull of @var{rop} and @var{op}. +It returns a value indicating whether none, one or both endpoints are inexact +(due to possible roundings). +@end deftypefun + +@deftypefun int mpfi_interv_d (mpfi_t @var{rop}, double @var{op1}, double @var{op2}) +@deftypefunx int mpfi_interv_ui (mpfi_t @var{rop}, unsigned long int @var{op1}, unsigned long int @var{op2}) +@deftypefunx int mpfi_interv_si (mpfi_t @var{rop}, long int @var{op1}, long int @var{op2}) +@deftypefunx int mpfi_interv_z (mpfi_t @var{rop}, mpz_t @var{op1}, mpz_t @var{op2}) +@deftypefunx int mpfi_interv_q (mpfi_t @var{rop}, mpq_t @var{op1}, mpq_t @var{op2}) +@deftypefunx int mpfi_interv_fr (mpfi_t @var{rop}, mpfr_t @var{op1}, mpfr_t @var{op2}) +Sets @var{rop} to the interval having as endpoints @var{op1} and @var{op2}. +The values of @var{op1} and @var{op2} are given in any order, the left +endpoints of @var{rop} is always the minimum of @var{op1} and +@var{rop2}. +It returns a value indicating whether none, one or both endpoints are inexact +(due to possible roundings). +@end deftypefun + + +@node Set Operations, Miscellaneous Interval Functions, Operating on the Endpoints, Interval Functions +@comment node-name, next, previous, up +@section Set Functions on Intervals +@cindex Set functions on intervals + +@deftypefun int mpfi_is_strictly_inside (mpfi_t @var{op1}, mpfi_t @var{op2}) +Returns a positive value if the second interval @var{op2} is contained in +the interior of @var{op1}, 0 otherwise. +@end deftypefun + +@deftypefun int mpfi_is_inside (mpfi_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_is_inside_d (double @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_is_inside_ui (unsigned long @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_is_inside_si (long int @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_is_inside_z (mpz_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_is_inside_q (mpq_t @var{op1}, mpfi_t @var{op2}) +@deftypefunx int mpfi_is_inside_fr (mpfr_t @var{op1}, mpfi_t @var{op2}) +Returns a positive value if @var{op1} is contained in @var{op2}, +0 otherwise. +Return 0 if at least one argument is NaN or an invalid interval. +@end deftypefun + +@deftypefun int mpfi_is_empty (mpfi_t @var{op}) +Returns a positive value if @var{op} is empty (its endpoints are in reverse order) +and 0 otherwise. Nothing is done in arithmetic or special functions +to handle empty intervals: this is the responsibility of the user +to avoid computing with empty intervals. +@end deftypefun + +@deftypefun int mpfi_intersect (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfi_t @var{op2}) +Sets @var{rop} to the intersection (possibly empty) of the intervals +@var{op1} and @var{op2}. +It returns a value indicating whether none, one or both endpoints are inexact +(due to possible roundings). +Warning: this function can return an empty interval (i.e.\ with endpoints +in reverse order). +@end deftypefun + +@deftypefun int mpfi_union (mpfi_t @var{rop}, mpfi_t @var{op1}, mpfi_t @var{op2}) +Sets @var{rop} to the convex hull of the union of the intervals @var{op1} and @var{op2}. +It returns a value indicating whether none, one or both endpoints are inexact +(due to possible roundings). +@end deftypefun + +@node Miscellaneous Interval Functions, Error Handling, Set Operations, Interval Functions +@comment node-name, next, previous, up +@section Miscellaneous Interval Functions +@cindex Miscellaneous interval functions + +@deftypefun int mpfi_increase (mpfi_t @var{rop}, mpfr_t @var{op}) +Subtracts @var{op} to the lower endpoint of @var{rop} and adds it to +the upper endpoint of @var{rop}, sets the resulting interval to @var{rop}. +It returns a value indicating whether none, one or both endpoints are inexact. +@end deftypefun + +@deftypefun int mpfi_blow (mpfi_t @var{rop}, mpfi_t @var{op1}, double @var{op2}) +@ifinfo +Sets @var{rop} to the interval whose center is the center of @var{op1} +and whose radius is the radius of @var{op1} multiplied by (1 + abs(@var{op2})). +@end ifinfo +@iftex +@tex +Sets @var{rop} to the interval whose center is the center of @var{op1} +and whose radius is the radius of @var{op1} multiplied by $(1 + | @var{op2} |)$. +@end tex +@end iftex +It returns a value indicating whether none, one or both endpoints are inexact. +@end deftypefun + +@deftypefun int mpfi_bisect (mpfi_t @var{rop1}, mpfi_t @var{rop2}, mpfi_t @var{op}) +Splits @var{op} into two halves and sets them to @var{rop1} and @var{rop2}. +Due to outward rounding, the two halves @var{rop1} and @var{rop2} may overlap. +It returns a value >0 if the splitting point is greater than the exact centre, +<0 if it is smaller and 0 if it is the exact centre. +@end deftypefun + +@deftypefun {const char *} mpfi_get_version () +Returns the MPFI version number as a NULL terminated string. +@end deftypefun + + +@node Error Handling, , Miscellaneous Interval Functions, Interval Functions +@comment node-name, next, previous, up +@section Error Handling +@cindex Error handling + +@deftypefn Macro void MPFI_ERROR ({char *} @var{msg}) +If there is no previous error, sets the error number to 1 and prints +the message @var{msg} to the standard error stream. If the error +number is already set, do nothing. +@end deftypefn + +@deftypefun int mpfi_is_error () +Returns 1 if the error number is set (to 1). +@end deftypefun + +@deftypefun void mpfi_set_error (int @var{op}) +Sets the error number to @var{op}. +@end deftypefun + +@deftypefun void mpfi_reset_error () +Resets the error number to 0. +@end deftypefun + +@node Contributors, References, Interval Functions, Top +@comment node-name, next, previous, up +@unnumbered Contributors + +MPFI has been written by Fabrice Rouillier, Nathalie Revol, Sylvain +Chevillard, Hong Diep Nguyen, Christoph Lauter and Philippe Th@'eveny. Its development +has greatly benefited from the patient and supportive help of the MPFR +team. + +@node References, Concept Index, Contributors, Top +@comment node-name, next, previous, up +@unnumbered References + +This is a largely lacunary list of introductory references. +@itemize @bullet + +@item MPFR team (SPACES project, INRIA Lorraine and LORIA), +"MPFR. The Multiple Precision Floating-Point Reliable Library", +available at @code{http://www.mpfr.org}. + +@item +The main Web site for interval computations is +@url{http://cs.utep.edu/interval-comp/main.html}. + +@item +The Web site of the IEEE-1788 working group for the standardization +of interval arithmetic is +@url{http://grouper.ieee.org/groups/1788/}. + +@item +G. Alefeld and J. Herzberger, "Introduction to interval analysis", +Academic Press, 1983. + +@item +R. Baker Kearfott, "Rigorous global search: continuous problems", +Kluwer, 1996. + +@item +T. Hickey and Q. Ju and M. H. Van Emden, +"Interval arithmetic: From principles to implementation", +Journal of the ACM, vol. 48, no 4, pp 1038--1068, September 2001. + +@item +E. Hansen, "Global optimization using interval analysis", +Marcel Dekker, 1992. + +@item +A. Neumaier, "Interval methods for systems of equations", +Cambridge University Press, 1990. + +@item +H. Ratschek and J. Rokne, "New computer methods for global optimization", +Ellis Horwood Ltd, 1988. + +@item +N. Revol and F. Rouillier, +"Motivations for an arbitrary precision interval arithmetic and the MPFI library", +Reliable Computing, vol. 11, no 4, pp 275--290, 2005. +@end itemize + + +@node Concept Index, Function Index, References, Top +@comment node-name, next, previous, up +@unnumbered Concept Index +@printindex cp + +@node Function Index, , Concept Index, Top +@comment node-name, next, previous, up +@unnumbered Function and Type Index +@printindex fn + + +@contents +@bye diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..5a27590 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,56 @@ +lib_LTLIBRARIES = libmpfi.la + +# apparently the type "intmax_t" s not always known +# and consequently set_sj, set_uj cause trouble +#libmpfi_la_SOURCES = mpfi-impl.h abs.c acos.c acosh.c add.c \ +# add_d.c add_fr.c add_q.c add_si.c add_ui.c add_z.c alea.c \ +# asin.c asinh.c atan2.c atan.c atanh.c bisect.c blow.c \ +# cbrt.c clear.c clears.c cmp.c cmp_sym_pi.c constants.c cos.c \ +# cosh.c csc.c csch.c cot.c coth.c d_div.c d_sub.c diam.c \ +# div.c div_2exp.c div_2si.c div_2ui.c div_d.c div_ext.c div_fr.c \ +# div_q.c div_si.c div_ui.c div_z.c erandom.c error.c exp.c \ +# exp2.c expm1.c fr_div.c fr_sub.c get_endpoints.c get_fr.c \ +# get_d.c get_prec.c get_version.c has_zero.c hypot.c \ +# increase.c init.c init2.c inits.c inits2.c intersect.c \ +# interv_d.c interv_fr.c \ +# interv_q.c interv_si.c interv_ui.c interv_z.c inp_str.c \ +# inv.c is_empty.c is_inside.c log.c log10.c log1p.c log2.c \ +# mag.c mid.c mig.c mul.c mul_2exp.c mul_2si.c mul_2ui.c \ +# mul_d.c mul_fr.c mul_q.c mul_si.c mul_ui.c mul_z.c neg.c \ +# nrandom.c out_str.c predicates.c print_binary.c put.c \ +# put_d.c put_fr.c put_q.c put_si.c put_ui.c put_z.c q_div.c \ +# q_sub.c quadrant.c revert_if_needed.c round_prec.c sec.c \ +# sech.c set.c set_d.c set_flt.c set_fr.c set_ld.c set_prec.c set_q.c \ +# set_si.c set_sj.c set_str.c set_ui.c set_uj.c set_z.c \ +# si_div.c si_sub.c sign.c sin.c \ +# sinh.c sqr.c sqrt.c sub.c sub_d.c sub_fr.c sub_q.c \ +# sub_si.c sub_ui.c sub_z.c swap.c tan.c tanh.c ui_div.c \ +# ui_sub.c union.c urandom.c z_div.c z_sub.c + +libmpfi_la_SOURCES = mpfi-impl.h abs.c acos.c acosh.c add.c \ + add_d.c add_fr.c add_q.c add_si.c add_ui.c add_z.c alea.c \ + asin.c asinh.c atan2.c atan.c atanh.c bisect.c blow.c \ + cbrt.c clear.c clears.c cmp.c cmp_sym_pi.c constants.c cos.c \ + cosh.c csc.c csch.c cot.c coth.c d_div.c d_sub.c diam.c \ + div.c div_2exp.c div_2si.c div_2ui.c div_d.c div_ext.c div_fr.c \ + div_q.c div_si.c div_ui.c div_z.c erandom.c error.c exp.c \ + exp2.c expm1.c fr_div.c fr_sub.c get_endpoints.c get_fr.c \ + get_d.c get_prec.c get_version.c has_zero.c hypot.c \ + increase.c init.c init2.c inits.c inits2.c intersect.c \ + interv_d.c interv_fr.c \ + interv_q.c interv_si.c interv_ui.c interv_z.c inp_str.c \ + inv.c is_empty.c is_inside.c log.c log10.c log1p.c log2.c \ + mag.c mid.c mig.c mul.c mul_2exp.c mul_2si.c mul_2ui.c \ + mul_d.c mul_fr.c mul_q.c mul_si.c mul_ui.c mul_z.c neg.c \ + nrandom.c out_str.c predicates.c print_binary.c put.c \ + put_d.c put_fr.c put_q.c put_si.c put_ui.c put_z.c q_div.c \ + q_sub.c quadrant.c revert_if_needed.c round_prec.c sec.c \ + sech.c set.c set_d.c set_flt.c set_fr.c set_ld.c set_prec.c set_q.c \ + set_si.c set_str.c set_ui.c set_z.c \ + si_div.c si_sub.c sign.c sin.c \ + sinh.c sqr.c sqrt.c sub.c sub_d.c sub_fr.c sub_q.c \ + sub_si.c sub_ui.c sub_z.c swap.c tan.c tanh.c ui_div.c \ + ui_sub.c union.c urandom.c z_div.c z_sub.c +libmpfi_la_LDFLAGS = -no-undefined + +AM_CPPFLAGS =-I$(top_srcdir) diff --git a/src/abs.c b/src/abs.c new file mode 100644 index 0000000..8c7379f --- /dev/null +++ b/src/abs.c @@ -0,0 +1,58 @@ +/* abs.c -- Absolute value. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_abs (mpfi_ptr a, mpfi_srcptr b) +{ + /* the result a contains the absolute values of every element of b */ + int inexact_right, inexact = 0; + + if (MPFI_NAN_P (b)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_IS_NONNEG (b)) + inexact = mpfi_set (a, b); + else if (MPFI_IS_NONPOS (b)) + inexact = mpfi_neg (a, b); + else { /* b contains 0 */ + if (mpfr_cmpabs (&(b->left), &(b->right)) < 0) { + inexact_right = mpfr_set (&(a->right), &(b->right), MPFI_RNDU); + } + else { + inexact_right = mpfr_neg (&(a->right), &(b->left), MPFI_RNDU); + } + mpfr_set_si (&(a->left), 0, MPFI_RNDD); + + if (inexact_right) + inexact += 2; + } + + return inexact; +} diff --git a/src/acos.c b/src/acos.c new file mode 100644 index 0000000..615ce76 --- /dev/null +++ b/src/acos.c @@ -0,0 +1,49 @@ +/* acos.c -- Arc cosine of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_acos (mpfi_ptr a, mpfi_srcptr b) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact=0; + + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_acos (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_acos (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/acosh.c b/src/acosh.c new file mode 100644 index 0000000..b48958e --- /dev/null +++ b/src/acosh.c @@ -0,0 +1,50 @@ +/* acosh.c -- Inverse hyperbolic cosine of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_acosh (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_acosh (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_acosh (&(a->right), &(b->right), MPFI_RNDU); + + if (mpfr_sgn (&(a->right)) == 0) { + /* -0 as right endpoint */ + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/add.c b/src/add.c new file mode 100644 index 0000000..4f477a9 --- /dev/null +++ b/src/add.c @@ -0,0 +1,63 @@ +/* add.c -- Add two intervals. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_add (mpfi_ptr a, mpfi_srcptr b, mpfi_srcptr c) +/* relies on the fact that each operand is OK, */ +/* ie its left endpoint is <= its right one. */ +/* This should always hold. */ +{ + int inexact_left, inexact_right, inexact=0; + + if (MPFI_IS_ZERO (c)) { + return (mpfi_set (a,b)); + } + else if (MPFI_IS_ZERO (b)) { + return (mpfi_set (a,c)); + } + else { + inexact_left = mpfr_add (&(a->left), &(b->left), &(c->left),MPFI_RNDD); + inexact_right = mpfr_add (&(a->right), &(b->right), &(c->right),MPFI_RNDU); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } +} diff --git a/src/add_d.c b/src/add_d.c new file mode 100644 index 0000000..dba53be --- /dev/null +++ b/src/add_d.c @@ -0,0 +1,54 @@ +/* add_d.c -- Interval translation. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_add_d (mpfi_ptr a, mpfi_srcptr b, const double c) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_add_d (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_add_d (&(a->right), &(b->right), c, MPFI_RNDU); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/add_fr.c b/src/add_fr.c new file mode 100644 index 0000000..7933065 --- /dev/null +++ b/src/add_fr.c @@ -0,0 +1,60 @@ +/* add_fr.c -- Add an interval and a floating-point number. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_add_fr (mpfi_ptr a, mpfi_srcptr b, mpfr_srcptr c) +{ + mpfr_t tmp; mpfr_prec_t prec; + int inexact_left, inexact_right, inexact = 0; + + prec = mpfi_get_prec(a); + mpfr_init2(tmp, prec); /* in case c is one of the endpoint of a, a temporary is needed */ + + inexact_left = mpfr_add (tmp, &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_add (&(a->right), &(b->right), c, MPFI_RNDU); + mpfr_set(&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear(tmp); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/add_q.c b/src/add_q.c new file mode 100644 index 0000000..145254f --- /dev/null +++ b/src/add_q.c @@ -0,0 +1,54 @@ +/* add_q.c -- Add an interval and a rational number. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_add_q (mpfi_ptr a, mpfi_srcptr b, mpq_srcptr c) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_add_q (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_add_q (&(a->right), &(b->right), c, MPFI_RNDU); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/add_si.c b/src/add_si.c new file mode 100644 index 0000000..41e6a97 --- /dev/null +++ b/src/add_si.c @@ -0,0 +1,54 @@ +/* add_si.c -- Add an interval and a signed long int. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_add_si (mpfi_ptr a, mpfi_srcptr b, const long c) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_add_si (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_add_si (&(a->right), &(b->right), c, MPFI_RNDU); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/add_ui.c b/src/add_ui.c new file mode 100644 index 0000000..eb11132 --- /dev/null +++ b/src/add_ui.c @@ -0,0 +1,61 @@ +/* add_ui.c -- Add an interval and an unsigned long int. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_add_ui (mpfi_ptr a, mpfi_srcptr b, const unsigned long c) +{ + int inexact_left, inexact_right, inexact = 0; + + if (c == 0) { + return ( mpfi_set (a,b) ); + } + else if (MPFI_IS_ZERO (b)) { + return ( mpfi_set_ui (a,c) ); + } + else { + inexact_left = mpfr_add_ui (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_add_ui (&(a->right), &(b->right), c, MPFI_RNDU); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } +} diff --git a/src/add_z.c b/src/add_z.c new file mode 100644 index 0000000..1463626 --- /dev/null +++ b/src/add_z.c @@ -0,0 +1,54 @@ +/* add_z.c -- Add an interval an an integer. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_add_z (mpfi_ptr a, mpfi_srcptr b, mpz_srcptr c) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_add_z (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_add_z (&(a->right), &(b->right), c, MPFI_RNDU); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/alea.c b/src/alea.c new file mode 100644 index 0000000..9beb3ca --- /dev/null +++ b/src/alea.c @@ -0,0 +1,41 @@ +/* alea.c -- Random element in the interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Picks randomly a point m in y */ +void +mpfi_alea (mpfr_ptr m, mpfi_srcptr y) +{ + static gmp_randstate_t state; + static int init = 0; + + if (!init) { + gmp_randinit_default (state); + init = -1; + } + + mpfi_urandom (m, y, state); +} diff --git a/src/asin.c b/src/asin.c new file mode 100644 index 0000000..d4ca868 --- /dev/null +++ b/src/asin.c @@ -0,0 +1,45 @@ +/* asin.c -- Arc sine of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_asin (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_asin (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_asin (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/asinh.c b/src/asinh.c new file mode 100644 index 0000000..d662a6b --- /dev/null +++ b/src/asinh.c @@ -0,0 +1,45 @@ +/* asinh.c -- Inverse hyperbolic sine. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_asinh (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_asinh (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_asinh (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/atan.c b/src/atan.c new file mode 100644 index 0000000..2a7aa4b --- /dev/null +++ b/src/atan.c @@ -0,0 +1,45 @@ +/* atan.c -- Arc tangent of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_atan (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_atan (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_atan (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/atan2.c b/src/atan2.c new file mode 100644 index 0000000..ffd0429 --- /dev/null +++ b/src/atan2.c @@ -0,0 +1,100 @@ +/* atan2.c -- Arc tangent of two intervals. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_atan2 (mpfi_ptr a, mpfi_srcptr b, mpfi_srcptr c) +{ + int inexact_left, inexact_right, inexact=0; + mpfi_t tmp; + + if ( MPFI_NAN_P (b) || MPFI_NAN_P (c) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + mpfi_init2 (tmp, mpfi_get_prec (a)); + + if (MPFI_IS_POS (b)) { + if (MPFI_IS_POS (c)) { + inexact_left = mpfr_atan2 (&(tmp->left), &(b->left), &(c->right), MPFI_RNDD); + inexact_right = mpfr_atan2 (&(tmp->right), &(b->right), &(c->left), MPFI_RNDU); + } + else if (MPFI_IS_NEG (c)) { + inexact_left = mpfr_atan2 (&(tmp->left), &(b->right), &(c->right), MPFI_RNDD); + inexact_right = mpfr_atan2 (&(tmp->right), &(b->left), &(c->left), MPFI_RNDU); + } + else { + inexact_left = mpfr_atan2 (&(tmp->left), &(b->left), &(c->right), MPFI_RNDD); + inexact_right = mpfr_atan2 (&(tmp->right), &(b->left), &(c->left), MPFI_RNDU); + } + } + else if (MPFI_IS_NEG (b)) { + if (MPFI_IS_POS (c)) { + inexact_left = mpfr_atan2 (&(tmp->left), &(b->left), &(c->left), MPFI_RNDD); + inexact_right = mpfr_atan2 (&(tmp->right), &(b->right), &(c->right), MPFI_RNDU); + } + else if (MPFI_IS_NEG (c)) { + inexact_left = mpfr_atan2 (&(tmp->left), &(b->right), &(c->left), MPFI_RNDD); + inexact_right = mpfr_atan2 (&(tmp->right), &(b->left), &(c->right), MPFI_RNDU); + } + else { + inexact_left = mpfr_atan2 (&(tmp->left), &(b->right), &(c->left), MPFI_RNDD); + inexact_right = mpfr_atan2 (&(tmp->right), &(b->right), &(c->right), MPFI_RNDU); + } + } + else { + if (MPFI_IS_POS (c)) { + inexact_left = mpfr_atan2 (&(tmp->left), &(b->left), &(c->left), MPFI_RNDD); + inexact_right = mpfr_atan2 (&(tmp->right), &(b->right), &(c->left), MPFI_RNDU); + } + else { + inexact_left = -mpfr_const_pi (&(tmp->left), MPFI_RNDU); + mpfr_neg (&(tmp->left), &(tmp->left), MPFI_RNDD); + inexact_right = mpfr_const_pi (&(tmp->right), MPFI_RNDU); + } + } + + if (mpfr_sgn (&(tmp->left)) == 0) { + /* +0 as left endpoint */ + mpfr_setsign (&(tmp->left), &(tmp->left), 0, MPFI_RNDU); + } + if (mpfr_sgn (&(tmp->right)) == 0) { + /* -0 as right endpoint */ + mpfr_setsign (&(tmp->right), &(tmp->right), 1, MPFI_RNDD); + } + + mpfi_set (a, tmp); + mpfi_clear (tmp); + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/atanh.c b/src/atanh.c new file mode 100644 index 0000000..b91f62a --- /dev/null +++ b/src/atanh.c @@ -0,0 +1,45 @@ +/* atanh.c -- Inverse hyperbolic tangent of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_atanh (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_atanh (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_atanh (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/bisect.c b/src/bisect.c new file mode 100644 index 0000000..2d1501a --- /dev/null +++ b/src/bisect.c @@ -0,0 +1,76 @@ +/* bisect.c -- Split an interval into two halves. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2011, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_bisect (mpfi_ptr y1, mpfi_ptr y2, mpfi_srcptr y) +{ + mpfr_prec_t prec, prec1, prec2; + mpfr_t centre; + int inexact_centre; + + if ( MPFI_NAN_P (y) ) { + mpfr_set_nan (&(y1->left)); + mpfr_set_nan (&(y1->right)); + mpfr_set_nan (&(y2->left)); + mpfr_set_nan (&(y2->right)); + MPFR_RET_NAN; + } + else if ( !mpfi_bounded_p (y) ) { + mpfi_set (y1, y); + mpfr_set_nan (&(y2->left)); + mpfr_set_nan (&(y2->right)); + MPFR_RET_NAN; + } + + prec = mpfi_get_prec (y); + prec1 = mpfi_get_prec (y1); + prec2 = mpfi_get_prec (y2); + if ( (prec1 >= prec2) && (prec1 >= prec)) + prec = prec1; + else if ( (prec2 >= prec1) && (prec2 >= prec)) + prec = prec2; + mpfr_init2 (centre, prec); + + inexact_centre = mpfi_mid (centre, y); + + mpfr_set (&(y1->left), &(y->left), MPFI_RNDD); + mpfr_set (&(y2->right), &(y->right), MPFI_RNDU); + mpfr_set (&(y1->right), centre, MPFI_RNDU); /* FIXME: double rounding + error */ + mpfr_set (&(y2->left), centre, MPFI_RNDD); /* FIXME: double rounding + error */ + + /* do not allow +0 as upper bound. Note that left endpoint of y2 + cannot be -0 because if centre is zero its precision is + sufficient for it to be an exact result (then center = +0). */ + if (mpfr_zero_p (&(y1->right)) && !mpfr_signbit (&(y1->right))) { + mpfr_neg (&(y1->right), &(y1->right), MPFI_RNDD); + } + + mpfr_clear (centre); + return inexact_centre; +} diff --git a/src/blow.c b/src/blow.c new file mode 100644 index 0000000..bcb3bf0 --- /dev/null +++ b/src/blow.c @@ -0,0 +1,96 @@ +/* blow.c -- Interval blow. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* keeps the same center and multiplies the radius by (1+fact), the result may + be grossly overestimated */ + +int +mpfi_blow (mpfi_ptr y, mpfi_srcptr x, double fact) +/* if c = mid (x) and r = rad (x), y = [c - (1+fact)*r , c + (1+fact)*r] */ +{ + mpfr_prec_t prec; + mpfr_t radius, factor; + mpfr_t centre; + int inex_diam, inex_div, inex_conv, inex_factor, inex_rad; + int inex_centre, inex_left, inex_right; + int inexact = 0; + + if (MPFI_NAN_P (x)) { + mpfr_set_nan (&(y->left)); + mpfr_set_nan (&(y->right)); + MPFR_RET_NAN; + } + + prec = mpfi_get_prec (x); + mpfr_init2 (radius, prec); + mpfr_init2 (factor, prec); + mpfr_init2 (centre, prec); + + inex_diam = mpfi_diam_abs (radius, x); + if (mpfr_zero_p (radius)) { + /* x is a singleton */ + return mpfi_set (y, x); + } + inex_div = mpfr_div_2exp (radius, radius, 1, MPFI_RNDU); /* either underflow + or exact*/ + + /* factor must be greater than 1 + |fact|, so it is not possible to perform + this addition directly in C with the double precision since the usual + rouding mode is rounding to nearest. */ + inex_conv = mpfr_set_d (factor, fact < 0.0 ? -fact : fact, MPFI_RNDU); + inex_factor = mpfr_add_ui (factor, factor, 1, MPFI_RNDU); + + inex_rad = mpfr_mul (radius, radius, factor, MPFI_RNDU); + inex_centre = mpfi_mid (centre, x); + inex_left = mpfr_sub (&(y->left), centre, radius, MPFI_RNDD); + inex_right = mpfr_add (&(y->right), centre, radius, MPFI_RNDU); + + mpfr_clear (radius); + mpfr_clear (factor); + mpfr_clear (centre); + + if ( MPFI_NAN_P (y) ) + MPFR_RET_NAN; + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(y->left)) && mpfr_signbit (&(y->left))) { + mpfr_neg (&(y->left), &(y->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(y->right)) && !mpfr_signbit (&(y->right))) { + mpfr_neg (&(y->right), &(y->right), MPFI_RNDD); + } + + if (inex_diam || inex_div || inex_conv || inex_factor || inex_rad + || inex_centre || inex_left) + inexact += 1; + if (inex_diam || inex_div || inex_conv || inex_factor || inex_rad + || inex_centre || inex_right) + inexact += 2; + + return inexact; +} diff --git a/src/cbrt.c b/src/cbrt.c new file mode 100644 index 0000000..42fc92a --- /dev/null +++ b/src/cbrt.c @@ -0,0 +1,45 @@ +/* cbrt.c -- Cubic root of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_cbrt (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_cbrt (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_cbrt (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/clear.c b/src/clear.c new file mode 100644 index 0000000..712667e --- /dev/null +++ b/src/clear.c @@ -0,0 +1,36 @@ +/* clear.c -- Free the memory space allocated for an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +void +mpfi_clear (mpfi_ptr a) +{ + /* There is no test to check that the two endpoints are different + and thus are not cleared twice. They should be different if only + mpfi functions have been used... */ + mpfr_clear (&(a->right)); + mpfr_clear (&(a->left)); +} diff --git a/src/clears.c b/src/clears.c new file mode 100644 index 0000000..a0b5bca --- /dev/null +++ b/src/clears.c @@ -0,0 +1,72 @@ +/* mpfi_clears -- free the memory space allocated for several intervals + + +Copyright 2018 Free Software Foundation, Inc. +Contributed by the AriC project, INRIA. + +This file is part of the GNU MPFI Library. + +The GNU MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* +#ifdef HAVE_CONFIG_H +# undef HAVE_STDARG +# include "config.h" +#endif + +#if HAVE_STDARG +# include +#else +# include +#endif +*/ + +#include +#include "mpfi-impl.h" + +/* +void +#if HAVE_STDARG +mpfi_clears (mpfi_ptr x, ...) +#else +mpfi_clears (va_alist) + va_dcl +#endif +{ + va_list arg; + +#if HAVE_STDARG + va_start (arg, x); +#else + mpfi_ptr x; + va_start(arg); + x = va_arg (arg, mpfi_ptr); +#endif +*/ + +void mpfi_clears (mpfi_ptr x, ...) +{ + va_list arg; + + va_start(arg, x); + + while (x != 0) + { + mpfi_clear (x); + x = (mpfi_ptr) va_arg (arg, mpfi_ptr); + } + va_end (arg); +} diff --git a/src/cmp.c b/src/cmp.c new file mode 100644 index 0000000..c6c54df --- /dev/null +++ b/src/cmp.c @@ -0,0 +1,136 @@ +/* cmp.c -- Default comparison functions. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2011, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Warning: there is no canonical order => */ +/* interval comparison is not clearly defined */ + +/* Customizable comparison functions */ +/* Since the mpfi_cmp_* are based on mpfi_cmp, only mpfi_cmp needs to be modified */ + +int (*mpfi_cmp) (mpfi_srcptr, mpfi_srcptr) = mpfi_cmp_default; +int (*mpfi_cmp_d) (mpfi_srcptr, const double) = mpfi_cmp_d_default; +int (*mpfi_cmp_ui) (mpfi_srcptr, const unsigned long) = mpfi_cmp_ui_default; +int (*mpfi_cmp_si) (mpfi_srcptr, const long) = mpfi_cmp_si_default; +int (*mpfi_cmp_z) (mpfi_srcptr, mpz_srcptr) = mpfi_cmp_z_default; +int (*mpfi_cmp_q) (mpfi_srcptr, mpq_srcptr) = mpfi_cmp_q_default; +int (*mpfi_cmp_fr) (mpfi_srcptr, mpfr_srcptr) = mpfi_cmp_fr_default; + +/* Default comparison functions */ +/* They return 1 if one (at least) of their operands is invalid (contains NaN) */ + +int +mpfi_cmp_default (mpfi_srcptr a, mpfi_srcptr b) +{ + if ( MPFI_NAN_P (a) || MPFI_NAN_P (b) ) + return 1; + return ( (mpfr_cmp (&(a->right), &(b->left)) < 0) ? -1 + :(mpfr_cmp (&(b->right), &(a->left)) < 0) ); +} + +int +mpfi_cmp_d_default (mpfi_srcptr a, const double b) +{ + int res = 0; + mpfi_t tmp; + + mpfi_init2 (tmp, mpfi_get_prec (a)); + mpfi_set_d (tmp, b); + res = mpfi_cmp (a, tmp); + MPFI_CLEAR (tmp); + + return (res); +} + +int +mpfi_cmp_ui_default (mpfi_srcptr a, const unsigned long b) +{ + int res = 0; + mpfi_t tmp; + + mpfi_init2 (tmp, mpfi_get_prec (a)); + mpfi_set_ui (tmp, b); + res = mpfi_cmp (a, tmp); + MPFI_CLEAR (tmp); + + return (res); +} + +int +mpfi_cmp_si_default (mpfi_srcptr a, const long b) +{ + int res = 0; + mpfi_t tmp; + + mpfi_init2 (tmp, mpfi_get_prec (a)); + mpfi_set_si (tmp, b); + res = mpfi_cmp (a, tmp); + MPFI_CLEAR (tmp); + + return (res); +} + +int +mpfi_cmp_z_default (mpfi_srcptr a, mpz_srcptr b) +{ + int res = 0; + mpfi_t tmp; + + mpfi_init2 (tmp, mpfi_get_prec (a)); + mpfi_set_z (tmp, b); + res = mpfi_cmp (a, tmp); + MPFI_CLEAR (tmp); + + return (res); +} + +int +mpfi_cmp_q_default (mpfi_srcptr a, mpq_srcptr b) +{ + int res = 0; + mpfi_t tmp; + + mpfi_init2 (tmp, mpfi_get_prec (a)); + mpfi_set_q (tmp, b); + res = mpfi_cmp (a, tmp); + MPFI_CLEAR (tmp); + + return (res); +} + +int +mpfi_cmp_fr_default (mpfi_srcptr a, mpfr_srcptr b) +{ + int res = 0; + mpfi_t tmp; + + mpfi_init2 (tmp, mpfi_get_prec (a)); + mpfi_set_fr (tmp, b); + res = mpfi_cmp (a, tmp); + MPFI_CLEAR (tmp); + + return (res); +} diff --git a/src/cmp_sym_pi.c b/src/cmp_sym_pi.c new file mode 100644 index 0000000..12b58cb --- /dev/null +++ b/src/cmp_sym_pi.c @@ -0,0 +1,71 @@ +/* cmp_sym_pi.c -- Internal function. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* compares z * Pi/2 - x and y where z is an integer (mpz) */ +/* the result is exact */ +int +mpfi_cmp_sym_pi (mpz_srcptr z, mpfr_srcptr x, mpfr_srcptr y, mpfr_prec_t prec_init) +{ + /* Assumption: x and y are neither NaN nor Infinite */ + mpfr_prec_t prec; + mpfi_t pi_over_two, tmp; + int not_ok; + + + prec = prec_init; + mpfi_init2 (pi_over_two, prec); + mpfi_init2 (tmp, prec); + + if (mpz_cmp_ui (z, 0) == 0) { + not_ok=0; + mpfi_set_prec (tmp, mpfr_get_prec (x)); + mpfi_set_fr (tmp, x); + mpfi_neg (tmp, tmp); + } + else { + do { + mpfi_const_pi (pi_over_two); + mpfi_div_2exp (pi_over_two, pi_over_two, 1); + + mpfi_mul_z (tmp, pi_over_two, z); + mpfi_sub_fr (tmp, tmp, x); + + not_ok = mpfi_is_inside_fr (y, tmp); + if (not_ok) { + prec += BITS_PER_MP_LIMB; + mpfi_set_prec (pi_over_two, prec); + mpfi_set_prec (tmp, prec); + } + } while (not_ok); + } + + not_ok = mpfi_cmp_fr_default (tmp, y); + mpfi_clear (pi_over_two); + mpfi_clear (tmp); + + return not_ok; +} diff --git a/src/constants.c b/src/constants.c new file mode 100644 index 0000000..6568a5e --- /dev/null +++ b/src/constants.c @@ -0,0 +1,62 @@ +/* constants.c -- Useful constants. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_const_log2 (mpfi_ptr a) +{ + mpfr_const_log2 (&(a->left), MPFI_RNDD); + mpfr_const_log2 (&(a->right), MPFI_RNDU); + + return MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT; +} + +int +mpfi_const_pi (mpfi_ptr a) +{ + mpfr_const_pi (&(a->left), MPFI_RNDD); + mpfr_const_pi (&(a->right), MPFI_RNDU); + + return MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT; +} + +int +mpfi_const_euler (mpfi_ptr a) +{ + mpfr_const_euler (&(a->left), MPFI_RNDD); + mpfr_const_euler (&(a->right), MPFI_RNDU); + + return MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT; +} + +int +mpfi_const_catalan (mpfi_ptr a) +{ + mpfr_const_catalan (&(a->left), MPFI_RNDD); + mpfr_const_catalan (&(a->right), MPFI_RNDU); + + return MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT; +} diff --git a/src/cos.c b/src/cos.c new file mode 100644 index 0000000..77dc91a --- /dev/null +++ b/src/cos.c @@ -0,0 +1,210 @@ +/* cos.c -- Cosine of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_cos (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + mpfr_prec_t prec, prec_left, prec_right; + mpfr_t tmp; + mpz_t z, zmod4; + mpz_t quad_left, quad_right; + int ql_mod4, qr_mod4; + + if (MPFI_NAN_P (b)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_INF_P (b)) { + /* the two endpoints are the same infinite */ + if ( mpfr_cmp (&(b->left), &(b->right)) == 0) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + mpfr_set_si (&(a->left), -1, MPFI_RNDD); + mpfr_set_si (&(a->right), 1, MPFI_RNDU); + return 0; + } + + mpz_init (quad_left); + mpz_init (quad_right); + mpz_init (z); + /* quad_left gives the quadrant where the left endpoint of b is */ + /* quad_left = floor (2 b->left / pi) */ + /* idem for quad_right and b->right */ + prec_left = mpfi_quadrant (quad_left, &(b->left)); + prec_right = mpfi_quadrant (quad_right, &(b->right)); + + /* if there is at least one period in b, then a = [-1, 1] */ + mpz_sub (z, quad_right, quad_left); + if (mpz_cmp_ui (z, 4) >= 0) { + mpfr_set_si (&(a->left), -1, MPFI_RNDD); + mpfr_set_si (&(a->right), 1, MPFI_RNDU); + inexact = 0; + } + else { + /* there is less than one period in b */ + /* let us discuss according to the position (quadrant) of the endpoints of + b */ + + /* computing precision = maximal precision required to determine the + relative position of the endpoints of b and of integer multiples of + Pi / 2 */ + prec = mpfi_get_prec (a); + if (prec_left > prec) prec = prec_left; + if (prec_right > prec) prec = prec_right; + + mpz_add (z, quad_left, quad_right); + /* z = quad_right + quad_left */ + + mpz_init (zmod4); + + /* qr_mod4 gives the quadrant where the right endpoint of b is */ + /* qr_mod4 = floor (2 b->right / pi) mod 4 */ + mpz_mod_ui (zmod4, quad_right, 4); + qr_mod4 = mpz_get_ui (zmod4); + + /* quad_left gives the quadrant where the left endpoint of b is */ + /* quad_left = floor (2 b->left / pi) mod 4 */ + mpz_mod_ui (zmod4, quad_left, 4); + ql_mod4 = mpz_get_ui (zmod4); + + + switch (qr_mod4) { + case 0: + switch (ql_mod4) { + case 0: + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_cos (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_cos (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + break; + case 1: + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + case 2: + inexact_left = mpfr_cos (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + case 3: + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->right), &(b->left), prec) >= 0) + inexact_left = mpfr_cos (&(a->left), &(b->left), MPFI_RNDD); + else + inexact_left = mpfr_cos (&(a->left), &(b->right), MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + } + break; + case 1: + switch (ql_mod4) { + case 0: + case 1: + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_cos (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_cos (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + break; + case 2: + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->right), &(b->left), prec) >= 0) + inexact_left = mpfr_cos (&(a->left), &(b->left), MPFI_RNDD); + else + inexact_left = mpfr_cos (&(a->left), &(b->right), MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + case 3: + inexact_left = mpfr_cos (&(a->left), &(b->right), MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + } + break; + case 2: + switch (ql_mod4) { + case 0: + inexact_right = mpfr_cos (&(a->right), &(b->left), MPFI_RNDU); + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + break; + case 1: + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->left), &(b->right), prec) >= 0) + inexact_right = mpfr_cos (&(a->right), &(b->left), MPFI_RNDU); + else + inexact_right = mpfr_cos (&(a->right), &(b->right), MPFI_RNDU); + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + break; + case 2: + inexact_left = mpfr_cos (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_cos (&(a->right), &(b->right), MPFI_RNDU); + break; + case 3: + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + } + break; + case 3: + switch (ql_mod4) { + case 0: + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->right), &(b->left), prec) >= 0) + inexact_right = mpfr_cos (&(a->right), &(b->left), MPFI_RNDU); + else + inexact_right = mpfr_cos (&(a->right), &(b->right), MPFI_RNDU); + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + break; + case 1: + inexact_right = mpfr_cos (&(a->right), &(b->right), MPFI_RNDU); + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + break; + case 2: + case 3: + inexact_left = mpfr_cos (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_cos (&(a->right), &(b->right), MPFI_RNDU); + break; + } + break; + } + + if (inexact_left) inexact = 1; + if (inexact_right) inexact += 2; + + mpz_clear (zmod4); + } + + mpz_clear (quad_left); + mpz_clear (quad_right); + mpz_clear (z); + + return inexact; +} diff --git a/src/cosh.c b/src/cosh.c new file mode 100644 index 0000000..68e1077 --- /dev/null +++ b/src/cosh.c @@ -0,0 +1,66 @@ +/* cosh.c -- Hyperbolic cosine of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_cosh (mpfi_ptr a, mpfi_srcptr b) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact=0; + + if ( MPFI_NAN_P (b) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if ( MPFI_IS_NONNEG (b) ) { + inexact_left = mpfr_cosh (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_cosh (&(a->right), &(b->right), MPFI_RNDU); + } + else if ( MPFI_HAS_ZERO (b) ) { + if (mpfr_cmpabs (&(b->left), &(b->right)) > 0) + inexact_right = mpfr_cosh (&(a->right), &(b->left), MPFI_RNDU); + else + inexact_right = mpfr_cosh ( &(a->right), &(b->right), MPFI_RNDU); + inexact_left = mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + + } + else { /* b <= 0 */ + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_cosh (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_cosh (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/cot.c b/src/cot.c new file mode 100644 index 0000000..722c5aa --- /dev/null +++ b/src/cot.c @@ -0,0 +1,115 @@ +/* cot.c -- Cotangent of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_cot (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + mpz_t z_left, z_right, z; + + if (MPFI_NAN_P (b)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_INF_P (b)) { + /* the two endpoints are the same infinite */ + if (mpfr_cmp (&(b->left), &(b->right)) == 0) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + return 0; + } + + mpz_init (z_left); + mpz_init (z_right); + mpz_init (z); + + mpfi_quadrant (z_left, &(b->left)); + mpfi_quadrant (z_right, &(b->right)); + mpz_sub (z, z_right, z_left); + + if (mpfr_zero_p (&(b->left)) || mpfr_zero_p (&(b->right))) { + /* one end point is zero, this is the only multiple of Pi to be exact */ + if (mpfr_zero_p (&(b->left)) && mpfr_zero_p (&(b->right))) { + /* cot([+0, -0] = [NaN, NaN] */ + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if ((mpfr_zero_p (&(b->left)) && mpz_cmp_ui (z_right, 1) > 0) + || (mpfr_zero_p (&(b->right)) && mpz_cmp_si (z_left, -2) < 0)) { + /* b contains more than one period */ + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + inexact = 0; + } + else if (mpfr_zero_p (&(b->left))) { + /* cot([+0, x]) = [cot(x), +oo] */ + inexact_left = mpfr_cot (&(a->left), &(b->right), MPFI_RNDD); + inexact = inexact_left ? MPFI_FLAGS_LEFT_ENDPOINT_INEXACT : 0; + mpfr_set_inf (&(a->right), 1); + } + else { + /* cot([x, -0]) = [-oo, cot(x)] */ + inexact_right = mpfr_cot (&(a->right), &(b->left), MPFI_RNDU); + inexact = inexact_right ? MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT : 0; + mpfr_set_inf (&(a->left), -1); + } + } + else if ((mpz_cmp_ui (z, 2) >= 0) + || (mpz_odd_p (z_left) && mpz_even_p (z_right))) { + /* there is at least one period in b or if b contains a k*Pi, */ + /* then a = ]-oo, +oo[ */ + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + inexact = 0; + } + else { /* within one period, cot is decreasing */ + mpfr_t tmp; + + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_cot (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_cot (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + if (inexact_left) inexact += 1; + if (inexact_right) inexact += 2; + } + + mpz_clear (z_left); + mpz_clear (z_right); + mpz_clear (z); + + return inexact; +} diff --git a/src/coth.c b/src/coth.c new file mode 100644 index 0000000..f4874d0 --- /dev/null +++ b/src/coth.c @@ -0,0 +1,59 @@ +/* coth.c -- Hyperbolic cotangent of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_coth (mpfi_ptr a, mpfi_srcptr b) +{ + mpfr_t tmp; + int inexact_left, inexact_right; + int inexact = 0; + + if (MPFI_NAN_P (b)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_HAS_ZERO (b)) { + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + return 0; + } + + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_coth (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_coth (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/csc.c b/src/csc.c new file mode 100644 index 0000000..cbc191f --- /dev/null +++ b/src/csc.c @@ -0,0 +1,141 @@ +/* mpfi_csc.c -- Cosecant of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_csc (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact = 0; + mpfr_prec_t prec, prec_left, prec_right; + mpfr_t tmp; + mpz_t quad_left, quad_right; + mpz_t z, zmod4; + int ql_mod4, qr_mod4; + + if (MPFI_NAN_P (b)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_INF_P (b)) { + /* the two endpoints are the same infinite */ + if ( mpfr_cmp (&(b->left), &(b->right)) == 0) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + return 0; + } + + mpz_init (quad_left); + mpz_init (quad_right); + mpz_init (z); + + prec_left = mpfi_quadrant (quad_left, &(b->left)); + prec_right = mpfi_quadrant (quad_right, &(b->right)); + if (mpfr_zero_p (&(b->right))) { + /* -0 is in quadrant -1 */ + mpz_sub_ui (quad_right, quad_right, 1); + } + + /* if there is at least one period in b or if b contains a k*Pi, */ + /* then a = ]-oo, +oo[ */ + mpz_sub (z, quad_right, quad_left); + if (mpz_cmp_ui (z, 2) >= 0 + || (mpz_odd_p (quad_left) && mpz_even_p (quad_right)) + || MPFI_IS_ZERO (b)) { + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + } + else { + /* computing precision = maximal precision required to determine the + relative position of the endpoints of b and of integer multiples of + Pi / 2 */ + prec = mpfi_get_prec (a); + if (prec_left > prec) prec = prec_left; + if (prec_right > prec) prec = prec_right; + + mpz_init (zmod4); + + /* qr_mod4 gives the quadrant where the right endpoint of b is */ + /* qr_mod4 = floor (2 b->right / pi) mod 4 */ + mpz_mod_ui (zmod4, quad_right, 4); + qr_mod4 = mpz_get_ui (zmod4); + + /* ql_mod4 gives the quadrant where the left endpoint of b is */ + /* ql_mod4 = floor (2 b->left / pi) mod 4 */ + mpz_mod_ui (zmod4, quad_left, 4); + ql_mod4 = mpz_get_ui (zmod4); + + + if (qr_mod4 == ql_mod4) { + if (qr_mod4 == 1 || qr_mod4 == 2) { + /* csc is increasing on b */ + inexact_left = mpfr_csc (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_csc (&(a->right), &(b->right), MPFI_RNDU); + } + else { + /* csc is decreasing on b */ + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_csc (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_csc (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + } + } + else if (ql_mod4 == 2) { + mpz_add (z, quad_left, quad_right); + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->right), &(b->left), prec) >= 0) + inexact_left = mpfr_csc (&(a->left), &(b->left), MPFI_RNDD); + else + inexact_left = mpfr_csc (&(a->left), &(b->right), MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), -1, MPFI_RNDU); + } + else { + mpz_add (z, quad_left, quad_right); + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->right), &(b->left), prec) >= 0) + inexact_right = mpfr_csc (&(a->right), &(b->left), MPFI_RNDU); + else + inexact_right = mpfr_csc (&(a->right), &(b->right), MPFI_RNDU); + inexact_left = mpfr_set_ui (&(a->left), +1, MPFI_RNDD); + } + + if (inexact_left) inexact = 1; + if (inexact_right) inexact += 2; + + mpz_clear (zmod4); + } + + mpz_clear (quad_left); + mpz_clear (quad_right); + + return inexact; +} diff --git a/src/csch.c b/src/csch.c new file mode 100644 index 0000000..6a6dc5d --- /dev/null +++ b/src/csch.c @@ -0,0 +1,67 @@ +/* csch.c -- Hyperbolic cosecant of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_csch (mpfi_ptr a, mpfi_srcptr b) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact=0; + + if (MPFI_NAN_P (b)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_HAS_ZERO (b)) { + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + return 0; + } + + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_csch (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_csch (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/d_div.c b/src/d_div.c new file mode 100644 index 0000000..753f2b2 --- /dev/null +++ b/src/d_div.c @@ -0,0 +1,77 @@ +/* d_div.c -- Divide a double by an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_d_div (mpfi_ptr a, const double b, mpfi_srcptr c) +{ + mpfr_t tmp; + int inexact_left = 0, inexact_right = 0, inexact = 0; + + if (MPFI_NAN_P (c)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_HAS_ZERO (c)) { /* a = ]-oo, +oo [ */ + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + } + else if (b == 0.0) { + mpfi_set_ui (a, 0); + } + else if (b > 0.0) { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_d_div (tmp, b, &(c->right), MPFI_RNDD); + inexact_right = mpfr_d_div (&(a->right), b, &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); + mpfr_clear (tmp); + } + else { + inexact_left = mpfr_d_div (&(a->left), b, &(c->left), MPFI_RNDD); + inexact_right = mpfr_d_div (&(a->right), b, &(c->right), MPFI_RNDU); + } + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/d_sub.c b/src/d_sub.c new file mode 100644 index 0000000..a849215 --- /dev/null +++ b/src/d_sub.c @@ -0,0 +1,66 @@ +/* d_sub.c -- Subtract an interval from a double. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_d_sub (mpfi_ptr a, const double b, mpfi_srcptr c) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact = 0; + + if (MPFI_IS_ZERO (c)) { + return mpfi_set_d (a, b); + } + else if (b==0.0) { + return mpfi_neg (a, c); + } + else { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_d_sub (tmp, b, &(c->right), MPFI_RNDD); + inexact_right = mpfr_d_sub (&(a->right), b, &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } +} diff --git a/src/diam.c b/src/diam.c new file mode 100644 index 0000000..055eac4 --- /dev/null +++ b/src/diam.c @@ -0,0 +1,91 @@ +/* diam.c -- Various diameter functions. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2018, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Absolute diameter */ +int +mpfi_diam_abs (mpfr_ptr diam, mpfi_srcptr interv) +{ + return (mpfr_sub (diam, &(interv->right), &(interv->left), MPFI_RNDU)); +} + +/* Relative diameter */ +/* Always computes an overestimation */ +/* return value: 0 if the result is exact, > 0 otherwise */ +int +mpfi_diam_rel (mpfr_ptr diam, mpfi_srcptr interv) +{ + mpfr_t center; + int inexact_mid, inexact_sub = 0, inexact = 0; + + mpfr_init2 (center, mpfr_get_prec (diam)); + + /* if interv is bounded, compute d/|c| where d is the absolute diameter of + interv and c is its midpoint + if interv is not bounded, d and c are infinite, their quotient does not + exist */ + inexact_sub = mpfr_sub (diam, &(interv->right), &(interv->left), MPFI_RNDU); + + inexact_mid = mpfi_mid (center, interv); + if (mpfr_sgn (center) * inexact_mid > 0 && !mpfr_inf_p (center)) { + /* the absolute value of center have to be underestimated for an + overestimated quotient, except for the infinite cases where the + division below should return NaN. + Note that in case of underflow, mpfr_sgn(center)==0 and the + if-condition fails, preventing the next operation to actually increase + the absolute value of center */ + if (mpfr_sgn (center) > 0) + mpfr_nextbelow (center); + else + mpfr_nextabove (center); + } + mpfr_abs (center, center, MPFI_RNDD); /* always exact */ + + inexact = mpfr_div (diam, diam, center, MPFI_RNDU); + mpfr_clear (center); + + if (mpfr_nan_p (diam)) + MPFR_RET_NAN; + + if (inexact || inexact_sub || inexact_mid) + return 1; + else + return 0; +} + +/* Diameter: relative if the interval does not contain 0 */ +/* absolute otherwise */ +int +mpfi_diam (mpfr_ptr diam, mpfi_srcptr interv) +{ + + if (!mpfi_has_zero (interv)) { + return (mpfi_diam_rel (diam, interv)); + } + else { + return (mpfi_diam_abs (diam, interv)); + } +} diff --git a/src/div.c b/src/div.c new file mode 100644 index 0000000..971e29d --- /dev/null +++ b/src/div.c @@ -0,0 +1,122 @@ +/* div.c -- Divide two intervals. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_div (mpfi_ptr a, mpfi_srcptr b, mpfi_srcptr c) +{ + mpfr_t tmp; + int inexact_left = 0, inexact_right = 0, inexact = 0; + + if ( MPFI_NAN_P (b) || MPFI_NAN_P (c) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_HAS_ZERO_NONSTRICT (c)) { + if ( MPFI_HAS_ZERO (c) || MPFI_HAS_ZERO (b) ) { /* a = ]-oo, +oo [ */ + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + } + else if (MPFI_IS_NONNEG (c)) { /* c >= 0 and its left endpoint is 0 */ + if (MPFI_IS_NONNEG (b)) { /* a = [ bl/cr, +oo [ */ + inexact_left = mpfr_div (&(a->left), &(b->left), &(c->right), MPFI_RNDD); + mpfr_set_inf (&(a->right), 1); + } + else { /* b <= 0 */ /* a = ] -oo, br/cr ] */ + inexact_right = mpfr_div (&(a->right), &(b->right), &(c->right), MPFI_RNDU); + mpfr_set_inf (&(a->left), -1); + } + } + else { /* c <= 0 and its right endpoint is 0 */ + if (MPFI_IS_NONNEG (b)) { /* a = ] -oo, bl/cl ] */ + inexact_right = mpfr_div (&(a->right), &(b->left), &(c->left), MPFI_RNDU); + mpfr_set_inf (&(a->left), -1); + } + else { /* b <= 0 */ /* a = [ br/cl, +oo [ */ + inexact_left = mpfr_div (&(a->left), &(b->right), &(c->left), MPFI_RNDD); + mpfr_set_inf (&(a->right), 1); + } + } + } + else if (MPFI_IS_POS (c)) { + if (MPFI_IS_NONNEG (b)) { /* a = [ bl/cr, br/cl ] */ + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_div (tmp, &(b->left), &(c->right), MPFI_RNDD); + inexact_right = mpfr_div (&(a->right), &(b->right), &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + } + else if (MPFI_IS_NONPOS (b)) { /* a = [ bl/cl, br/cr ] */ + inexact_left = mpfr_div (&(a->left), &(b->left), &(c->left), MPFI_RNDD); + inexact_right = mpfr_div (&(a->right), &(b->right), &(c->right), MPFI_RNDU); + } + else { /* b contains 0 in its interior */ /* a = [ bl/cl, br/cl ] */ + mpfr_init2 (tmp, mpfr_get_prec (&(a->right))); + inexact_right = mpfr_div (tmp, &(b->right), &(c->left), MPFI_RNDU); + inexact_left = mpfr_div (&(a->left), &(b->left), &(c->left), MPFI_RNDD); + mpfr_set (&(a->right), tmp, MPFI_RNDU); /* exact */ + mpfr_clear (tmp); + } + } + else { /* c < 0 */ + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + if (MPFI_IS_NONNEG (b)) { /* a = [ br/cr, bl/cl ] */ + inexact_left = mpfr_div (tmp, &(b->right), &(c->right), MPFI_RNDD); + inexact_right = mpfr_div (&(a->right), &(b->left), &(c->left), MPFI_RNDU); + } + else if (MPFI_IS_NONPOS (b)) { /* a = [ br/cl, bl/cr ] */ + inexact_left = mpfr_div (tmp, &(b->right), &(c->left), MPFI_RNDD); + inexact_right = mpfr_div (&(a->right), &(b->left), &(c->right), MPFI_RNDU); + } + else { /* b contains 0 in its interior */ /* a = [ br/cr, bl/cr ] */ + inexact_left = mpfr_div (tmp, &(b->right), &(c->right), MPFI_RNDD); + inexact_right = mpfr_div (&(a->right), &(b->left), &(c->right), MPFI_RNDU); + } + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + return inexact; +} diff --git a/src/div_2exp.c b/src/div_2exp.c new file mode 100644 index 0000000..2f73144 --- /dev/null +++ b/src/div_2exp.c @@ -0,0 +1,45 @@ +/* div_2exp.c -- Scale endpoints. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_div_2exp (mpfi_ptr a, mpfi_srcptr b, unsigned long c) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_div_2exp (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_div_2exp (&(a->right), &(b->right), c, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/div_2si.c b/src/div_2si.c new file mode 100644 index 0000000..39a18fe --- /dev/null +++ b/src/div_2si.c @@ -0,0 +1,45 @@ +/* div_2si.c -- Scale endpoints. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_div_2si (mpfi_ptr a, mpfi_srcptr b, long c) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_div_2si (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_div_2si (&(a->right), &(b->right), c, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/div_2ui.c b/src/div_2ui.c new file mode 100644 index 0000000..7d25888 --- /dev/null +++ b/src/div_2ui.c @@ -0,0 +1,45 @@ +/* div_2ui.c -- Scale endpoints. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_div_2ui (mpfi_ptr a, mpfi_srcptr b, unsigned long c) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_div_2ui (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_div_2ui (&(a->right), &(b->right), c, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/div_d.c b/src/div_d.c new file mode 100644 index 0000000..33e6eca --- /dev/null +++ b/src/div_d.c @@ -0,0 +1,80 @@ +/* div_d.c -- Divide an interval by a double. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_div_d (mpfi_ptr a, mpfi_srcptr b, const double c) +{ + mpfr_t tmp; + int inexact_left, inexact_right; + int inexact = 0; + + if (MPFI_NAN_P (b)) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (c == 0.0) + { + if (mpfr_zero_p (&(b->left))) + mpfr_set_nan (&(a->left)); + else + mpfr_set_inf (&(a->left), -1); + inexact_left = 0; + + if (mpfr_zero_p (&(b->right))) + mpfr_set_nan (&(a->right)); + else + mpfr_set_inf (&(a->right), +1); + inexact_right = 0; + } + else if (c < 0.0) + { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_div_d (tmp, &(b->right), c, MPFI_RNDD); + inexact_right = mpfr_div_d (&(a->right), &(b->left), c, MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + } + else /* c > 0.0 */ + { + inexact_left = mpfr_div_d (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_div_d (&(a->right), &(b->right), c, MPFI_RNDU); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + /* no need to check to sign of the bounds in case they are 0 */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/div_fr.c b/src/div_fr.c new file mode 100644 index 0000000..8bcfca3 --- /dev/null +++ b/src/div_fr.c @@ -0,0 +1,43 @@ +/* div_fr.c -- Divide an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_div_fr (mpfi_ptr a, mpfi_srcptr b, mpfr_srcptr c) +{ + mpfi_t tmp; + int inexact; + + mpfi_init2 (tmp, mpfr_get_prec (c)); + mpfi_set_fr (tmp, c); /* exact */ + inexact = mpfi_div (a, b, tmp); + MPFI_CLEAR (tmp); + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + return inexact; +} diff --git a/src/div_q.c b/src/div_q.c new file mode 100644 index 0000000..5bed20f --- /dev/null +++ b/src/div_q.c @@ -0,0 +1,104 @@ +/* div_q.c -- Divide an interval by a rational number. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_div_q (mpfi_ptr a, mpfi_srcptr b, mpq_srcptr c) +{ + mpfr_t tmp; + int inexact_left, inexact_right; + int inexact = 0; + + if (MPFI_NAN_P (b)) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (!mpq_sgn (c)) /* c = 0 */ + { + if (mpfr_zero_p (&(b->left))) + mpfr_set_nan (&(a->left)); + else + mpfr_set_inf (&(a->left), -1); + inexact_left = 0; + + if (mpfr_zero_p (&(b->right))) + mpfr_set_nan (&(a->right)); + else + mpfr_set_inf (&(a->right), +1); + inexact_right = 0; + } + else if (mpq_sgn (c) < 0) /* c < 0 */ + { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_div_q (tmp, &(b->right), c, MPFI_RNDD); + if (mpfr_inf_p (tmp) && !mpfr_inf_p (&(b->right))) + { + /* work around MPFR bug in mpfr_div_q (present in MPFR-3.0.0) */ + inexact_left = 1; /* overflow */ + } + inexact_right = mpfr_div_q (&(a->right), &(b->left), c, MPFI_RNDU); + if (mpfr_inf_p (&(a->right)) && !mpfr_inf_p (&(b->left))) + { + /* work around MPFR bug in mpfr_div_q */ + inexact_right = 1; /* overflow */ + } + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + } + else /* c > 0 */ + { + int mpfr_bug_work_around; + mpfr_bug_work_around = !mpfr_inf_p (&(b->left)); + inexact_left = mpfr_div_q (&(a->left), &(b->left), c, MPFI_RNDD); + if (mpfr_bug_work_around && mpfr_inf_p (&(a->left))) + { + /* work around MPFR bug in mpfr_div_q */ + inexact_left = 1; /* overflow */ + } + + mpfr_bug_work_around = !mpfr_inf_p (&(b->right)); + inexact_right = mpfr_div_q (&(a->right), &(b->right), c, MPFI_RNDU); + if (mpfr_bug_work_around && mpfr_inf_p (&(a->right))) + { + /* work around MPFR bug in mpfr_div_q */ + inexact_right = 1; /* overflow */ + } + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + /* no need to check to sign of the bounds in case they are 0 */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/div_si.c b/src/div_si.c new file mode 100644 index 0000000..66598dc --- /dev/null +++ b/src/div_si.c @@ -0,0 +1,79 @@ +/* div_si.c -- Divide an interval by a signed long int. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_div_si (mpfi_ptr a, mpfi_srcptr b, const long c) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact=0; + + if (MPFI_NAN_P (b)) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (c == 0) + { + if (mpfr_zero_p (&(b->left))) + mpfr_set_nan (&(a->left)); + else + mpfr_set_inf (&(a->left), -1); + inexact_left = 0; + + if (mpfr_zero_p (&(b->right))) + mpfr_set_nan (&(a->right)); + else + mpfr_set_inf (&(a->right), +1); + inexact_right = 0; + } + else if (c < 0) + { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_div_si (tmp, &(b->right), c, MPFI_RNDD); + inexact_right = mpfr_div_si (&(a->right), &(b->left), c, MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + } + else /* c > 0 */ + { + inexact_left = mpfr_div_si (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_div_si (&(a->right), &(b->right), c, MPFI_RNDU); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + /* no need to check to sign of the bounds in case they are 0 */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/div_ui.c b/src/div_ui.c new file mode 100644 index 0000000..09f57c8 --- /dev/null +++ b/src/div_ui.c @@ -0,0 +1,70 @@ +/* div_ui.c -- Divide an interval by an unsigned long int. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2011, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_div_ui (mpfi_ptr a, mpfi_srcptr b, const unsigned long c) +{ + int inexact_left, inexact_right, inexact=0; + + if (MPFI_NAN_P (b)) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (c == 0) + { + if (mpfr_zero_p (&(b->left))) + mpfr_set_nan (&(a->left)); + else + mpfr_set_inf (&(a->left), -1); + inexact_left = 0; + + if (mpfr_zero_p (&(b->right))) + mpfr_set_nan (&(a->right)); + else + mpfr_set_inf (&(a->right), +1); + inexact_right = 0; + } + else + { + inexact_left = mpfr_div_ui (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_div_ui (&(a->right), &(b->right), c, MPFI_RNDU); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + /* no need to check to sign of the bounds in case they are 0 */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/div_z.c b/src/div_z.c new file mode 100644 index 0000000..1ace637 --- /dev/null +++ b/src/div_z.c @@ -0,0 +1,80 @@ +/* div_z.c -- Divide an interval by an integer. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_div_z (mpfi_ptr a, mpfi_srcptr b, mpz_srcptr c) +{ + mpfr_t tmp; + int inexact_left, inexact_right; + int inexact = 0; + + if (MPFI_NAN_P (b)) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (!mpz_sgn (c)) /* c = 0 */ + { + if (mpfr_zero_p (&(b->left))) + mpfr_set_nan (&(a->left)); + else + mpfr_set_inf (&(a->left), -1); + inexact_left = 0; + + if (mpfr_zero_p (&(b->right))) + mpfr_set_nan (&(a->right)); + else + mpfr_set_inf (&(a->right), +1); + inexact_right = 0; + } + else if (mpz_sgn (c) < 0) /* c < 0 */ + { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_div_z (tmp, &(b->right), c, MPFI_RNDD); + inexact_right = mpfr_div_z (&(a->right), &(b->left), c, MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + } + else /* c > 0 */ + { + inexact_left = mpfr_div_z (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_div_z (&(a->right), &(b->right), c, MPFI_RNDU); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + /* no need to check to sign of the bounds in case they are 0 */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/erandom.c b/src/erandom.c new file mode 100644 index 0000000..40c2448 --- /dev/null +++ b/src/erandom.c @@ -0,0 +1,98 @@ +/* erandom.c -- Random element in the interval, following an exponential distribution. + without any guarantee: to be checked + +Copyright 2018 + AriC project, Inria Rhone-Alpes, France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Picks randomly a point m in y */ +void +mpfi_erandom (mpfr_ptr m, mpfi_srcptr y, gmp_randstate_t state) +{ + mpfr_prec_t prec, tmp_prec; + mpfr_t diam, fact; + + + if (MPFI_NAN_P(y)) { + mpfr_set_nan (m); + return; + } + + if (mpfr_equal_p (&(y->left), &(y->right))) { + mpfr_set (m, &(y->left), MPFR_RNDN); + return; + } + + prec = mpfr_get_prec (m); + tmp_prec = mpfi_get_prec(y); + if (tmp_prec > prec) + { + prec = tmp_prec; + } + mpfr_init2 (diam, prec); + mpfr_init2 (fact, prec); + + mpfi_diam_abs (diam, y); + mpfr_erandom (fact, state, MPFR_RNDN); + mpfr_sub_d (fact, fact, 0.5, MPFR_RNDN); + if (mpfr_cmp_ui (fact, 0) < 0) + mpfr_set_ui(fact, 0, MPFR_RNDN); + else if (mpfr_cmp_ui(fact, 1) > 0) + mpfr_set_ui(fact, 1, MPFR_RNDN); /* now fact lies between 0 and 1 */ + + if (mpfr_cmp_ui (diam, 1) <= 0) { + /* the picked point lies at a relative distance "fact" of the left + endpoint: m = inf + (sup - inf) * fact */ + mpfr_mul (fact, fact, diam, MPFR_RNDN); + /* FIXME: because of possible cancelation, the random distribution is + not uniform among the floating-point numbers in y */ + mpfr_add (m, &(y->left), fact, MPFR_RNDN); + } + else { + mpfr_exp_t e; + if (mpfr_cmp_abs (&(y->left), &(y->right)) < 0) { + e = mpfr_inf_p (&(y->right)) ? mpfr_get_emax () + : mpfr_get_exp (&(y->right)); + } + else { + e = mpfr_inf_p (&(y->left)) ? mpfr_get_emax () + : mpfr_get_exp (&(y->left)); + } + e += 1; + /* resize fact in [0, 2^e] where e = 1 + max{exp(left), exp(right)} */ + mpfr_mul_2exp (fact, fact, e, MPFR_RNDN); + mpfr_set (m, &(y->left), MPFR_RNDN); + if (mpfr_inf_p (m)) { + mpfr_nextabove (m); + } + /* m may be outside y */ + mpfr_add (m, m, fact, MPFR_RNDN); + } + mpfr_clear (fact); + mpfr_clear (diam); + + /* Ensure that m belongs to y (if the precision is sufficient) */ + if (mpfr_cmp (m, &(y->left)) < 0) + mpfr_set (m, &(y->left), MPFR_RNDU); + + if (mpfr_cmp (&(y->right), m) < 0) + mpfr_set (m, &(y->right), MPFR_RNDD); +} diff --git a/src/error.c b/src/error.c new file mode 100644 index 0000000..a5fc686 --- /dev/null +++ b/src/error.c @@ -0,0 +1,46 @@ +/* error.c -- Helper functions handling errors. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int mpfi_error = 0; + +void +mpfi_set_error (const int i) +{ + mpfi_error = i; +} + +void +mpfi_reset_error () +{ + mpfi_error = 0; +} + +int +mpfi_is_error () +{ + return (mpfi_error==1); +} diff --git a/src/exp.c b/src/exp.c new file mode 100644 index 0000000..f005acf --- /dev/null +++ b/src/exp.c @@ -0,0 +1,51 @@ +/* exp.c -- Exponential of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Computes the exp of an interval */ +int +mpfi_exp (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_exp (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_exp (&(a->right), &(b->right), MPFI_RNDU); + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/exp2.c b/src/exp2.c new file mode 100644 index 0000000..c23ed4b --- /dev/null +++ b/src/exp2.c @@ -0,0 +1,50 @@ +/* exp2.c -- Power of two of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_exp2 (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_exp2 (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_exp2 (&(a->right), &(b->right), MPFI_RNDU); + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/expm1.c b/src/expm1.c new file mode 100644 index 0000000..d317b8b --- /dev/null +++ b/src/expm1.c @@ -0,0 +1,45 @@ +/* expm1.c -- Computes the exp of an interval, minus 1. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_expm1 (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_expm1 (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_expm1 (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/fr_div.c b/src/fr_div.c new file mode 100644 index 0000000..496b15d --- /dev/null +++ b/src/fr_div.c @@ -0,0 +1,77 @@ +/* fr_div.c -- Divide a floating-point number by an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_fr_div (mpfi_ptr a, mpfr_srcptr b, mpfi_srcptr c) +{ + mpfr_t tmp; + int inexact_left = 0, inexact_right = 0, inexact = 0; + + if (MPFI_NAN_P (c) || mpfr_nan_p (b)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_HAS_ZERO (c)) { /* a = ]-oo, +oo [ */ + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + } + else if (mpfr_sgn (b) == 0) { /* b = 0, a= [+0, -0] */ + mpfi_set_ui (a, 0); + } + else if (mpfr_sgn(b) > 0) { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_div (tmp, b, &(c->right), MPFI_RNDD); + inexact_right = mpfr_div (&(a->right), b, &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); + mpfr_clear (tmp); + } + else { + inexact_left = mpfr_div (&(a->left), b, &(c->left), MPFI_RNDD); + inexact_right = mpfr_div (&(a->right), b, &(c->right), MPFI_RNDU); + } + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/fr_sub.c b/src/fr_sub.c new file mode 100644 index 0000000..02e204b --- /dev/null +++ b/src/fr_sub.c @@ -0,0 +1,66 @@ +/* fr_sub.c -- Subtract an interval from a floating-point number. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_fr_sub (mpfi_ptr a, mpfr_srcptr b, mpfi_srcptr c) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact = 0; + + if (MPFI_IS_ZERO (c)) { + return mpfi_set_fr (a, b); + } + else if (MPFR_IS_ZERO(b)) { + return mpfi_neg (a, c); + } + else { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_sub (tmp, b, &(c->right), MPFI_RNDD); + inexact_right = mpfr_sub (&(a->right), b, &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } +} diff --git a/src/get_d.c b/src/get_d.c new file mode 100644 index 0000000..36537b1 --- /dev/null +++ b/src/get_d.c @@ -0,0 +1,40 @@ +/* get_d.c -- Return the center of an interval as a double. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2011, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +double +mpfi_get_d (mpfi_srcptr a) +{ + double res; + mpfr_t tmp; + + mpfr_init2 (tmp, 53); /* Double rounding may occur for subnormal numbers */ + mpfi_mid (tmp, a); + res = mpfr_get_d (tmp, MPFR_RNDN); + mpfr_clear (tmp); + + return res; +} diff --git a/src/get_endpoints.c b/src/get_endpoints.c new file mode 100644 index 0000000..03b0137 --- /dev/null +++ b/src/get_endpoints.c @@ -0,0 +1,38 @@ +/* get_endpoints.c -- Operations related to the internal representation endpoints. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_get_left (mpfr_ptr b, mpfi_srcptr a) +{ + return mpfr_set (b, &(a->left), MPFI_RNDD); +} + +int +mpfi_get_right (mpfr_ptr b, mpfi_srcptr a) +{ + return mpfr_set (b, &(a->right), MPFI_RNDU); +} diff --git a/src/get_fr.c b/src/get_fr.c new file mode 100644 index 0000000..03d6dd6 --- /dev/null +++ b/src/get_fr.c @@ -0,0 +1,32 @@ +/* get_fr.c -- Return the center of an interval as a floating point. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2011, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +void +mpfi_get_fr (mpfr_ptr m, mpfi_srcptr a) +{ + mpfi_mid (m, a); +} diff --git a/src/get_prec.c b/src/get_prec.c new file mode 100644 index 0000000..6e2bffb --- /dev/null +++ b/src/get_prec.c @@ -0,0 +1,39 @@ +/* get_prec.c -- return the precision of the interval's endpoints. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Returns the largest precision of the endpoints of x */ +/* Reminder: the endpoints' precisions are supposed to be the same */ +mpfr_prec_t +mpfi_get_prec (mpfi_srcptr x) +{ + mpfr_prec_t prec_left, prec_right; + + prec_left = mpfr_get_prec (&(x->left)); + prec_right = mpfr_get_prec (&(x->right)); + + return (prec_left>prec_right ? prec_left : prec_right); +} diff --git a/src/get_version.c b/src/get_version.c new file mode 100644 index 0000000..da12ccf --- /dev/null +++ b/src/get_version.c @@ -0,0 +1,32 @@ +/* get_version.c -- Return current MPFI version. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +const char * +mpfi_get_version (void) +{ + return (VERSION); +} diff --git a/src/has_zero.c b/src/has_zero.c new file mode 100644 index 0000000..226e122 --- /dev/null +++ b/src/has_zero.c @@ -0,0 +1,34 @@ +/* has_zero.c -- true if 0 is in the interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_has_zero (mpfi_srcptr a) +{ + return (mpfr_cmp_ui (&(a->left), 0) <= 0 + && mpfr_cmp_ui (&(a->right), 0) >= 0 + && !MPFI_NAN_P (a)); +} diff --git a/src/hypot.c b/src/hypot.c new file mode 100644 index 0000000..2bcdd41 --- /dev/null +++ b/src/hypot.c @@ -0,0 +1,89 @@ +/* hypot.c -- Euclidean distance. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_hypot (mpfi_ptr a, mpfi_srcptr b, mpfi_srcptr c) +{ + int inexact_left, inexact_right, inexact=0; + mpfi_t tmp; + int bmax_left_p, cmax_left_p; + + if (MPFI_NAN_P (b) || MPFI_NAN_P (c)) { + /* hypot (y, +-inf) = hypot (+-inf, y) = +inf even if y is NaN */ + if (MPFI_NAN_P (b) + && mpfr_inf_p (&(c->left)) && mpfr_inf_p (&(c->right)) + && mpfr_equal_p (&(c->left), &(c->right))) { + mpfi_abs (a, c); + return inexact; + } + else if (MPFI_NAN_P (c) + && mpfr_inf_p (&(b->left)) && mpfr_inf_p (&(b->right)) + && mpfr_equal_p (&(b->left), &(b->right))) { + mpfi_abs (a, b); + return inexact; + } + + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + mpfi_init2 (tmp, mpfi_get_prec (a)); + + bmax_left_p = mpfr_cmp_abs (&(b->left), &(b->right)) > 0; + cmax_left_p = mpfr_cmp_abs (&(c->left), &(c->right)) > 0; + + if (MPFI_HAS_ZERO_NONSTRICT (b)) { + if (MPFI_HAS_ZERO_NONSTRICT (c)) + inexact_left = mpfr_set_ui (&(tmp->left), 0, MPFI_RNDU); + else + inexact_left = mpfr_abs (&(tmp->left), cmax_left_p ? &(c->right) : &(c->left), MPFI_RNDD); + } + else { + if (MPFI_HAS_ZERO_NONSTRICT (c)) + inexact_left = mpfr_abs (&(tmp->left), bmax_left_p ? &(b->right) : &(b->left), MPFI_RNDD); + else + inexact_left = mpfr_hypot (&(tmp->left), bmax_left_p ? &(b->right) : &(b->left), cmax_left_p ? &(c->right) : &(c->left), MPFI_RNDD); + } + + inexact_right = mpfr_hypot (&(tmp->right), bmax_left_p ? &(b->left) : &(b->right), cmax_left_p ? &(c->left) : &(c->right), MPFI_RNDU); + + if (mpfr_sgn (&(tmp->right)) == 0) { + /* -0 as right endpoint */ + mpfr_setsign (&(tmp->right), &(tmp->right), 1, MPFI_RNDD); + } + + mpfi_set (a, tmp); + mpfi_clear (tmp); + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/increase.c b/src/increase.c new file mode 100644 index 0000000..b768a43 --- /dev/null +++ b/src/increase.c @@ -0,0 +1,58 @@ +/* increase.c -- Interval dilatation. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_increase (mpfi_ptr a, mpfr_srcptr e) +{ + int inexact_left, inexact_right, inexact=0; + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + else if ( mpfr_nan_p (e) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + inexact_right = mpfr_add (&(a->right), &(a->right), e, MPFI_RNDU); + inexact_left = mpfr_sub (&(a->left), &(a->left), e, MPFI_RNDD); + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + return inexact; +} diff --git a/src/init.c b/src/init.c new file mode 100644 index 0000000..0699149 --- /dev/null +++ b/src/init.c @@ -0,0 +1,35 @@ +/* init.c -- Initialize an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2018 + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and AriC project, Inria Grenoble - Rhone-Alpes, France + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +void +mpfi_init (mpfi_t x) +{ + mpfr_init (&(x->left)); + mpfr_init (&(x->right)); +} + diff --git a/src/init2.c b/src/init2.c new file mode 100644 index 0000000..2c14b70 --- /dev/null +++ b/src/init2.c @@ -0,0 +1,34 @@ +/* init2.c -- Initialize an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2018 + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and AriC project, Inria Grenoble - Rhone-Alpes, France + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +void +mpfi_init2 (mpfi_t x, mpfr_prec_t p) +{ + mpfr_init2 (&(x->left),p); + mpfr_init2 (&(x->right),p); +} diff --git a/src/inits.c b/src/inits.c new file mode 100644 index 0000000..bf7c0db --- /dev/null +++ b/src/inits.c @@ -0,0 +1,74 @@ +/* mpfi_inits -- initialize several intervals + +Copyright 2018 Free Software Foundation, Inc. +Contributed by the AriC project, INRIA. + +This file is part of the GNU MPFI Library. + +The GNU MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MPFI Library; see the file COPYING.LESSER. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* +#ifdef HAVE_CONFIG_H +# undef HAVE_STDARG +# include "config.h" +#endif +*/ + +/* +#if HAVE_STDARG +# include +#else +# include +#endif +*/ + +# include +#include "mpfi-impl.h" + +/* Since it uses "...", we need an explicit support for K&R */ + +/* +void +#if HAVE_STDARG +mpfi_inits (mpfi_ptr x, ...) +#else +mpfi_inits (va_alist) + va_dcl +#endif +{ + va_list arg; + +#if HAVE_STDARG + va_start (arg, x); +#else + mpfi_ptr x; + va_start(arg); + x = va_arg (arg, mpfi_ptr); +#endif +*/ + +void mpfi_inits(mpfi_ptr x, ...) +{ + va_list arg; + + va_start (arg, x); + while (x != 0) + { + mpfi_init (x); + x = (mpfi_ptr) va_arg (arg, mpfi_ptr); + } + va_end (arg); +} diff --git a/src/inits2.c b/src/inits2.c new file mode 100644 index 0000000..ba5a4b2 --- /dev/null +++ b/src/inits2.c @@ -0,0 +1,77 @@ +/* mpfi_inits2 -- initialize several intervals with floating-point endpoints of given + precision + +Copyright 2018 Free Software Foundation, Inc. +Contributed by the AriC project, INRIA. + +This file is part of the GNU MPFI Library. + +The GNU MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MPFI Library; see the file COPYING.LESSER. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* +#ifdef HAVE_CONFIG_H +# undef HAVE_STDARG +# include "config.h" +#endif + +#if HAVE_STDARG +# include +#else +# include +#endif +*/ + +#include +#include "mpfi-impl.h" + +/* + * Contrary to mpfi_init2, mpfr_prec_t p is the first argument + */ + +/* Explicit support for K&R compiler */ +/* +void +#if HAVE_STDARG +mpfi_inits2 (mpfr_prec_t p, mpfi_ptr x, ...) +#else +mpfi_inits2 (va_alist) + va_dcl +#endif +{ + va_list arg; +#if HAVE_STDARG + va_start (arg, x); +#else + mpfr_prec_t p; + mpfi_ptr x; + va_start(arg); + p = va_arg (arg, mpfr_prec_t); + x = va_arg (arg, mpfi_ptr); +#endif +*/ + +void mpfi_inits2 (mpfr_prec_t p, mpfi_ptr x, ...) +{ + va_list arg; + va_start (arg, x); + + while (x != 0) + { + mpfi_init2 (x, p); + x = (mpfi_ptr) va_arg (arg, mpfi_ptr); + } + va_end (arg); +} diff --git a/src/inp_str.c b/src/inp_str.c new file mode 100644 index 0000000..cc951d1 --- /dev/null +++ b/src/inp_str.c @@ -0,0 +1,86 @@ +/* inp_str.c -- Set an interval from an input stream. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi_io.h" +#include "mpfi-impl.h" + +size_t +mpfi_inp_str (mpfi_ptr x, FILE *s, int base) +{ + size_t blank = 0; + size_t t; + size_t pos; + size_t size = 256; + char *str; + int c; + + void * (*mpfi_allocate_func) (size_t); + void * (*mpfi_reallocate_func) (void *,size_t, size_t); + void (*mpfi_free_func) (void *, size_t); + + mp_get_memory_functions (&mpfi_allocate_func, &mpfi_reallocate_func, + &mpfi_free_func); + + c = fgetc (s); + while (MPFI_ISSPACE (c)) { + c = fgetc (s); + ++blank; + } + + if (c != '[') { + /* one single number defining an interval */ + ungetc (c, s); + t = mpfr_inp_str (&(x->left), s, base, MPFI_RNDD); + mpfr_set (&(x->right), &(x->left), MPFI_RNDD); + mpfr_nextabove (&(x->right)); + + return t != 0 ? blank + t : 0; + } + else { + /* interval given by two endpoints between square brackets */ + /* the interval is copied into a string and handled by mpfi_set_str */ + str = (char *)(*mpfi_allocate_func)(size); + + pos = 0; + str[pos++] = '['; + + while (c != ']') { + c = fgetc (s); + if (c == EOF) + break; + str[pos++] = c; + if (pos == size) { + str = (char *)(*mpfi_reallocate_func)(str, size, 2 * size); + size *= 2; + } + } + str[pos]='\0'; + + t = mpfi_set_str (x, str, base); + (*mpfi_free_func)(str, size); + + return t == 0 ? blank + pos : 0; + } +} diff --git a/src/intersect.c b/src/intersect.c new file mode 100644 index 0000000..7508b55 --- /dev/null +++ b/src/intersect.c @@ -0,0 +1,58 @@ +/* intersect.c -- Intervals intersection. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_intersect (mpfi_ptr a, mpfi_srcptr b, mpfi_srcptr c) +{ +/* If intersection = empty set, a will have its left bound > right one */ + int inexact_left, inexact_right, inexact=0; + + if ( MPFI_NAN_P (b) || MPFI_NAN_P (c) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (mpfr_cmp (&(b->left), &(c->left)) <= 0) + inexact_left = mpfr_set (&(a->left), &(c->left), MPFI_RNDD); + else + inexact_left = mpfr_set (&(a->left), &(b->left), MPFI_RNDD); + + if (mpfr_cmp (&(c->right), &(b->right)) <= 0) + inexact_right = mpfr_set (&(a->right), &(c->right), MPFI_RNDU); + else + inexact_right = mpfr_set (&(a->right), &(b->right), MPFI_RNDU); + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + if (mpfr_cmp (&(a->left), &(a->right)) > 0) /* a is the empty set */ + inexact = MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT; + + return inexact; +} diff --git a/src/interv_d.c b/src/interv_d.c new file mode 100644 index 0000000..a0c8a87 --- /dev/null +++ b/src/interv_d.c @@ -0,0 +1,60 @@ +/* interv_d.c -- Build an interval from two doubles. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_interv_d (mpfi_ptr a, const double b, const double c) +{ + int inexact_left, inexact_right, inexact=0; + + if (b <= c) { + inexact_left = mpfr_set_d (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set_d (&(a->right), c, MPFI_RNDU); + } + else { + inexact_left = mpfr_set_d (&(a->left), c, MPFI_RNDD); + inexact_right = mpfr_set_d (&(a->right), b, MPFI_RNDU); + } + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + return inexact; +} diff --git a/src/interv_fr.c b/src/interv_fr.c new file mode 100644 index 0000000..d661c0d --- /dev/null +++ b/src/interv_fr.c @@ -0,0 +1,63 @@ +/* interv_fr.c -- Build an interval from two floating-point numbers. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_interv_fr (mpfi_ptr a, mpfr_srcptr b, mpfr_srcptr c) +{ + int inexact_left, inexact_right, inexact=0; + + if ( mpfr_nan_p (b) || mpfr_nan_p (c) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if ( mpfr_cmp (b, c) <= 0 ) { + inexact_left = mpfr_set (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set (&(a->right), c, MPFI_RNDU); + } + else { + inexact_left = mpfr_set (&(a->left), c, MPFI_RNDD); + inexact_right = mpfr_set (&(a->right), b, MPFI_RNDU); + } + /* a cannot be a NaN, it has been tested before */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + return inexact; +} diff --git a/src/interv_q.c b/src/interv_q.c new file mode 100644 index 0000000..77dc517 --- /dev/null +++ b/src/interv_q.c @@ -0,0 +1,48 @@ +/* interv_q.c -- Build an interval from two rational numbers. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_interv_q (mpfi_ptr a, mpq_srcptr b, mpq_srcptr c) +{ + int inexact_left, inexact_right, inexact=0; + + if ( mpq_cmp (b, c) <= 0) { + inexact_left = mpfr_set_q (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set_q (&(a->right), c, MPFI_RNDU); + } + else { + inexact_left = mpfr_set_q (&(a->left), c, MPFI_RNDD); + inexact_right = mpfr_set_q (&(a->right), b, MPFI_RNDU); + } + /* a cannot be a NaN, mpfr_set_q never returns a NaN */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/interv_si.c b/src/interv_si.c new file mode 100644 index 0000000..c94d454 --- /dev/null +++ b/src/interv_si.c @@ -0,0 +1,55 @@ +/* interv_si.c -- Build an interval from two signed long integers. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_interv_si (mpfi_ptr a, const long b, const long c) +{ + int inexact_left, inexact_right, inexact=0; + + if (b <= c) { + inexact_left = mpfr_set_si (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), c, MPFI_RNDU); + } + else { + inexact_left = mpfr_set_si (&(a->left), c, MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), b, MPFI_RNDU); + } + + /* note: a cannot be a NaN, mpfr_set_si never sets a NaN */ + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/interv_ui.c b/src/interv_ui.c new file mode 100644 index 0000000..f9fa3fb --- /dev/null +++ b/src/interv_ui.c @@ -0,0 +1,55 @@ +/* interv_ui.c -- Build an interval from two unsigned integers. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_interv_ui (mpfi_ptr a, const unsigned long b, const unsigned long c) +{ + int inexact_left, inexact_right, inexact=0; + + if (b <= c) { + inexact_left = mpfr_set_ui (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set_ui (&(a->right), c, MPFI_RNDU); + } + else { + inexact_left = mpfr_set_ui (&(a->left), c, MPFI_RNDD); + inexact_right = mpfr_set_ui (&(a->right), b, MPFI_RNDU); + } + + /* note: a cannot be a NaN, mpfr_set_ui never sets a NaN */ + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/interv_z.c b/src/interv_z.c new file mode 100644 index 0000000..4112699 --- /dev/null +++ b/src/interv_z.c @@ -0,0 +1,48 @@ +/* interv_z.c -- Build an interval from two integers. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_interv_z (mpfi_ptr a, mpz_srcptr b, mpz_srcptr c) +{ + int inexact_left, inexact_right, inexact=0; + + if ( mpz_cmp (b, c) <= 0 ) { + inexact_left = mpfr_set_z (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set_z (&(a->right), c, MPFI_RNDU); + } + else { + inexact_left = mpfr_set_z (&(a->left), c, MPFI_RNDD); + inexact_right = mpfr_set_z (&(a->right), b, MPFI_RNDU); + } + /* a cannot be a NaN, mpfr_set_z never returns a NaN */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/inv.c b/src/inv.c new file mode 100644 index 0000000..6801ce2 --- /dev/null +++ b/src/inv.c @@ -0,0 +1,70 @@ +/* inv.c -- Inverse of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_inv (mpfi_ptr a, mpfi_srcptr b) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact = 0; + + if ( MPFI_NAN_P (b) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + else if ( (mpfr_sgn (&(b->left)) < 0) && (mpfr_sgn (&(b->right)) > 0) ) { + /* b has endpoints of opposite signs */ + /* b can even be [0-, 0+] */ + /* The result is [-oo, +oo] and both endpoints are exact. */ + /*MPFI_ERROR ("mpfi_inv: inversion by an interval that contains 0");*/ + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + } + else { /* signed zeroes and Infinity are properly handled by MPFR */ + mpfr_init2 (tmp, mpfr_get_prec (&(a->right))); + inexact_right = mpfr_ui_div (tmp, 1, &(b->left), MPFI_RNDU); + inexact_left = mpfr_ui_div (&(a->left), 1, &(b->right), MPFI_RNDD); + mpfr_set (&(a->right), tmp, MPFI_RNDU); /* exact */ + mpfr_clear (tmp); + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + } + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + return inexact; +} diff --git a/src/is_empty.c b/src/is_empty.c new file mode 100644 index 0000000..7ed73b9 --- /dev/null +++ b/src/is_empty.c @@ -0,0 +1,32 @@ +/* is_empty.c -- Test if an interval is empty. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_is_empty (mpfi_srcptr a) +{ + return ( MPFI_NAN_P (a) || (mpfr_cmp (&(a->left), &(a->right)) > 0) ); +} diff --git a/src/is_inside.c b/src/is_inside.c new file mode 100644 index 0000000..fd404c3 --- /dev/null +++ b/src/is_inside.c @@ -0,0 +1,122 @@ +/* is_inside.c -- Test whether the first operand is in the second one. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2011, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_is_strictly_inside (mpfi_srcptr a, mpfi_srcptr b) +{ + return mpfr_cmp (&(b->left), &(a->left)) < 0 + && mpfr_cmp (&(a->right), &(b->right)) < 0; +} + +int +mpfi_is_inside (mpfi_srcptr a, mpfi_srcptr b) +{ + /* Returns 0 if one of the operands is a NaN */ + if (MPFI_NAN_P (a) || MPFI_NAN_P (b)) + return 0; + + return mpfr_cmp (&(b->left), &(a->left)) <= 0 + && mpfr_cmp (&(a->right), &(b->right)) <= 0; +} + +int +mpfi_is_inside_d (const double a, mpfi_srcptr b) +{ + int res; + mpfi_t tmp; + + mpfi_init2 (tmp, mpfi_get_prec (b)); + mpfi_set_d (tmp, a); + res = mpfi_is_inside (tmp, b); + MPFI_CLEAR (tmp); + + return res; +} + +int +mpfi_is_inside_ui (const unsigned long a, mpfi_srcptr b) +{ + /* Returns 0 if one of the operands is a NaN */ + if (MPFI_NAN_P (b)) + return 0; + + return mpfr_cmp_ui (&(b->left), a) <= 0 + && mpfr_cmp_ui (&(b->right), a) >= 0; +} + +int +mpfi_is_inside_si (const long a, mpfi_srcptr b) +{ + /* Returns 0 if one of the operands is a NaN */ + if (MPFI_NAN_P (b)) + return 0; + + return mpfr_cmp_si (&(b->left), a) <= 0 + && mpfr_cmp_si (&(b->right), a) >= 0; +} + +int +mpfi_is_inside_z (mpz_srcptr a, mpfi_srcptr b) +{ + int res; + mpfi_t tmp; + + mpfi_init2 (tmp, mpfi_get_prec (b)); + mpfi_set_z (tmp, a); + res = mpfi_is_inside (tmp, b); + MPFI_CLEAR (tmp); + + return res; +} + +int +mpfi_is_inside_q (mpq_srcptr a, mpfi_srcptr b) +{ + int res; + mpfi_t tmp; + /* Returns 0 if one of the operands is a NaN */ + if (MPFI_NAN_P (b)) + return 0; + + mpfi_init2 (tmp, mpfi_get_prec (b)); + mpfi_set_q (tmp, a); + res = mpfi_is_inside (tmp, b); + MPFI_CLEAR (tmp); + + return res; +} + +int +mpfi_is_inside_fr (mpfr_srcptr a, mpfi_srcptr b) +{ + /* Returns 0 if one of the operands is a NaN */ + if (mpfr_nan_p (a) || MPFI_NAN_P (b)) + return 0; + + return mpfr_cmp (a, &(b->left)) >= 0 + && mpfr_cmp (a, &(b->right)) <= 0; +} diff --git a/src/log.c b/src/log.c new file mode 100644 index 0000000..8b07cab --- /dev/null +++ b/src/log.c @@ -0,0 +1,53 @@ +/* log.c -- Logarithm of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Computes the log of an interval */ +/* Special cases are handled by mpfr_log */ + +int +mpfi_log (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_log (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_log (&(a->right), &(b->right), MPFI_RNDU); + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/log10.c b/src/log10.c new file mode 100644 index 0000000..aa07abb --- /dev/null +++ b/src/log10.c @@ -0,0 +1,50 @@ +/* log10.c -- Logarithm in base 10 of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_log10 (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_log10 (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_log10 (&(a->right), &(b->right), MPFI_RNDU); + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + return inexact; +} + diff --git a/src/log1p.c b/src/log1p.c new file mode 100644 index 0000000..ff5b528 --- /dev/null +++ b/src/log1p.c @@ -0,0 +1,46 @@ +/* log1p.c -- Logarithm of 1 plus an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Special cases are handled by mpfr_log */ +int +mpfi_log1p (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_log1p (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_log1p (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/log2.c b/src/log2.c new file mode 100644 index 0000000..1f1ab54 --- /dev/null +++ b/src/log2.c @@ -0,0 +1,51 @@ +/* log2.c -- Logarithm in base 2 of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Special cases are handled by mpfr_log */ +int +mpfi_log2 (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_log2 (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_log2 (&(a->right), &(b->right), MPFI_RNDU); + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/mag.c b/src/mag.c new file mode 100644 index 0000000..a6285e2 --- /dev/null +++ b/src/mag.c @@ -0,0 +1,55 @@ +/* mag.c -- Element with largest absolute value. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Magnitude: the largest absolute value of any element */ +int +mpfi_mag (mpfr_ptr m, mpfi_srcptr x) +{ + int inexact; + + if (MPFI_NAN_P (x)) { + mpfr_set_nan (m); + MPFR_RET_NAN; + } + + if (mpfi_is_nonneg_default (x)) { + inexact = mpfr_set (m, &(x->right), MPFI_RNDU); + if (mpfr_zero_p (m) && mpfr_signbit (m)) + /* fix sign of zero */ + mpfr_neg (m, m, MPFI_RNDU); + } + else if (mpfi_is_nonpos_default (x)) { + inexact = mpfr_neg (m, &(x->left), MPFI_RNDU); + } + else { /* x contains 0 */ + inexact = mpfr_neg (m, &(x->left), MPFI_RNDU); + if (mpfr_cmp (m, &(x->right)) < 0) + inexact = mpfr_set (m, &(x->right), MPFI_RNDU); + } + + return inexact; +} diff --git a/src/mid.c b/src/mid.c new file mode 100644 index 0000000..de20f78 --- /dev/null +++ b/src/mid.c @@ -0,0 +1,66 @@ +/* mid.c -- Middle of the interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Middle of y + With an IEEE-compliant arithmetic, this formula provides more + accurate results than x->left + 0.5*(x->right - x->left) or + x->right - 0.5*(x->right - x->left) */ + +int +mpfi_mid (mpfr_ptr m, mpfi_srcptr y) +{ + int inexact_add, inexact_div2=0; + mpfr_t tmp_l, tmp_r; + + inexact_add = mpfr_add (m, &(y->left), &(y->right), MPFR_RNDN); + + /* when one of the bound is infinite: nothing to be done */ + if ( ! (MPFR_IS_INF(&(y->left)) || MPFR_IS_INF(&y->right)) ) + { + /* In case of overflow: first division by 2 and then addition */ + if (MPFR_IS_INF(m)) + { + mpfr_init2(tmp_l, mpfi_get_prec(y)); + mpfr_div_2ui(tmp_l, &(y->left), 1, MPFR_RNDN); /* should be exact*/ + mpfr_init2(tmp_r, mpfi_get_prec(y)); + mpfr_div_2ui(tmp_r, &(y->right), 1, MPFR_RNDN); /* should be exact*/ + inexact_add = mpfr_add (m, tmp_l, tmp_r, MPFR_RNDN); + mpfr_clear (tmp_l); + mpfr_clear (tmp_r); + } + else + { + inexact_div2 = mpfr_div_2ui (m, m, 1, MPFR_RNDN); + } + } + + /* Hope it copes correctly with an underflow in the division by 2... */ + if (inexact_div2) + return inexact_div2; + else + return inexact_add; +} diff --git a/src/mig.c b/src/mig.c new file mode 100644 index 0000000..deda72b --- /dev/null +++ b/src/mig.c @@ -0,0 +1,48 @@ +/* mig.c -- Element with the smallest absolute value. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Mignitude: the smallest absolute value of any element */ +int +mpfi_mig (mpfr_ptr m, mpfi_srcptr x) +{ + int inexact; + + if (MPFI_NAN_P (x)) { + mpfr_set_nan (m); + MPFR_RET_NAN; + } + + if (mpfi_is_nonneg_default (x)) + inexact = mpfr_set (m, &(x->left), MPFI_RNDD); + else if (mpfi_is_nonpos_default (x)) + inexact = mpfr_neg (m, &(x->right), MPFI_RNDD); + else { /* x contains 0 */ + inexact = mpfr_set_ui (m, 0, MPFI_RNDD); + } + + return inexact; +} diff --git a/src/mpfi-impl.h b/src/mpfi-impl.h new file mode 100644 index 0000000..591427b --- /dev/null +++ b/src/mpfi-impl.h @@ -0,0 +1,111 @@ +/* mpfi-impl.h -- Include file for mpfi. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2018, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#ifndef __MPFI_IMPL_H__ +#define __MPFI_IMPL_H__ + +#include "mpfi.h" +#include "mpfi_config.h" + +#if MPFR_VERSION < MPFR_VERSION_NUM(3,0,0) +#define MPFI_RNDD GMP_RNDD +#define MPFI_RNDU GMP_RNDU +#else +#define MPFI_RNDD MPFR_RNDD +#define MPFI_RNDU MPFR_RNDU +#define GMP_RNDN MPFR_RNDN +#endif + +#define MPFI_IS_POS(x) ((mpfr_sgn((&(x->left)))>=0) && (mpfr_sgn((&(x->right)))>0)) +#define MPFI_IS_STRICTLY_POS(x) ((mpfr_sgn((&(x->left)))>0) && (mpfr_sgn((&(x->right)))>0)) +#define MPFI_IS_NONNEG(x) ((mpfr_sgn((&(x->left)))>=0) && (mpfr_sgn((&(x->right)))>=0)) +#define MPFI_IS_NEG(x) ((mpfr_sgn((&(x->left)))<0) && (mpfr_sgn((&(x->right)))<=0)) +#define MPFI_IS_STRICTLY_NEG(x) ((mpfr_sgn((&(x->left)))<0) && (mpfr_sgn((&(x->right)))<0)) +#define MPFI_IS_NONPOS(x) ((mpfr_sgn((&(x->left)))<=0) && (mpfr_sgn((&(x->right)))<=0)) +#define MPFI_IS_NULL(x) ((mpfr_sgn((&(x->left)))==0) && (mpfr_sgn((&(x->right)))==0)) +#define MPFI_HAS_ZERO(x) ((mpfr_sgn((&(x->left)))<0) && (mpfr_sgn((&(x->right)))>0)) +#define MPFI_HAS_ZERO_NONSTRICT(x) ((mpfr_sgn((&(x->left)))<=0) && (mpfr_sgn((&(x->right)))>=0)) + + +#if defined(GMP_NUMB_BITS) /* GMP 4.1.2 or above */ +# define BITS_PER_MP_LIMB (GMP_NUMB_BITS+GMP_NAIL_BITS) +#elif defined (__GMP_BITS_PER_MP_LIMB) /* Older versions 4.x.x */ +#define BITS_PER_MP_LIMB __GMP_BITS_PER_MP_LIMB +#else +# error "Could not detect BITS_PER_MP_LIMB. Get GMP 4.1.0 at least." +#endif + +#define MPFR_RET_NAN do {mpfr_set_nanflag(); return 0;} while (0) + +#define MPFR_IS_NAN(x) (mpfr_nan_p(x)) +#define MPFR_IS_ZERO(x) (mpfr_sgn(x) == 0) +#define MPFR_IS_INF(x) (mpfr_inf_p(x)) + +/* Internal functions */ + +#if defined (__cplusplus) +extern "C" { +#endif + + + +mpfr_prec_t mpfi_quadrant (mpz_ptr, mpfr_srcptr); +int mpfi_cmp_sym_pi (mpz_srcptr, mpfr_srcptr, mpfr_srcptr, mpfr_prec_t); + +/* default comparison functions */ +int mpfi_cmp_default (mpfi_srcptr, mpfi_srcptr); +int mpfi_cmp_d_default (mpfi_srcptr, const double); +int mpfi_cmp_ui_default (mpfi_srcptr, const unsigned long); +int mpfi_cmp_si_default (mpfi_srcptr, const long); +int mpfi_cmp_z_default (mpfi_srcptr, mpz_srcptr); +int mpfi_cmp_q_default (mpfi_srcptr, mpq_srcptr); +int mpfi_cmp_fr_default (mpfi_srcptr, mpfr_srcptr); + +int mpfi_is_pos_default (mpfi_srcptr); +int mpfi_is_nonneg_default (mpfi_srcptr); +int mpfi_is_neg_default (mpfi_srcptr); +int mpfi_is_nonpos_default (mpfi_srcptr); +int mpfi_is_zero_default (mpfi_srcptr); +int mpfi_is_strictly_neg_default (mpfi_srcptr); +int mpfi_is_strictly_pos_default (mpfi_srcptr); + +#if defined (__cplusplus) +} +#endif + +/* Debug macros */ +#ifdef WARN_IF_REVERTED_ENDPOINTS +/* include stdio.h when using this macro */ +# define WARNING_REVERTED_ENDPOINTS(a, fname) \ + do { \ + fprintf (stdout, "Pb endpoints in reverse order in %s\n", fname); \ + mpfi_out_str (stdout, 10, 0, a); \ + fprintf (stdout, "\n"); \ + } while (0) +#else +# define WARNING_REVERTED_ENDPOINTS(a, fname) +#endif + +#endif /* __MPFI_IMPL_H__ */ diff --git a/src/mpfi-intmax.h b/src/mpfi-intmax.h new file mode 100644 index 0000000..7609430 --- /dev/null +++ b/src/mpfi-intmax.h @@ -0,0 +1,70 @@ +/* MPFI copy of the MPFR internal header related to intmax_t. + +Copyright 2004-2018 Free Software Foundation, Inc. +Contributed by the AriC and Caramba projects, INRIA. + +This file is part of the GNU MPFR Library. + +The GNU MPFR Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MPFR Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef __MPFR_INTMAX_H__ +#define __MPFR_INTMAX_H__ + +/* The ISO C99 standard specifies that in C++ implementations the + * INTMAX_MAX, ... macros should only be defined if explicitly requested. + */ +#if defined __cplusplus +# define __STDC_LIMIT_MACROS +# define __STDC_CONSTANT_MACROS +#endif + +/* The definition of MPFR_USE_INTMAX_T is needed on systems for which + * the current (non-standard) macro tests in mpfr.h is not sufficient. + * This will force the support of intmax_t/uintmax_t if + * and/or are available. This also avoids a failure in the + * tests (replace the macro tests in mpfr.h by just + * #if defined (MPFR_USE_INTMAX_T) + * to simulate such a system and reproduce the problem). + * Note: if this makes the build fail on some systems (because these + * headers are broken), we will need a configure test to undefine + * HAVE_INTTYPES_H and HAVE_STDINT_H in such a case. + */ + +#if HAVE_INTTYPES_H +# include +# define MPFR_USE_INTMAX_T +#endif + +#if HAVE_STDINT_H +# include +# define MPFR_USE_INTMAX_T +#endif + +/* Largest signed integer type available for the MPFR build. */ +#if defined(MPFR_USE_INTMAX_T) +typedef intmax_t mpfr_intmax_t; +typedef uintmax_t mpfr_uintmax_t; +#elif defined(HAVE_LONG_LONG) +typedef long long mpfr_intmax_t; +typedef unsigned long long mpfr_uintmax_t; +# define MPFR_INTMAX_MAX LLONG_MAX +#else +typedef long mpfr_intmax_t; +typedef unsigned long mpfr_uintmax_t; +# define MPFR_INTMAX_MAX LONG_MAX +#endif + +#endif diff --git a/src/mpfi.h b/src/mpfi.h new file mode 100644 index 0000000..eeb7174 --- /dev/null +++ b/src/mpfi.h @@ -0,0 +1,387 @@ +/* mpfi.h -- Include file for mpfi. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2012, 2018, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + + +#ifndef __MPFI_H__ +#define __MPFI_H__ + +/* Machine independent implementations */ + +#include +#include + +/* Define MPFI version number */ +#define MPFI_VERSION_MAJOR 1 +#define MPFI_VERSION_MINOR 5 +#define MPFI_VERSION_PATCHLEVEL 4 +#define MPFI_VERSION_STRING "1.5.4" + +typedef struct { + __mpfr_struct left; + __mpfr_struct right; +}__mpfi_struct; + +typedef __mpfi_struct mpfi_t[1]; +typedef __mpfi_struct *mpfi_ptr; +typedef const __mpfi_struct *mpfi_srcptr; + +#ifdef __cplusplus +extern "C" { +#endif + +/* Rounding */ +int mpfi_round_prec (mpfi_ptr, mpfr_prec_t prec); + + +/* Initialization, destruction and assignment */ + +/* initializations */ +void mpfi_init (mpfi_ptr); +void mpfi_init2 (mpfi_ptr, mpfr_prec_t); +void mpfi_inits (mpfi_ptr x, ...); +void mpfi_inits2 (mpfr_prec_t p, mpfi_ptr x, ...); + +void mpfi_clear (mpfi_ptr); +void mpfi_clears (mpfi_ptr x, ...); + +/* mpfi bounds have the same precision */ +mpfr_prec_t mpfi_get_prec (mpfi_srcptr); +void mpfi_set_prec (mpfi_ptr, mpfr_prec_t); + + +/* assignment functions */ +int mpfi_set (mpfi_ptr, mpfi_srcptr); +int mpfi_set_si (mpfi_ptr, const long); +int mpfi_set_ui (mpfi_ptr, const unsigned long); +/* int mpfi_set_sj (mpfi_ptr, const intmax_t); */ +/* int mpfi_set_uj (mpfi_ptr, const uintmax_t); */ +int mpfi_set_d (mpfi_ptr, const double); +int mpfi_set_flt (mpfi_ptr, const float); +int mpfi_set_ld (mpfi_ptr, const long double); +int mpfi_set_z (mpfi_ptr, mpz_srcptr); +int mpfi_set_q (mpfi_ptr, mpq_srcptr); +int mpfi_set_fr (mpfi_ptr, mpfr_srcptr); +int mpfi_set_str (mpfi_ptr, const char *, int); + +/* combined initialization and assignment functions */ +int mpfi_init_set (mpfi_ptr, mpfi_srcptr); +int mpfi_init_set_si (mpfi_ptr, const long); +int mpfi_init_set_ui (mpfi_ptr, const unsigned long); +int mpfi_init_set_d (mpfi_ptr, const double); +int mpfi_init_set_flt (mpfi_ptr, const float); +int mpfi_init_set_ld (mpfi_ptr, const long double); +int mpfi_init_set_z (mpfi_ptr, mpz_srcptr); +int mpfi_init_set_q (mpfi_ptr, mpq_srcptr); +int mpfi_init_set_fr (mpfi_ptr, mpfr_srcptr); +int mpfi_init_set_str (mpfi_ptr, const char *, int); + +/* swapping two intervals */ +void mpfi_swap (mpfi_ptr, mpfi_ptr); + + +/* Various useful interval functions */ +/* with scalar or interval results */ + +/* absolute diameter */ +int mpfi_diam_abs (mpfr_ptr, mpfi_srcptr); +/* relative diameter */ +int mpfi_diam_rel (mpfr_ptr, mpfi_srcptr); +/* diameter: relative if the interval does not contain 0 */ +/* absolute otherwise */ +int mpfi_diam (mpfr_ptr, mpfi_srcptr); +/* magnitude: the largest absolute value of any element */ +int mpfi_mag (mpfr_ptr, mpfi_srcptr); +/* mignitude: the smallest absolute value of any element */ +int mpfi_mig (mpfr_ptr, mpfi_srcptr); +/* middle of y */ +int mpfi_mid (mpfr_ptr, mpfi_srcptr); +/* picks randomly a point m in y */ +void mpfi_alea (mpfr_ptr, mpfi_srcptr); +void mpfi_urandom (mpfr_ptr, mpfi_srcptr, gmp_randstate_t); +void mpfi_nrandom (mpfr_ptr, mpfi_srcptr, gmp_randstate_t); +void mpfi_erandom (mpfr_ptr, mpfi_srcptr, gmp_randstate_t); + + +/* Conversions */ + +double mpfi_get_d (mpfi_srcptr); +void mpfi_get_fr (mpfr_ptr, mpfi_srcptr); + + +/* Basic arithmetic operations */ + +/* arithmetic operations between two interval operands */ +int mpfi_add (mpfi_ptr, mpfi_srcptr, mpfi_srcptr); +int mpfi_sub (mpfi_ptr, mpfi_srcptr, mpfi_srcptr); +int mpfi_mul (mpfi_ptr, mpfi_srcptr, mpfi_srcptr); +int mpfi_div (mpfi_ptr, mpfi_srcptr, mpfi_srcptr); + +/* arithmetic operations between an interval operand and a double prec. floating-point */ +int mpfi_add_d (mpfi_ptr, mpfi_srcptr, const double); +int mpfi_sub_d (mpfi_ptr, mpfi_srcptr, const double); +int mpfi_d_sub (mpfi_ptr, const double, mpfi_srcptr); +int mpfi_mul_d (mpfi_ptr, mpfi_srcptr, const double); +int mpfi_div_d (mpfi_ptr, mpfi_srcptr, const double); +int mpfi_d_div (mpfi_ptr, const double, mpfi_srcptr); + +/* arithmetic operations between an interval operand and an unsigned long integer */ +int mpfi_add_ui (mpfi_ptr, mpfi_srcptr, const unsigned long); +int mpfi_sub_ui (mpfi_ptr, mpfi_srcptr, const unsigned long); +int mpfi_ui_sub (mpfi_ptr, const unsigned long, mpfi_srcptr); +int mpfi_mul_ui (mpfi_ptr, mpfi_srcptr, const unsigned long); +int mpfi_div_ui (mpfi_ptr, mpfi_srcptr, const unsigned long); +int mpfi_ui_div (mpfi_ptr, const unsigned long, mpfi_srcptr); + +/* arithmetic operations between an interval operand and a long integer */ +int mpfi_add_si (mpfi_ptr, mpfi_srcptr, const long); +int mpfi_sub_si (mpfi_ptr, mpfi_srcptr, const long); +int mpfi_si_sub (mpfi_ptr, const long, mpfi_srcptr); +int mpfi_mul_si (mpfi_ptr, mpfi_srcptr, const long); +int mpfi_div_si (mpfi_ptr, mpfi_srcptr, const long); +int mpfi_si_div (mpfi_ptr, const long, mpfi_srcptr); + +/* arithmetic operations between an interval operand and a multiple prec. integer */ +int mpfi_add_z (mpfi_ptr, mpfi_srcptr, mpz_srcptr); +int mpfi_sub_z (mpfi_ptr, mpfi_srcptr, mpz_srcptr); +int mpfi_z_sub (mpfi_ptr, mpz_srcptr, mpfi_srcptr); +int mpfi_mul_z (mpfi_ptr, mpfi_srcptr, mpz_srcptr); +int mpfi_div_z (mpfi_ptr, mpfi_srcptr, mpz_srcptr); +int mpfi_z_div (mpfi_ptr, mpz_srcptr, mpfi_srcptr); + +/* arithmetic operations between an interval operand and a multiple prec. rational */ +int mpfi_add_q (mpfi_ptr, mpfi_srcptr, mpq_srcptr); +int mpfi_sub_q (mpfi_ptr, mpfi_srcptr, mpq_srcptr); +int mpfi_q_sub (mpfi_ptr, mpq_srcptr, mpfi_srcptr); +int mpfi_mul_q (mpfi_ptr, mpfi_srcptr, mpq_srcptr); +int mpfi_div_q (mpfi_ptr, mpfi_srcptr, mpq_srcptr); +int mpfi_q_div (mpfi_ptr, mpq_srcptr, mpfi_srcptr); + +/* arithmetic operations between an interval operand and a mult. prec. floating-pt nb */ +int mpfi_add_fr (mpfi_ptr, mpfi_srcptr, mpfr_srcptr); +int mpfi_sub_fr (mpfi_ptr, mpfi_srcptr, mpfr_srcptr); +int mpfi_fr_sub (mpfi_ptr, mpfr_srcptr, mpfi_srcptr); +int mpfi_mul_fr (mpfi_ptr, mpfi_srcptr, mpfr_srcptr); +int mpfi_div_fr (mpfi_ptr, mpfi_srcptr, mpfr_srcptr); +int mpfi_fr_div (mpfi_ptr, mpfr_srcptr, mpfi_srcptr); + +/* arithmetic operations taking a single interval operand */ +int mpfi_neg (mpfi_ptr, mpfi_srcptr); +int mpfi_sqr (mpfi_ptr, mpfi_srcptr); +/* the inv function generates the whole real interval + if 0 is in the interval defining the divisor */ +int mpfi_inv (mpfi_ptr, mpfi_srcptr); +/* the sqrt of a (partially) negative interval is a NaN */ +int mpfi_sqrt (mpfi_ptr, mpfi_srcptr); +int mpfi_cbrt (mpfi_ptr, mpfi_srcptr); +/* the first interval contains the absolute values of */ +/* every element of the second interval */ +int mpfi_abs (mpfi_ptr, mpfi_srcptr); + +/* extended division: returns 2 intervals if the denominator contains 0 */ +int mpfi_div_ext (mpfi_ptr, mpfi_ptr, mpfi_srcptr, mpfi_srcptr); + +/* various operations */ +int mpfi_mul_2exp (mpfi_ptr, mpfi_srcptr, unsigned long); +int mpfi_mul_2ui (mpfi_ptr, mpfi_srcptr, unsigned long); +int mpfi_mul_2si (mpfi_ptr, mpfi_srcptr, long); +int mpfi_div_2exp (mpfi_ptr, mpfi_srcptr, unsigned long); +int mpfi_div_2ui (mpfi_ptr, mpfi_srcptr, unsigned long); +int mpfi_div_2si (mpfi_ptr, mpfi_srcptr, long); + +/* Special functions */ +int mpfi_log (mpfi_ptr, mpfi_srcptr); +int mpfi_exp (mpfi_ptr, mpfi_srcptr); +int mpfi_exp2 (mpfi_ptr, mpfi_srcptr); + +int mpfi_cos (mpfi_ptr, mpfi_srcptr); +int mpfi_sin (mpfi_ptr, mpfi_srcptr); +int mpfi_tan (mpfi_ptr, mpfi_srcptr); +int mpfi_acos (mpfi_ptr, mpfi_srcptr); +int mpfi_asin (mpfi_ptr, mpfi_srcptr); +int mpfi_atan (mpfi_ptr, mpfi_srcptr); +int mpfi_atan2 (mpfi_ptr, mpfi_srcptr, mpfi_srcptr); + +int mpfi_sec (mpfi_ptr, mpfi_srcptr); +int mpfi_csc (mpfi_ptr, mpfi_srcptr); +int mpfi_cot (mpfi_ptr, mpfi_srcptr); + +int mpfi_cosh (mpfi_ptr, mpfi_srcptr); +int mpfi_sinh (mpfi_ptr, mpfi_srcptr); +int mpfi_tanh (mpfi_ptr, mpfi_srcptr); +int mpfi_acosh (mpfi_ptr, mpfi_srcptr); +int mpfi_asinh (mpfi_ptr, mpfi_srcptr); +int mpfi_atanh (mpfi_ptr, mpfi_srcptr); + +int mpfi_sech (mpfi_ptr, mpfi_srcptr); +int mpfi_csch (mpfi_ptr, mpfi_srcptr); +int mpfi_coth (mpfi_ptr, mpfi_srcptr); + +int mpfi_log1p (mpfi_ptr, mpfi_srcptr); +int mpfi_expm1 (mpfi_ptr, mpfi_srcptr); + +int mpfi_log2 (mpfi_ptr, mpfi_srcptr); +int mpfi_log10 (mpfi_ptr, mpfi_srcptr); + +int mpfi_hypot (mpfi_ptr, mpfi_srcptr, mpfi_srcptr); + +int mpfi_const_log2 (mpfi_ptr); +int mpfi_const_pi (mpfi_ptr); +int mpfi_const_euler (mpfi_ptr); +int mpfi_const_catalan (mpfi_ptr); + +/* Comparison functions */ +/* Warning: the meaning of interval comparison is not clearly defined */ +/* customizable comparison functions */ + +extern int (*mpfi_cmp) (mpfi_srcptr, mpfi_srcptr); + +extern int (*mpfi_cmp_d) (mpfi_srcptr, const double); +extern int (*mpfi_cmp_ui) (mpfi_srcptr, const unsigned long); +extern int (*mpfi_cmp_si) (mpfi_srcptr, const long); +extern int (*mpfi_cmp_z) (mpfi_srcptr, mpz_srcptr); +extern int (*mpfi_cmp_q) (mpfi_srcptr, mpq_srcptr); +extern int (*mpfi_cmp_fr) (mpfi_srcptr, mpfr_srcptr); + +extern int (*mpfi_is_pos) (mpfi_srcptr); +extern int (*mpfi_is_nonneg) (mpfi_srcptr); +extern int (*mpfi_is_neg) (mpfi_srcptr); +extern int (*mpfi_is_nonpos) (mpfi_srcptr); +extern int (*mpfi_is_zero) (mpfi_srcptr); +extern int (*mpfi_is_strictly_pos) (mpfi_srcptr); +extern int (*mpfi_is_strictly_neg) (mpfi_srcptr); + +int mpfi_has_zero (mpfi_srcptr); + +int mpfi_nan_p (mpfi_srcptr); +int mpfi_inf_p (mpfi_srcptr); +int mpfi_bounded_p (mpfi_srcptr); + +/* Interval manipulation */ + +/* operations related to the internal representation by endpoints */ + +/* get left or right bound of the interval defined by the + second argument and put the result in the first one */ +int mpfi_get_left (mpfr_ptr, mpfi_srcptr); +int mpfi_get_right (mpfr_ptr, mpfi_srcptr); + +int mpfi_revert_if_needed (mpfi_ptr); + +/* Set operations on intervals */ +/* "Convex hulls" */ +/* extends the interval defined by the first argument + so that it contains the second one */ + +int mpfi_put (mpfi_ptr, mpfi_srcptr); +int mpfi_put_d (mpfi_ptr, const double); +int mpfi_put_si (mpfi_ptr, const long); +int mpfi_put_ui (mpfi_ptr, const unsigned long); +int mpfi_put_z (mpfi_ptr, mpz_srcptr); +int mpfi_put_q (mpfi_ptr, mpq_srcptr); +int mpfi_put_fr (mpfi_ptr, mpfr_srcptr); + +/* builds an interval whose left bound is the lower (round -infty) + than the second argument and the right bound is greater + (round +infty) than the third one */ + +int mpfi_interv_d (mpfi_ptr, const double, const double); +int mpfi_interv_si (mpfi_ptr, const long, const long); +int mpfi_interv_ui (mpfi_ptr, const unsigned long, const unsigned long); +int mpfi_interv_z (mpfi_ptr, mpz_srcptr, mpz_srcptr); +int mpfi_interv_q (mpfi_ptr, mpq_srcptr, mpq_srcptr); +int mpfi_interv_fr (mpfi_ptr, mpfr_srcptr, mpfr_srcptr); + +/* Inclusion tests */ +/* tests if the first argument is inside the interval + defined by the second one */ +int mpfi_is_strictly_inside (mpfi_srcptr, mpfi_srcptr); +int mpfi_is_inside (mpfi_srcptr, mpfi_srcptr); +int mpfi_is_inside_d (const double, mpfi_srcptr); +int mpfi_is_inside_ui (const unsigned long, mpfi_srcptr); +int mpfi_is_inside_si (const long, mpfi_srcptr); +int mpfi_is_inside_z (mpz_srcptr, mpfi_srcptr); +int mpfi_is_inside_q (mpq_srcptr, mpfi_srcptr); +int mpfi_is_inside_fr (mpfr_srcptr, mpfi_srcptr); + +/* set operations */ +int mpfi_is_empty (mpfi_srcptr); +int mpfi_intersect (mpfi_ptr, mpfi_srcptr, mpfi_srcptr); +int mpfi_union (mpfi_ptr, mpfi_srcptr, mpfi_srcptr); + +/* complement... : to do later */ + + +/* Miscellaneous */ + +/* adds the second argument to the right bound of the first one + and subtracts the second argument to the left bound of + the first one */ +int mpfi_increase (mpfi_ptr, mpfr_srcptr); +/* keeps the same center and multiply the radius by 2*(1+fact) */ +int mpfi_blow (mpfi_ptr, mpfi_srcptr, double); +/* splits the interval into 2 halves */ +int mpfi_bisect (mpfi_ptr, mpfi_ptr, mpfi_srcptr); + +const char * mpfi_get_version (void); + +/* Error handling */ + +extern int mpfi_error; +void mpfi_reset_error (void); +void mpfi_set_error (const int); +int mpfi_is_error (void); +#ifdef __cplusplus +} +#endif + +#define MPFI_ERROR(s) \ + do { \ + if(!mpfi_error) { \ + mpfi_error = 1; \ + fprintf(stderr, "\n%s\n", s); \ + } \ + } while (0) + +#define MPFI_FLAGS_BOTH_ENDPOINTS_EXACT 0 +#define MPFI_FLAGS_LEFT_ENDPOINT_INEXACT 1 +#define MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT 2 +#define MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT 3 + +#define MPFI_BOTH_ARE_EXACT(x) ( (int)(x) == 0 ) +#define MPFI_LEFT_IS_INEXACT(x) ( (int)(x)%2 ) +#define MPFI_RIGHT_IS_INEXACT(x) ( (int)(x)/2 ) +#define MPFI_BOTH_ARE_INEXACT(x) ( (int)(x) == 3 ) + +#define MPFI_REVERT_INEXACT_FLAGS(x) \ + ( ((x)==1) ? 2 : ((x)==2) ? 1 : x ) + +#define MPFI_NAN_P(a) ( MPFR_IS_NAN(&(a->left)) || MPFR_IS_NAN (&(a->right)) ) +#define MPFI_INF_P(a) ( MPFR_IS_INF(&(a->left)) || MPFR_IS_INF (&(a->right)) ) +#define MPFI_IS_ZERO(a) (MPFI_NAN_P(a) ? 0 : ((mpfr_sgn(&(a->right))==0) && (mpfr_sgn(&(a->left))==0))) + +#define MPFI_CLEAR(m) {mpfr_clear(&(m->right)); mpfr_clear(&(m->left));} + +#endif /* __MPFI_H__ */ diff --git a/src/mpfi_io.h b/src/mpfi_io.h new file mode 100644 index 0000000..22acebe --- /dev/null +++ b/src/mpfi_io.h @@ -0,0 +1,50 @@ +/* mpfi_io.h -- Header for mpfi_io.c. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + + +#ifndef __MPFI_IO_H__ +#define __MPFI_IO_H__ + +#include +#include +#include +#include + +/*#define isblank isspace*/ +#define MPFI_ISSPACE isspace + +#ifdef __cplusplus +extern "C" { +#endif +size_t mpfi_out_str(FILE *stream, int base, size_t n_digits, mpfi_srcptr op); +size_t mpfi_inp_str(mpfi_ptr x,FILE *stream,int base); + +void mpfi_print_binary(mpfi_srcptr); +#ifdef __cplusplus +} +#endif + +#endif /* __MPFI_IO_H__ */ diff --git a/src/mul.c b/src/mul.c new file mode 100644 index 0000000..794ad7b --- /dev/null +++ b/src/mul.c @@ -0,0 +1,158 @@ +/* mul.c -- Multiply two intervals. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_mul (mpfi_ptr a, mpfi_srcptr b, mpfi_srcptr c) +{ + mpfr_t t1; + mpfr_t t2; + int inexact_left, inexact_right; + int inexact = 0; + + /* Handling the NaN cases */ + if ( MPFI_NAN_P (b) || MPFI_NAN_P (c) ) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + /* Handling the case where one operand is 0, in order */ + /* to avoid problems with 0 * an infinite interval */ + if (MPFI_IS_ZERO (b)) { + return (mpfi_set (a, b)); + } + if (MPFI_IS_ZERO (c)) { + return (mpfi_set (a, c)); + } + + if (mpfr_sgn (&(b->left)) >= 0) { + if (mpfr_sgn (&(c->left)) >=0) { + /* b nonnegative and c nonnegative */ + inexact_left = mpfr_mul (&(a->left), &(b->left), &(c->left), MPFI_RNDD); + inexact_right = mpfr_mul (&(a->right), &(b->right), &(c->right), MPFI_RNDU); + } + else { + mpfr_init2 (t1, mpfr_get_prec (&(a->left))); + if (mpfr_sgn (&(c->right)) <= 0) { + /* b nonnegative and c non-positive */ + inexact_left = mpfr_mul (t1, &(b->right), &(c->left), MPFI_RNDD); + inexact_right = mpfr_mul (&(a->right), &(b->left), &(c->right), MPFI_RNDU); + } + else { + /* b nonnegative and c overlapping 0 */ + inexact_left = mpfr_mul (t1, &(b->right), &(c->left), MPFI_RNDD); + inexact_right = mpfr_mul (&(a->right), &(b->right), &(c->right), MPFI_RNDU); + } + mpfr_set (&(a->left), t1, MPFI_RNDD); /* exact */ + mpfr_clear (t1); + } + } + else { + if (mpfr_sgn (&(b->right)) <= 0) { + /* b non-positive */ + mpfr_init2 (t1, mpfr_get_prec (&(a->left))); + if (mpfr_sgn (&(c->left)) >= 0) { + /* b non-positive and c nonnegative */ + inexact_left = mpfr_mul (t1, &(b->left), &(c->right), MPFI_RNDD); + inexact_right = mpfr_mul (&(a->right), &(b->right), &(c->left), MPFI_RNDU); + } + else { + if (mpfr_sgn (&(c->right)) <= 0) { + /* b non-positive and c non-positive */ + inexact_left = mpfr_mul (t1, &(b->right), &(c->right), MPFI_RNDD); + inexact_right = mpfr_mul (&(a->right), &(b->left), &(c->left), MPFI_RNDU); + } + else { + /* b non-positive and c overlapping 0 */ + inexact_left = mpfr_mul (t1, &(b->left), &(c->right), MPFI_RNDD); + inexact_right = mpfr_mul (&(a->right), &(b->left), &(c->left), MPFI_RNDU); + } + } + mpfr_set (&(a->left), t1, MPFI_RNDD); /* exact */ + mpfr_clear (t1); + } + else { + /* b contains 0 */ + if (mpfr_sgn (&(c->left)) >= 0) { + /* b overlapping 0 and c nonnegative */ + mpfr_init2 (t1, mpfr_get_prec (&(a->left))); + + inexact_left = mpfr_mul (t1, &(b->left), &(c->right), MPFI_RNDD); + inexact_right = mpfr_mul (&(a->right), &(b->right), &(c->right), MPFI_RNDU); + + mpfr_set (&(a->left), t1, MPFI_RNDD); + mpfr_clear (t1); + } + else { + if (mpfr_sgn (&(c->right)) <= 0) { + /* b overlapping 0 and c non-positive */ + mpfr_init2 (t1, mpfr_get_prec (&(a->left))); + + inexact_left = mpfr_mul (t1, &(b->right), &(c->left), MPFI_RNDD); + inexact_right = mpfr_mul (&(a->right), &(b->left), &(c->left), MPFI_RNDU); + + mpfr_set (&(a->left), t1, MPFI_RNDD); + mpfr_clear (t1); + } + else { + /* b overlapping 0 and c overlapping 0 + Beware the case where the result is one of the operands! */ + int inexact_tmp; + + mpfr_init2 (t1, mpfr_get_prec (&(a->left))); + mpfr_init2 (t2, mpfr_get_prec (&(a->left))); + inexact_tmp = mpfr_mul (t1, &(b->left), &(c->right), MPFI_RNDD); + inexact_left = mpfr_mul (t2, &(b->right), &(c->left), MPFI_RNDD); + if (mpfr_cmp (t1, t2) < 0) { + mpfr_swap (t2, t1); /* same precision */ + inexact_left = inexact_tmp; + } + + mpfr_set_prec (t1, mpfr_get_prec (&(a->right))); + inexact_tmp = mpfr_mul (t1, &(b->left), &(c->left), MPFI_RNDU); + inexact_right = mpfr_mul (&(a->right), &(b->right), &(c->right), MPFI_RNDU); + if (mpfr_cmp (t1, &(a->right)) > 0) { + mpfr_set (&(a->right), t1, MPFI_RNDU); /* exact */ + inexact_right = inexact_tmp; + } + mpfr_set (&(a->left), t2, MPFI_RNDD); /* exact */ + mpfr_clear (t1); + mpfr_clear (t2); + } + } + } + } + + /* no need to check to sign of an endpoint equal to 0, it should be OK */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/mul_2exp.c b/src/mul_2exp.c new file mode 100644 index 0000000..820127d --- /dev/null +++ b/src/mul_2exp.c @@ -0,0 +1,45 @@ +/* mul_2exp.c -- Scale endpoints. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_mul_2exp (mpfi_ptr a, mpfi_srcptr b, unsigned long c) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_mul_2exp (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_mul_2exp (&(a->right), &(b->right), c, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/mul_2si.c b/src/mul_2si.c new file mode 100644 index 0000000..5da6139 --- /dev/null +++ b/src/mul_2si.c @@ -0,0 +1,45 @@ +/* mul_2si.c -- Scale endpoints. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_mul_2si (mpfi_ptr a, mpfi_srcptr b, long c) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_mul_2si (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_mul_2si (&(a->right), &(b->right), c, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/mul_2ui.c b/src/mul_2ui.c new file mode 100644 index 0000000..975d301 --- /dev/null +++ b/src/mul_2ui.c @@ -0,0 +1,45 @@ +/* mul_2ui.c -- Scale endpoints. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_mul_2ui (mpfi_ptr a, mpfi_srcptr b, unsigned long c) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_mul_2ui (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_mul_2ui (&(a->right), &(b->right), c, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/mul_d.c b/src/mul_d.c new file mode 100644 index 0000000..65eb453 --- /dev/null +++ b/src/mul_d.c @@ -0,0 +1,69 @@ +/* mul_d.c -- Multiply an interval and a double. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_mul_d (mpfi_ptr a, mpfi_srcptr b, const double c) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact=0; + + if ( MPFI_NAN_P (b) ) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (c == 0.0) + { + return mpfi_set_si(a, 0); + } + else if (c < 0.0) + { + mpfr_init2(tmp, mpfr_get_prec( &(a->left)) ); + inexact_left = mpfr_mul_d (tmp, &(b->right), c, MPFI_RNDD); + inexact_right = mpfr_mul_d( &(a->right), &(b->left), c, MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear(tmp); + } + else /* c > 0.0 */ + { + inexact_left = mpfr_mul_d( &(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_mul_d( &(a->right), &(b->right), c, MPFI_RNDU); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + /* no need to check to sign of the bounds in case they are 0 */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/mul_fr.c b/src/mul_fr.c new file mode 100644 index 0000000..66f06aa --- /dev/null +++ b/src/mul_fr.c @@ -0,0 +1,50 @@ +/* mul_fr.c -- Multiply an interval and a floating-point number. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_mul_fr (mpfi_ptr a, mpfi_srcptr b, mpfr_srcptr c) +{ + mpfi_t tmp; + int inexact = 0; + + if ( MPFI_NAN_P (b) || mpfr_nan_p(c) ) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + mpfi_init2 (tmp, mpfr_get_prec (c)); + mpfi_set_fr (tmp, c); /* exact */ + inexact = mpfi_mul (a, b, tmp); + MPFI_CLEAR (tmp); + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + return inexact; +} diff --git a/src/mul_q.c b/src/mul_q.c new file mode 100644 index 0000000..2fadf4e --- /dev/null +++ b/src/mul_q.c @@ -0,0 +1,94 @@ +/* mul_q.c -- Multiply an interval and a rational number. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_mul_q (mpfi_ptr a, mpfi_srcptr b, mpq_srcptr c) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact=0; + + if ( MPFI_NAN_P (b) ) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (!mpq_sgn(c)) /* c == 0 */ + { + return mpfi_set_si(a, 0); + } + else if (mpq_sgn(c) <0) /* c < 0 */ + { + mpfr_init2(tmp, mpfr_get_prec( &(a->left)) ); + + inexact_left = mpfr_mul_q (tmp, &(b->right), c, MPFI_RNDD); + if (mpfr_inf_p (tmp) && !mpfr_inf_p (&(b->right))) + { + /* work around MPFR bug in mpfr_mul_q (present in MPFR-3.0.0) */ + inexact_left = 1; /* overflow */ + } + + inexact_right = mpfr_mul_q( &(a->right), &(b->left), c, MPFI_RNDU); + if (mpfr_inf_p (&(a->right)) && !mpfr_inf_p (&(b->left))) + { + /* work around MPFR bug in mpfr_mul_q */ + inexact_right = 1; /* overflow */ + } + + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear(tmp); + } + else /* c > 0 */ + { + int mpfr_bug_work_around; + + mpfr_bug_work_around = !mpfr_inf_p (&(b->left)); + inexact_left = mpfr_mul_q( &(a->left), &(b->left), c, MPFI_RNDD); + if (mpfr_bug_work_around && mpfr_inf_p (&(a->left))) + { + /* work around MPFR bug in mpfr_mul_q */ + inexact_left = 1; /* overflow */ + } + + mpfr_bug_work_around = !mpfr_inf_p (&(b->right)); + inexact_right = mpfr_mul_q( &(a->right), &(b->right), c, MPFI_RNDU); + if (mpfr_bug_work_around && mpfr_inf_p (&(a->right))) + { + /* work around MPFR bug in mpfr_mul_q */ + inexact_right = 1; /* overflow */ + } + } + + /* no need to check to sign of the bounds in case they are 0 */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/mul_si.c b/src/mul_si.c new file mode 100644 index 0000000..d1758e8 --- /dev/null +++ b/src/mul_si.c @@ -0,0 +1,66 @@ +/* mul_si.c -- Multiply an interval and a signed long int. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_mul_si (mpfi_ptr a, mpfi_srcptr b, const long c) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact=0; + + if ( MPFI_NAN_P (b) ) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (c == 0) + { + return mpfi_set_si(a, 0); + } + else if (c < 0) + { + mpfr_init2(tmp, mpfr_get_prec( &(a->left)) ); + inexact_left = mpfr_mul_si (tmp, &(b->right), c, MPFI_RNDD); + inexact_right = mpfr_mul_si( &(a->right), &(b->left), c, MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear(tmp); + } + else /* c > 0 */ + { + inexact_left = mpfr_mul_si( &(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_mul_si( &(a->right), &(b->right), c, MPFI_RNDU); + } + + /* no need to check to sign of the bounds in case they are 0 */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/mul_ui.c b/src/mul_ui.c new file mode 100644 index 0000000..55e825d --- /dev/null +++ b/src/mul_ui.c @@ -0,0 +1,57 @@ +/* mul_ui.c -- Multiply an interval and an unsigned long int. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_mul_ui (mpfi_ptr a, mpfi_srcptr b, const unsigned long c) +{ + int inexact_left, inexact_right, inexact=0; + + if ( MPFI_NAN_P (b) ) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (c == 0) + { + return mpfi_set_si(a, 0); + } + else /* c > 0 */ + { + inexact_left = mpfr_mul_ui( &(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_mul_ui( &(a->right), &(b->right), c, MPFI_RNDU); + } + + /* no need to check to sign of the bounds in case they are 0 */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/mul_z.c b/src/mul_z.c new file mode 100644 index 0000000..f8692e2 --- /dev/null +++ b/src/mul_z.c @@ -0,0 +1,66 @@ +/* mul_z.c -- Multiply an interval and an integer. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_mul_z (mpfi_ptr a, mpfi_srcptr b, mpz_srcptr c) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact=0; + + if ( MPFI_NAN_P (b) ) + { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (!mpz_sgn(c)) /* c == 0 */ + { + return mpfi_set_si(a, 0); + } + else if (mpz_sgn(c) <0) /* c < 0 */ + { + mpfr_init2(tmp, mpfr_get_prec( &(a->left)) ); + inexact_left = mpfr_mul_z (tmp, &(b->right), c, MPFI_RNDD); + inexact_right = mpfr_mul_z( &(a->right), &(b->left), c, MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear(tmp); + } + else /* c > 0 */ + { + inexact_left = mpfr_mul_z( &(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_mul_z( &(a->right), &(b->right), c, MPFI_RNDU); + } + + /* no need to check to sign of the bounds in case they are 0 */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/neg.c b/src/neg.c new file mode 100644 index 0000000..d9115bc --- /dev/null +++ b/src/neg.c @@ -0,0 +1,49 @@ +/* neg.c -- Return interval opposite. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_neg (mpfi_ptr a, mpfi_srcptr b) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact=0; + + mpfr_init2 (tmp, mpfr_get_prec (&(a->right))); + inexact_right = mpfr_set (tmp, &(b->left), MPFI_RNDD); + inexact_left = mpfr_neg (&(a->left), &(b->right), MPFI_RNDD); + mpfr_neg (&(a->right), tmp, MPFI_RNDU); /* exact */ + mpfr_clear (tmp); + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/nrandom.c b/src/nrandom.c new file mode 100644 index 0000000..9f341b4 --- /dev/null +++ b/src/nrandom.c @@ -0,0 +1,98 @@ +/* nrandom.c -- Random element in the interval, following a normal distribution. + without any guarantee, to be checked + +Copyright 2018 + AriC project, Inria Rhone-Alpes, France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Picks randomly a point m in y */ +void +mpfi_nrandom (mpfr_ptr m, mpfi_srcptr y, gmp_randstate_t state) +{ + mpfr_prec_t prec, tmp_prec; + mpfr_t diam, fact; + + + if (MPFI_NAN_P(y)) { + mpfr_set_nan (m); + return; + } + + if (mpfr_equal_p (&(y->left), &(y->right))) { + mpfr_set (m, &(y->left), MPFR_RNDN); + return; + } + + prec = mpfr_get_prec (m); + tmp_prec = mpfi_get_prec(y); + if (tmp_prec > prec) + { + prec = tmp_prec; + } + mpfr_init2 (diam, prec); + mpfr_init2 (fact, prec); + + mpfi_diam_abs (diam, y); + mpfr_nrandom (fact, state, MPFR_RNDN); + mpfr_add_d (fact, fact, 0.5, MPFR_RNDN); + if (mpfr_cmp_ui (fact, 0) < 0) + mpfr_set_ui(fact, 0, MPFR_RNDN); + else if (mpfr_cmp_ui(fact, 1) > 0) + mpfr_set_ui(fact, 1, MPFR_RNDN); /* now fact lies between 0 and 1 */ + + if (mpfr_cmp_ui (diam, 1) <= 0) { + /* the picked point lies at a relative distance "fact" of the left + endpoint: m = inf + (sup - inf) * fact */ + mpfr_mul (fact, fact, diam, MPFR_RNDN); + /* FIXME: because of possible cancelation, the random distribution is + not uniform among the floating-point numbers in y */ + mpfr_add (m, &(y->left), fact, MPFR_RNDN); + } + else { + mpfr_exp_t e; + if (mpfr_cmp_abs (&(y->left), &(y->right)) < 0) { + e = mpfr_inf_p (&(y->right)) ? mpfr_get_emax () + : mpfr_get_exp (&(y->right)); + } + else { + e = mpfr_inf_p (&(y->left)) ? mpfr_get_emax () + : mpfr_get_exp (&(y->left)); + } + e += 1; + /* resize fact in [0, 2^e] where e = 1 + max{exp(left), exp(right)} */ + mpfr_mul_2exp (fact, fact, e, MPFR_RNDN); + mpfr_set (m, &(y->left), MPFR_RNDN); + if (mpfr_inf_p (m)) { + mpfr_nextabove (m); + } + /* m may be outside y */ + mpfr_add (m, m, fact, MPFR_RNDN); + } + mpfr_clear (fact); + mpfr_clear (diam); + + /* Ensure that m belongs to y (if the precision is sufficient) */ + if (mpfr_cmp (m, &(y->left)) < 0) + mpfr_set (m, &(y->left), MPFR_RNDU); + + if (mpfr_cmp (&(y->right), m) < 0) + mpfr_set (m, &(y->right), MPFR_RNDD); +} diff --git a/src/out_str.c b/src/out_str.c new file mode 100644 index 0000000..5aaf63c --- /dev/null +++ b/src/out_str.c @@ -0,0 +1,42 @@ +/* out_str.c -- Output an interval representation in a stream. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi_io.h" +#include "mpfi-impl.h" + +size_t +mpfi_out_str (FILE *f, int base, size_t n_digits, mpfi_srcptr a) +{ + size_t res_left, res_right; + fprintf (f, "["); + res_left = mpfr_out_str (f, base, n_digits, &(a->left), MPFI_RNDD); + fprintf (f, ","); + res_right = mpfr_out_str (f, base, n_digits, &(a->right), MPFI_RNDU); + fprintf (f, "]"); + if ( (res_left > 0) && (res_right > 0) ) + return res_left + res_right + 3; /* 3 stands for "[", "," and "]" */ + else + return 0; +} diff --git a/src/predicates.c b/src/predicates.c new file mode 100644 index 0000000..03be082 --- /dev/null +++ b/src/predicates.c @@ -0,0 +1,46 @@ +/* predicates.c -- Predicates. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_nan_p (mpfi_srcptr a) +{ + return (mpfr_nan_p (&(a->left)) || mpfr_nan_p (&(a->right))); +} + +int +mpfi_inf_p (mpfi_srcptr a) +{ + return (mpfr_inf_p (&(a->left)) || mpfr_inf_p (&(a->right))) + && !MPFI_NAN_P (a); +} + +int +mpfi_bounded_p (mpfi_srcptr a) +{ + return (mpfr_number_p (&(a->left)) && mpfr_number_p (&(a->right)) + && !MPFI_NAN_P (a)); +} diff --git a/src/print_binary.c b/src/print_binary.c new file mode 100644 index 0000000..c4e621a --- /dev/null +++ b/src/print_binary.c @@ -0,0 +1,38 @@ +/* print_binary.c -- Print binary representation of an interval in stdout. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2018, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + + +#include "mpfi_io.h" +#include "mpfi-impl.h" + +void +mpfi_print_binary (mpfi_srcptr x) +{ + printf ("[ "); + mpfr_printf ("%Rf", &(x->left)); + printf (" , "); + mpfr_printf ("%Rf", &(x->right)); + printf (" ]"); +} diff --git a/src/put.c b/src/put.c new file mode 100644 index 0000000..45b897e --- /dev/null +++ b/src/put.c @@ -0,0 +1,59 @@ +/* put.c -- Convex hull of two intervals. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* The result is the first interval extended so */ +/* that it contains the second (scalar) one. */ +/* Also called "convex hull". */ + +int +mpfi_put (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left = 0; + int inexact_right=0; + int inexact=0; + + if ( MPFI_NAN_P (b) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if ( mpfr_cmp (&(a->left), &(b->left)) > 0 ) { + inexact_left = mpfr_set (&(a->left), &(b->left), MPFI_RNDD); + } + if (mpfr_cmp (&(a->right), &(b->right)) < 0) { + inexact_right = mpfr_set (&(a->right), &(b->right), MPFI_RNDU); + } + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/put_d.c b/src/put_d.c new file mode 100644 index 0000000..55355cd --- /dev/null +++ b/src/put_d.c @@ -0,0 +1,75 @@ +/* put_d.c -- Convex hull of an interval and a double. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_put_d (mpfi_ptr a, const double b) +{ + int inexact_left = 0; + int inexact_right = 0; + int inexact = 0; + /* MPFR erange flag is used to determine if b is NaN */ + int erange_old; + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + erange_old = mpfr_erangeflag_p (); + mpfr_clear_erangeflag (); + + if (mpfr_cmp_d (&(a->left), b) > 0 ) { + inexact_left = mpfr_set_d (&(a->left), b, MPFI_RNDD); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + } + else if (mpfr_cmp_d (&(a->right), b) < 0 ) { + inexact_right = mpfr_set_d (&(a->right), b, MPFI_RNDU); + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + } + else if (mpfr_cmp_d (&(a->left), b) == 0 && mpfr_erangeflag_p ()) { + /* d is NaN */ + mpfr_set_nan (&(a->left)); + } + + erange_old ? mpfr_set_erangeflag () : mpfr_clear_erangeflag (); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/put_fr.c b/src/put_fr.c new file mode 100644 index 0000000..630350e --- /dev/null +++ b/src/put_fr.c @@ -0,0 +1,66 @@ +/* put_fr.c -- Convex hull of an interval and a floating-point number. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_put_fr (mpfi_ptr a, mpfr_srcptr b) +{ + int inexact_left = 0; + int inexact_right = 0; + int inexact = 0; + + if ( mpfr_nan_p (b) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if ( mpfr_cmp (&(a->left), b) > 0 ) { + inexact_left = mpfr_set (&(a->left), b, MPFI_RNDD); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + } + else if (mpfr_cmp (&(a->right), b) < 0) { + inexact_right = mpfr_set (&(a->right), b, MPFI_RNDU); + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/put_q.c b/src/put_q.c new file mode 100644 index 0000000..7227b1a --- /dev/null +++ b/src/put_q.c @@ -0,0 +1,56 @@ +/* put_q.c -- Convex hull of an interval and a rational number. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_put_q (mpfi_ptr a, mpq_srcptr b) +{ + int inexact_left = 0; + int inexact_right = 0; + int inexact = 0; + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (mpfr_cmp_q (&(a->left), b) > 0 ) { + inexact_left = mpfr_set_q (&(a->left), b, MPFI_RNDD); + } + else if (mpfr_cmp_q (&(a->right), b) < 0 ) { + inexact_right = mpfr_set_q (&(a->right), b, MPFI_RNDU); + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/put_si.c b/src/put_si.c new file mode 100644 index 0000000..ceac99e --- /dev/null +++ b/src/put_si.c @@ -0,0 +1,55 @@ +/* put_si.c -- Convex hull of an interval and a signed long int. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_put_si (mpfi_ptr a, const long b) +{ + int inexact_left = 0; + int inexact_right = 0; + int inexact = 0; + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if ( mpfr_cmp_si (&(a->left), b) > 0 ) { + inexact_left = mpfr_set_si (&(a->left), b, MPFI_RNDD); + } + else if (mpfr_cmp_si (&(a->right), b) < 0) { + inexact_right = mpfr_set_si (&(a->right), b, MPFI_RNDU); + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + } + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/put_ui.c b/src/put_ui.c new file mode 100644 index 0000000..208f1d9 --- /dev/null +++ b/src/put_ui.c @@ -0,0 +1,55 @@ +/* put_ui.c -- Convex hull of an interval and an unsigned long int. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_put_ui (mpfi_ptr a, const unsigned long b) +{ + int inexact_left = 0; + int inexact_right = 0; + int inexact = 0; + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if ( mpfr_cmp_ui (&(a->left), b) > 0 ) { + inexact_left = mpfr_set_ui (&(a->left), b, MPFI_RNDD); + } + else if (mpfr_cmp_ui (&(a->right), b) < 0) { + inexact_right = mpfr_set_ui (&(a->right), b, MPFI_RNDU); + + if (b == 0) + /* zero right endpoint is always -0 */ + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/put_z.c b/src/put_z.c new file mode 100644 index 0000000..4d94caa --- /dev/null +++ b/src/put_z.c @@ -0,0 +1,55 @@ +/* put_z.c -- Convex hull of an interval and an integer. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_put_z (mpfi_ptr a, mpz_srcptr b) +{ + int inexact_left = 0; + int inexact_right = 0; + int inexact = 0; + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (mpfr_cmp_z (&(a->left), b) > 0 ) { + inexact_left = mpfr_set_z (&(a->left), b, MPFI_RNDD); + } + else if (mpfr_cmp_z (&(a->right), b) < 0 ) { + inexact_right = mpfr_set_z (&(a->right), b, MPFI_RNDU); + + if (mpz_cmp_ui (b, 0) == 0) + /* zero upper bound is -0 */ + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/q_div.c b/src/q_div.c new file mode 100644 index 0000000..0c601a6 --- /dev/null +++ b/src/q_div.c @@ -0,0 +1,74 @@ +/* q_div.c -- Divide a rational number by an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_q_div (mpfi_ptr a, mpq_srcptr b, mpfi_srcptr c) +{ + mpfi_t tmp; + int inexact_set, inexact_div, inexact=0; + + if (MPFI_NAN_P (c)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_HAS_ZERO (c)) { /* a = ]-oo, +oo [ */ + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + return inexact; + } + + if (mpq_sgn (b) == 0) { /* a = [-0, +0] */ + mpfi_set_ui (a, 0); + return inexact; + } + + mpfi_init2 (tmp, mpfi_get_prec (a)); + inexact_set = mpfi_set_q (tmp, b); + inexact_div = mpfi_div (a, tmp, c); + MPFI_CLEAR (tmp); + + if (MPFI_LEFT_IS_INEXACT (inexact_div) + || (inexact_set && !mpfr_inf_p (&a->left) && !mpfr_zero_p (&a->left))) { + /* the first condition MPFI_LEFT_IS_INEXACT (inexact_div) handles, among + others, overflow and underflow cases. + if a->left = infinity in non-overflow case, then a->left is the + quotient of b with an infinite endpoint of c, thus it is exact even if + tmp is not exact. + if a->left = 0 in non-underflow case, then either a->left is the + quotient of b with a zero endpoint of c, or b is null, thus a->left is + exact. */ + inexact += 1; + } + if (MPFI_RIGHT_IS_INEXACT (inexact_div) + ||(inexact_set && !mpfr_inf_p (&a->right) && !mpfr_zero_p (&a->right))){ + inexact += 2; + } + + return inexact; +} diff --git a/src/q_sub.c b/src/q_sub.c new file mode 100644 index 0000000..98e0d6a --- /dev/null +++ b/src/q_sub.c @@ -0,0 +1,84 @@ +/* q_sub.c -- Subtract an interval by an rational number. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2011, 2012, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" +#include "mpfi_config.h" + +#ifndef HAVE_MPFR_Q_SUB +static int +mpfr_q_sub (mpfr_ptr x, mpq_srcptr z, mpfr_srcptr y, mpfr_rnd_t rnd) +{ + /* mpfr_q_sub does not exist (at least up to version 3.0) */ + + /* Here we use the fact that x and y do not point to the same variable */ + int inex; + + inex = mpfr_sub_q (x, y, z, rnd == MPFI_RNDD ? MPFI_RNDU : MPFI_RNDD); + mpfr_neg (x, x, MPFI_RNDD); + + return -inex; +} +#endif /* HAVE_MPFR_Q_SUB */ + +int +mpfi_q_sub (mpfi_ptr a, mpq_srcptr b, mpfi_srcptr c) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact = 0; + + if (MPFI_IS_ZERO (c)) { + return mpfi_set_q (a, b); + } + else if (!mpq_sgn(b)) { + return mpfi_neg (a, c); + } + else { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_q_sub (tmp, b, &(c->right), MPFI_RNDD); + inexact_right = mpfr_q_sub (&(a->right), b, &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } + +} + diff --git a/src/quadrant.c b/src/quadrant.c new file mode 100644 index 0000000..3d1f186 --- /dev/null +++ b/src/quadrant.c @@ -0,0 +1,71 @@ +/* quadrant.c -- Internal function for trigonometric functions. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* returns in quad the integer part of the division of x by Pi/2 */ +/* the result is exact */ +/* the returned value is the precision required to perform the division */ +mpfr_prec_t +mpfi_quadrant (mpz_ptr quad, mpfr_srcptr x) +{ +/* Assumption: x is neither a NaN nor an Infinite */ + int ok = 0; + mpfr_prec_t prec; + mpfi_t two_over_pi, tmp; + + prec = mpfr_get_prec (x); + + if (MPFR_IS_ZERO(x)) { + mpz_set_ui(quad, 0); + } + else { + mpfi_init2 (two_over_pi, prec); + mpfi_init2 (tmp, prec); + + do { + mpfi_const_pi (two_over_pi); + mpfi_ui_div (two_over_pi, 2, two_over_pi); + + mpfi_mul_fr (tmp, two_over_pi, x); + mpfr_floor (&(tmp->left), &(tmp->left)); + mpfr_floor (&(tmp->right), &(tmp->right)); + + ok = mpfr_cmp (&(tmp->left), &(tmp->right)); + if (ok != 0) { + prec += BITS_PER_MP_LIMB; + mpfi_set_prec (two_over_pi, prec); + mpfi_set_prec (tmp, prec); + } + } while (ok != 0); + + mpfr_get_z (quad, &(tmp->left), MPFR_RNDN); /* exact */ + + mpfi_clear (two_over_pi); + mpfi_clear (tmp); + } + + return prec; +} diff --git a/src/revert_if_needed.c b/src/revert_if_needed.c new file mode 100644 index 0000000..f9133bf --- /dev/null +++ b/src/revert_if_needed.c @@ -0,0 +1,45 @@ +/* revert_if_needed.c -- Helper function : swap endpoints so that + left <= right. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* ensures that the result is [a,b] with a<=b */ +/* should be useless but bugs are not excluded... */ +/* Returns 1 if endpoints have been exchanged */ + +int +mpfi_revert_if_needed (mpfi_ptr a) +{ + if ( MPFI_NAN_P (a) ) + return 0; + + if ( mpfr_cmp (&(a->right), &(a->left)) < 0 ) { + mpfr_swap (&(a->left), &(a->right)); + return 1; + } + else + return 0; +} diff --git a/src/round_prec.c b/src/round_prec.c new file mode 100644 index 0000000..ebf28df --- /dev/null +++ b/src/round_prec.c @@ -0,0 +1,46 @@ +/* round_prec.c -- Change interval's precision with rounding. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* The precision of the interval x is set to prec, */ +/* the previous value of x is kept. */ +int +mpfi_round_prec (mpfi_ptr x, mpfr_prec_t prec) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_round_prec (&(x->left), MPFI_RNDD, prec); + inexact_right = mpfr_round_prec (&(x->right), MPFI_RNDU, prec); + + if ( MPFI_NAN_P(x) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + return inexact; +} diff --git a/src/sec.c b/src/sec.c new file mode 100644 index 0000000..eeb7f55 --- /dev/null +++ b/src/sec.c @@ -0,0 +1,136 @@ +/* sec.c -- Secant of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sec (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact = 0; + mpfr_prec_t prec, prec_left, prec_right; + mpfr_t tmp; + mpz_t z_left, z_right; + mpz_t z, zmod4; + int ql_mod4, qr_mod4; + + if (MPFI_NAN_P (b)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_INF_P (b)) { + /* the two endpoints are the same infinite */ + if ( mpfr_cmp (&(b->left), &(b->right)) == 0) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + return 0; + } + + mpz_init (z_left); + mpz_init (z_right); + mpz_init (z); + + prec_left = mpfi_quadrant (z_left, &(b->left)); + prec_right = mpfi_quadrant (z_right, &(b->right)); + + /* if there is at least one period in b or if b contains a Pi/2 + k*Pi, */ + /* then a = ]-oo, +oo[ */ + mpz_sub (z, z_right, z_left); + if ( (mpz_cmp_ui (z, 2) >= 0) || + (mpz_even_p (z_left) && mpz_odd_p (z_right)) ) { + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + inexact = 0; + } + else { + /* computing precision = maximal precision required to determine the */ + /* relative position of the endpoints of b and of integer multiples of Pi / 2 */ + prec = mpfi_get_prec (a); + if (prec_left > prec) prec = prec_left; + if (prec_right > prec) prec = prec_right; + + mpz_init (zmod4); + + /* qr_mod4 gives the quadrant where the right endpoint of b is */ + /* qr_mod4 = floor (2 b->right / pi) mod 4 */ + mpz_mod_ui (zmod4, z_right, 4); + qr_mod4 = mpz_get_ui (zmod4); + + /* z_left gives the quadrant where the left endpoint of b is */ + /* z_left = floor (2 b->left / pi) mod 4 */ + mpz_mod_ui (zmod4, z_left, 4); + ql_mod4 = mpz_get_ui (zmod4); + + + if (qr_mod4 == ql_mod4) { + if (qr_mod4 == 0 || qr_mod4 == 1) { + /* sec is increasing on b */ + inexact_left = mpfr_sec (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_sec (&(a->right), &(b->right), MPFI_RNDU); + } + else { + /* sec is decreasing on b */ + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_sec (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_sec (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + } + } + else if (ql_mod4 == 1) { + mpz_add (z, z_left, z_right); + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->right), &(b->left), prec) >= 0) + inexact_left = mpfr_sec (&(a->left), &(b->left), MPFI_RNDD); + else + inexact_left = mpfr_sec (&(a->left), &(b->right), MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), -1, MPFI_RNDU); + } + else { + mpz_add (z, z_left, z_right); + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->right), &(b->left), prec) >= 0) + inexact_right = mpfr_sec (&(a->right), &(b->left), MPFI_RNDU); + else + inexact_right = mpfr_sec (&(a->right), &(b->right), MPFI_RNDU); + inexact_left = mpfr_set_ui (&(a->left), +1, MPFI_RNDD); + } + + if (inexact_left) inexact = 1; + if (inexact_right) inexact += 2; + + mpz_clear (zmod4); + } + + mpz_clear (z_left); + mpz_clear (z_right); + + return inexact; +} diff --git a/src/sech.c b/src/sech.c new file mode 100644 index 0000000..5d1d799 --- /dev/null +++ b/src/sech.c @@ -0,0 +1,73 @@ +/* sech.c -- Hyperbolic secant of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sech (mpfi_ptr a, mpfi_srcptr b) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact=0; + + if ( MPFI_NAN_P (b) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if ( MPFI_IS_NONNEG (b) ) { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_sech (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_sech (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + } + else if ( MPFI_HAS_ZERO (b) ) { + mpfr_init2 (tmp, mpfr_get_prec (&(b->left))); + mpfr_neg (tmp, &(b->left), MPFI_RNDD); /* exact */ + if (mpfr_cmp (tmp, &(b->right)) > 0) + inexact_left = mpfr_sech (&(a->left), tmp, MPFI_RNDD); + else + inexact_left = mpfr_sech (&(a->left), &(b->right), MPFI_RNDD); + inexact_right = mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + mpfr_clear (tmp); + } + else { /* b <= 0 */ + inexact_left = mpfr_sech (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_sech (&(a->right), &(b->right), MPFI_RNDU); + } + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/set.c b/src/set.c new file mode 100644 index 0000000..7439149 --- /dev/null +++ b/src/set.c @@ -0,0 +1,65 @@ +/* set.c -- Assignments between intervals. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_set (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + inexact_left = mpfr_set (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_set (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +/* Combined initialization and assignment */ + +int +mpfi_init_set (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_init_set (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_init_set (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/set_d.c b/src/set_d.c new file mode 100644 index 0000000..178aa6d --- /dev/null +++ b/src/set_d.c @@ -0,0 +1,78 @@ +/* set_d.c -- Assign a floating-point double to an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_set_d (mpfi_ptr a, const double b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_set_d (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set_d (&(a->right), b, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (b == 0.0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +/* Combined initialization and assignment */ + +int +mpfi_init_set_d (mpfi_ptr a, const double b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_init_set_d (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_init_set_d (&(a->right), b, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (b == 0.0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/set_flt.c b/src/set_flt.c new file mode 100644 index 0000000..c8fe03b --- /dev/null +++ b/src/set_flt.c @@ -0,0 +1,79 @@ +/* set_flt.c -- Assign a floating-point single precision (binary32) to an interval. + +Copyright 2018 + AriC project, Inria Rhone-Alpes, France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_set_flt (mpfi_ptr a, const float b) +{ + int inexact_left, inexact_right, inexact=0; + + /* we convert f to double precision and use mpfr_set_d; + NaN and infinities should be preserved, and all single precision + numbers are exactly representable in the double format, thus the + conversion is always exact */ + inexact_left = mpfr_set_d (&(a->left), (double) b, MPFI_RNDD); + inexact_right = mpfr_set_d (&(a->right), (double) b, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (b == 0.0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +/* Combined initialization and assignment */ + +int +mpfi_init_set_flt (mpfi_ptr a, const float b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_init_set_d (&(a->left), (double) b, MPFI_RNDD); + inexact_right = mpfr_init_set_d (&(a->right), (double) b, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (b == 0.0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/set_fr.c b/src/set_fr.c new file mode 100644 index 0000000..6597e9c --- /dev/null +++ b/src/set_fr.c @@ -0,0 +1,78 @@ +/* set_fr.c -- Assign a floating-point number to an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_set_fr (mpfi_ptr a, mpfr_srcptr b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_set (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set (&(a->right), b, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (mpfr_zero_p (b)) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +/* Combined initialization and assignment */ + +int +mpfi_init_set_fr (mpfi_ptr a, mpfr_srcptr b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_init_set (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_init_set (&(a->right), b, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (mpfr_zero_p (b)) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/set_ld.c b/src/set_ld.c new file mode 100644 index 0000000..fd8f259 --- /dev/null +++ b/src/set_ld.c @@ -0,0 +1,75 @@ +/* set_ld.c -- Assign a floating-point long double to an interval. + +Copyright 2018 + AriC project, Inria Grenoble - Rhone-Alpes, France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_set_ld (mpfi_ptr a, const long double b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_set_ld (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set_ld (&(a->right), b, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (b == 0.0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +/* Combined initialization and assignment */ + +int +mpfi_init_set_ld (mpfi_ptr a, const long double b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_init_set_ld (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_init_set_ld (&(a->right), b, MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (b == 0.0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/set_prec.c b/src/set_prec.c new file mode 100644 index 0000000..382e534 --- /dev/null +++ b/src/set_prec.c @@ -0,0 +1,35 @@ +/* set_prec.c -- Set the interval's precision. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* The precision of the interval x is set to prec, */ +/* the previous value of x is lost. */ +void +mpfi_set_prec (mpfi_ptr x,mpfr_prec_t prec) +{ + mpfr_set_prec (&(x->right),prec); + mpfr_set_prec (&(x->left),prec); +} diff --git a/src/set_q.c b/src/set_q.c new file mode 100644 index 0000000..1f01363 --- /dev/null +++ b/src/set_q.c @@ -0,0 +1,70 @@ +/* set_q.c -- Assign a rational number to an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_set_q (mpfi_ptr a, mpq_srcptr b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_set_q (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set_q (&(a->right), b, MPFI_RNDU); + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +/* Combined initialization and assignment */ + +int +mpfi_init_set_q (mpfi_ptr a, mpq_srcptr b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_init_set_q (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_init_set_q (&(a->right), b, MPFI_RNDU); + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/set_si.c b/src/set_si.c new file mode 100644 index 0000000..e51dbeb --- /dev/null +++ b/src/set_si.c @@ -0,0 +1,72 @@ +/* set_si.c -- Assign long int to an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_set_si (mpfi_ptr a, const long b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_set_si (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), b, MPFI_RNDU); + + if (b == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +/* Combined initialization and assignment */ + +int +mpfi_init_set_si (mpfi_ptr a, const long b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_init_set_si (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_init_set_si (&(a->right), b, MPFI_RNDU); + + if (b == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/set_sj.c b/src/set_sj.c new file mode 100644 index 0000000..8f7373d --- /dev/null +++ b/src/set_sj.c @@ -0,0 +1,99 @@ +/* mpfi_set_sj -- set a MPFI interval from a huge machine signed integer + +Copyright 2017-2018 Free Software Foundation, Inc. +Contributed by the AriC project, INRIA. + +This file is part of the GNU MPFR Library. + +The GNU MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MPFI Library; see the file COPYING.LESSER. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "mpfi-intmax.h" +#include "mpfi-impl.h" + +#ifdef _MPFR_H_HAVE_INTMAX_T + +int +mpfi_set_sj (mpfi_t a, intmax_t b) +{ +int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_set_sj_2exp (&(a->left), b, 0, MPFI_RNDD); + inexact_right = mpfr_set_sj_2exp (&(a->right), b, 0, MPFI_RNDU); + + if (b == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + + +/* Combined initialization and assignment */ + +int +mpfi_init_set_sj (mpfi_ptr a, const intmax_t b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_init_set_sj (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_init_set_sj (&(a->right), b, MPFI_RNDU); + + if (b == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +int +mpfi_set_sj_2exp (mpfi_t x, intmax_t b, intmax_t e) +{ +int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_set_sj_2exp (&(a->left), b, e, MPFI_RNDD); + inexact_right = mpfr_set_sj_2exp (&(a->right), b, e, MPFI_RNDU); + + if (b == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +#endif diff --git a/src/set_str.c b/src/set_str.c new file mode 100644 index 0000000..5bd2ee6 --- /dev/null +++ b/src/set_str.c @@ -0,0 +1,126 @@ +/* set_str.c -- Set an interval to the value of a string. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi_io.h" +#include "mpfi-impl.h" + +int +mpfi_set_str (mpfi_ptr x, const char *s, int base) +{ + const char *cur; + char *end; + + cur = s; + /* read the blanks */ + while (*cur && MPFI_ISSPACE (*cur)) ++cur; + if (*cur == '\0') { + /* Error: blank string */ + return 1; + } + + /* Now *cur is the first non blank character */ + if (*cur == '[') { + ++cur; + + /* read the blanks between '[' and the number itself */ + while (*cur && MPFI_ISSPACE (*cur)) ++cur; + if (*cur == '\0') { + /* Error: no number in string */ + return 1; + } + + mpfr_strtofr (&(x->left), cur, &end, base, MPFI_RNDD); + if (end == cur) { + /* Error: no number in string */ + return 1; + } + cur = end; + + /* Read (possibly) blank characters between the first number and the comma */ + while (*cur && MPFI_ISSPACE (*cur) ) ++cur; + if (*cur == '\0') { + /* Error: only one number in string */ + return 1; + } + + if (*cur != ',') { + /* Error: missing comma */ + return 1; + } + ++cur; + + /* From now on, we are reading the second number */ + + /* read (possibly) blank characters between the comma and the 2nd number */ + while (*cur && MPFI_ISSPACE (*cur)) ++cur; + if (*cur == '\0') { + /* Error: only one number in string */ + return 1; + } + + /* Now *cur is the first character of the 2nd number */ + mpfr_strtofr (&(x->right), cur, &end, base, MPFI_RNDU); + if (end == cur) { + /* Error: only one number in string */ + return 1; + } + cur = end; + + /* Read (possibly) blank characters between the 2nd number and */ + /* closing square bracket */ + while (*cur && MPFI_ISSPACE (*cur)) ++cur; + if (*cur == '\0') { + /* Error: missing closing square bracket */ + return 1; + } + + if (*cur != ']') { + /* Missing closing square bracket */ + return 1; + } + + /* Note that the string may contain any character after the */ + /* closing square bracket: they will be ignored */ + } + else { + /* Only one number to store as an interval */ + /* s[i] is the first non blank character and is not an */ + /* opening square bracket */ + + /* Note that the whole string must be a valid number */ + if (mpfr_set_str (&(x->left), cur, base, MPFI_RNDD)) + return 1; + mpfr_set_str (&(x->right), cur, base, MPFI_RNDU); + } + + return 0; +} + +int +mpfi_init_set_str (mpfi_ptr x, const char *s, int base) +{ + mpfi_init (x); + return (mpfi_set_str (x, s, base)); +} diff --git a/src/set_ui.c b/src/set_ui.c new file mode 100644 index 0000000..892424a --- /dev/null +++ b/src/set_ui.c @@ -0,0 +1,70 @@ +/* set_ui.c -- Assign an unsigned long int to an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_set_ui (mpfi_ptr a, const unsigned long b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_set_ui (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set_ui (&(a->right), b, MPFI_RNDU); + + if (b == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +/* Combined initialization and assignment */ + +int +mpfi_init_set_ui (mpfi_ptr a, const unsigned long b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_init_set_ui (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_init_set_ui (&(a->right), b, MPFI_RNDU); + + if (b == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/set_uj.c b/src/set_uj.c new file mode 100644 index 0000000..dabc1e7 --- /dev/null +++ b/src/set_uj.c @@ -0,0 +1,99 @@ +/* mpfi_set_uj -- set a MPFI interval from a huge machine unsigned integer + +Copyright 2017-2018 Free Software Foundation, Inc. +Contributed by the AriC project, INRIA. + +This file is part of the GNU MPFR Library. + +The GNU MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MPFI Library; see the file COPYING.LESSER. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "mpfi-intmax.h" +#include "mpfi-impl.h" + +#ifdef _MPFR_H_HAVE_INTMAX_T + +int +mpfi_set_uj (mpfi_t a, uintmax_t b) +{ +int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_set_uj_2exp (&(a->left), b, 0, MPFI_RNDD); + inexact_right = mpfr_set_uj_2exp (&(a->right), b, 0, MPFI_RNDU); + + if (b == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + + +/* Combined initialization and assignment */ + +int +mpfi_init_set_uj (mpfi_ptr a, const uintmax_t b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_init_set_uj (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_init_set_uj (&(a->right), b, MPFI_RNDU); + + if (b == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +int +mpfi_set_uj_2exp (mpfi_t x, uintmax_t b, intmax_t e) +{ +int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_set_uj_2exp (&(a->left), b, e, MPFI_RNDD); + inexact_right = mpfr_set_uj_2exp (&(a->right), b, e, MPFI_RNDU); + + if (b == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +#endif diff --git a/src/set_z.c b/src/set_z.c new file mode 100644 index 0000000..22c4ebd --- /dev/null +++ b/src/set_z.c @@ -0,0 +1,72 @@ +/* set_z.c -- Assign an integer to an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_set_z (mpfi_ptr a, mpz_srcptr b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_set_z (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_set_z (&(a->right), b, MPFI_RNDU); + + if (mpz_cmp_ui (b, 0) == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} + +/* Combined initialization and assignment */ + +int +mpfi_init_set_z (mpfi_ptr a, mpz_srcptr b) +{ + int inexact_left, inexact_right, inexact = 0; + + inexact_left = mpfr_init_set_z (&(a->left), b, MPFI_RNDD); + inexact_right = mpfr_init_set_z (&(a->right), b, MPFI_RNDU); + + if (mpz_cmp_ui (b, 0) == 0) { + /* fix signed zero so as to return [+0, -0] */ + mpfr_setsign (&(a->left), &(a->left), 0, MPFI_RNDU); + mpfr_setsign (&(a->right), &(a->right), 1, MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/si_div.c b/src/si_div.c new file mode 100644 index 0000000..0871148 --- /dev/null +++ b/src/si_div.c @@ -0,0 +1,74 @@ +/* si_div.c -- Divide a signed long int by an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_si_div (mpfi_ptr a, const long b, mpfi_srcptr c) +{ + mpfr_t tmp; + int inexact_left = 0, inexact_right = 0, inexact = 0; + + if (MPFI_NAN_P (c)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_HAS_ZERO (c)) { /* a = ]-oo, +oo [ */ + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + } + else if (b == 0) { + mpfi_set_ui (a, 0); + } + else if (b > 0) { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_si_div (tmp, b, &(c->right), MPFI_RNDD); + inexact_right = mpfr_si_div (&(a->right), b, &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); + mpfr_clear (tmp); + } + else { + inexact_left = mpfr_si_div (&(a->left), b, &(c->left), MPFI_RNDD); + inexact_right = mpfr_si_div (&(a->right), b, &(c->right), MPFI_RNDU); + } + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/si_sub.c b/src/si_sub.c new file mode 100644 index 0000000..a9592f6 --- /dev/null +++ b/src/si_sub.c @@ -0,0 +1,66 @@ +/* si_sub.c -- Subtract an interval from a signed long int. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_si_sub (mpfi_ptr a, const long b, mpfi_srcptr c) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact = 0; + + if (MPFI_IS_ZERO (c)) { + return mpfi_set_si (a, b); + } + else if (b==0) { + return mpfi_neg (a, c); + } + else { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_si_sub (tmp, b, &(c->right), MPFI_RNDD); + inexact_right = mpfr_si_sub (&(a->right), b, &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } + +} diff --git a/src/sign.c b/src/sign.c new file mode 100644 index 0000000..bbf6a87 --- /dev/null +++ b/src/sign.c @@ -0,0 +1,101 @@ +/* sign.c -- Default testing sign functions. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Customizable sign testing functions */ + +int (*mpfi_is_pos) (mpfi_srcptr) = mpfi_is_pos_default; +int (*mpfi_is_strictly_pos) (mpfi_srcptr) = mpfi_is_strictly_pos_default; +int (*mpfi_is_nonneg) (mpfi_srcptr) = mpfi_is_nonneg_default; +int (*mpfi_is_neg) (mpfi_srcptr) = mpfi_is_neg_default; +int (*mpfi_is_strictly_neg) (mpfi_srcptr) = mpfi_is_strictly_neg_default; +int (*mpfi_is_nonpos) (mpfi_srcptr) = mpfi_is_nonpos_default; +int (*mpfi_is_zero) (mpfi_srcptr) = mpfi_is_zero_default; + + +int +mpfi_is_pos_default (mpfi_srcptr a) +{ + if ( mpfi_nan_p (a) ) + return 0; + + return (MPFI_IS_POS (a)); +} + +int +mpfi_is_strictly_pos_default (mpfi_srcptr a) +{ + if ( mpfi_nan_p (a) ) + return 0; + + return (MPFI_IS_STRICTLY_POS (a)); +} + +int +mpfi_is_nonneg_default (mpfi_srcptr a) +{ + if ( mpfi_nan_p (a) ) + return 0; + + return (MPFI_IS_NONNEG (a)); +} + +int +mpfi_is_neg_default (mpfi_srcptr a) +{ + if ( mpfi_nan_p (a) ) + return 0; + + return (MPFI_IS_NEG (a)); +} + +int +mpfi_is_strictly_neg_default (mpfi_srcptr a) +{ + if ( mpfi_nan_p (a) ) + return 0; + + return (MPFI_IS_STRICTLY_NEG (a)); +} + +int +mpfi_is_nonpos_default (mpfi_srcptr a) +{ + if ( mpfi_nan_p (a) ) + return 0; + + return (MPFI_IS_NONPOS (a)); +} + +int +mpfi_is_zero_default (mpfi_srcptr a) +{ + if ( mpfi_nan_p (a) ) + return 0; + + return((mpfr_sgn (&(a->right)) == 0) && + (mpfr_sgn (&(a->left)) == 0)); +} diff --git a/src/sin.c b/src/sin.c new file mode 100644 index 0000000..dbf2205 --- /dev/null +++ b/src/sin.c @@ -0,0 +1,209 @@ +/* sin.c -- Sine of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sin (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact = 0; + mpfr_prec_t prec, prec_left, prec_right; + mpfr_t tmp; + mpz_t z, zmod4; + mpz_t quad_left, quad_right; + int ql_mod4, qr_mod4; + + if (MPFI_NAN_P (b)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_INF_P (b)) { + /* the two endpoints are the same infinite */ + if ( mpfr_cmp (&(b->left), &(b->right)) == 0) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + mpfr_set_si (&(a->left), -1, MPFI_RNDD); + mpfr_set_si (&(a->right), 1, MPFI_RNDU); + return 0; + } + + mpz_init (quad_left); + mpz_init (quad_right); + mpz_init (z); + /* quad_left gives the quadrant where the left endpoint of b is */ + /* quad_left = floor (2 b->left / pi) */ + /* idem for quad_right and b->right */ + prec_left = mpfi_quadrant (quad_left, &(b->left)); + prec_right = mpfi_quadrant (quad_right, &(b->right)); + + + /* if there is at least one period in b, then a = [-1, 1] */ + mpz_sub (z, quad_right, quad_left); + if (mpz_cmp_ui (z, 4) >= 0) { + mpfr_set_si (&(a->left), -1, MPFI_RNDD); + mpfr_set_si (&(a->right), 1, MPFI_RNDU); + inexact = 0; + } + else { + /* there is less than one period in b */ + /* let us discuss according to the position (quadrant) of the endpoints of b */ + + /* computing precision = maximal precision required to determine the */ + /* relative position of the endpoints of b and of integer multiples of Pi / 2 */ + prec = mpfi_get_prec (a); + if (prec_left > prec) prec = prec_left; + if (prec_right > prec) prec = prec_right; + + mpz_add (z, quad_left, quad_right); + /* z = quad_right + quad_left */ + + mpz_init (zmod4); + + /* qr_mod4 gives the quadrant where the right endpoint of b is */ + /* qr_mod4 = floor (2 b->right / pi) mod 4 */ + mpz_mod_ui (zmod4, quad_right, 4); + qr_mod4 = mpz_get_ui (zmod4); + + /* quad_left gives the quadrant where the left endpoint of b is */ + /* quad_left = floor (2 b->left / pi) mod 4 */ + mpz_mod_ui (zmod4, quad_left, 4); + ql_mod4 = mpz_get_ui (zmod4); + + + switch (qr_mod4) { + case 0: + switch (ql_mod4) { + case 0: + case 3: + inexact_left = mpfr_sin (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_sin (&(a->right), &(b->right), MPFI_RNDU); + break; + case 1: + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->left), &(b->right), prec) >= 0) + inexact_right = mpfr_sin (&(a->right), &(b->left), MPFI_RNDU); + else + inexact_right = mpfr_sin (&(a->right), &(b->right), MPFI_RNDU); + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + break; + case 2: + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + inexact_right = mpfr_sin (&(a->right), &(b->right), MPFI_RNDU); + break; + } + break; + case 1: + switch (ql_mod4) { + case 0: + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->right), &(b->left), prec) >= 0) + inexact_left = mpfr_sin (&(a->left), &(b->left), MPFI_RNDD); + else + inexact_left = mpfr_sin (&(a->left), &(b->right), MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + case 1: + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_sin (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_sin (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + break; + case 2: + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + case 3: + inexact_left = mpfr_sin (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + } + break; + case 2: + switch (ql_mod4) { + case 0: + inexact_left = mpfr_sin (&(a->left), &(b->right), MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + case 1: + case 2: + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_sin (tmp, &(b->right), MPFI_RNDD); + inexact_right = mpfr_sin (&(a->right), &(b->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + break; + case 3: + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->left), &(b->right), prec) >= 0) + inexact_left = mpfr_sin (&(a->left), &(b->left), MPFI_RNDD); + else + inexact_left = mpfr_sin (&(a->left), &(b->right), MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + } + break; + case 3: + switch (ql_mod4) { + case 0: + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + inexact_right = mpfr_set_si (&(a->right), 1, MPFI_RNDU); + break; + case 1: + inexact_right = mpfr_sin (&(a->right), &(b->left), MPFI_RNDU); + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + break; + case 2: + mpz_add_ui (z, z, 1); + if (mpfi_cmp_sym_pi (z, &(b->right), &(b->left), prec) >= 0) + inexact_right = mpfr_sin (&(a->right), &(b->left), MPFI_RNDU); + else + inexact_right = mpfr_sin (&(a->right), &(b->right), MPFI_RNDU); + inexact_left = mpfr_set_si (&(a->left), -1, MPFI_RNDD); + break; + case 3: + inexact_left = mpfr_sin (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_sin (&(a->right), &(b->right), MPFI_RNDU); + break; + } + break; + } + + if (inexact_left) inexact = 1; + if (inexact_right) inexact += 2; + + mpz_clear (zmod4); + } + + mpz_clear (quad_left); + mpz_clear (quad_right); + mpz_clear (z); + + return inexact; +} diff --git a/src/sinh.c b/src/sinh.c new file mode 100644 index 0000000..398543c --- /dev/null +++ b/src/sinh.c @@ -0,0 +1,45 @@ +/* sinh.c -- Hyperbolic sine of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sinh (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_sinh (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_sinh (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/sqr.c b/src/sqr.c new file mode 100644 index 0000000..328b1ca --- /dev/null +++ b/src/sqr.c @@ -0,0 +1,79 @@ +/* sqr.c -- Square of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sqr (mpfi_ptr a, mpfi_srcptr u) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact=0; + + if ( MPFI_NAN_P (u) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + if (mpfr_sgn (&(u->left)) >= 0) { + /* u nonnegative */ + inexact_left = mpfr_mul (&(a->left), &(u->left), &(u->left), MPFI_RNDD); + inexact_right = mpfr_mul (&(a->right), &(u->right), &(u->right), MPFI_RNDU); + } + else { + if (mpfr_sgn (&(u->right)) <= 0) { + /* u non-positive -> beware the case where a = u */ + mpfr_init2 (tmp, mpfr_get_prec (&(a->right))); + inexact_right = mpfr_mul (tmp, &(u->left), &(u->left), MPFI_RNDU); + inexact_left = mpfr_mul (&(a->left), &(u->right), &(u->right), MPFI_RNDD); + mpfr_set (&(a->right), tmp, MPFI_RNDU); /* exact */ + mpfr_clear (tmp); + } + else { + /* inf = 0, sup = max of the squares of the endpoints of u */ + if (mpfr_cmp_abs (&(u->left), &(u->right)) <= 0) { + inexact_right = + mpfr_mul (&(a->right), &(u->right), &(u->right), MPFI_RNDU); + } + else { + inexact_right = + mpfr_mul (&(a->right), &(u->left), &(u->left), MPFI_RNDU); + } + inexact_left = mpfr_set_si (&(a->left), (long)0, MPFI_RNDD); + } + } + + /* The NaN case has already been handled */ + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + return inexact; +} diff --git a/src/sqrt.c b/src/sqrt.c new file mode 100644 index 0000000..fbfac43 --- /dev/null +++ b/src/sqrt.c @@ -0,0 +1,47 @@ +/* sqrt.c -- Square root of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sqrt (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + /* if b is (partially) negative, the left bound will be a NaN */ + /* it is handled by MPFR */ + inexact_left = mpfr_sqrt (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_sqrt (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/sub.c b/src/sub.c new file mode 100644 index 0000000..108b672 --- /dev/null +++ b/src/sub.c @@ -0,0 +1,65 @@ +/* sub.c -- Subtract two intervals. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sub (mpfi_ptr a, mpfi_srcptr b, mpfi_srcptr c) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact = 0; + + if (MPFI_IS_ZERO (c)) { + return mpfi_set (a, b); + } + else if (MPFI_IS_ZERO (b)) { + return mpfi_neg (a, c); + } + else { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_sub (tmp, &(b->left), &(c->right), MPFI_RNDD); + inexact_right = mpfr_sub (&(a->right), &(b->right), &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } +} diff --git a/src/sub_d.c b/src/sub_d.c new file mode 100644 index 0000000..f969e4d --- /dev/null +++ b/src/sub_d.c @@ -0,0 +1,62 @@ +/* sub_d.c -- Subtract a double from an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sub_d (mpfi_ptr a, mpfi_srcptr b, const double c) +{ + int inexact_left, inexact_right, inexact = 0; + + if (c==0.0) { + return mpfi_set (a, b); + } + else if (MPFI_IS_ZERO (b)) { + return mpfi_set_d (a, -c); + } + else { + inexact_left = mpfr_sub_d (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_sub_d (&(a->right), &(b->right), c, MPFI_RNDU); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } + +} diff --git a/src/sub_fr.c b/src/sub_fr.c new file mode 100644 index 0000000..5a7a78b --- /dev/null +++ b/src/sub_fr.c @@ -0,0 +1,63 @@ +/* sub_fr.c -- Subtract a floating-point number from an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2011 + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sub_fr (mpfi_ptr a, mpfi_srcptr b, mpfr_srcptr c) +{ + mpfr_t tmp; + int inexact_left, inexact_right, inexact = 0; + + if (MPFR_IS_ZERO (c)) { + return mpfi_set (a, b); + } + else { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_sub (tmp, &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_sub (&(a->right), &(b->right), c, MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } + +} diff --git a/src/sub_q.c b/src/sub_q.c new file mode 100644 index 0000000..def0de6 --- /dev/null +++ b/src/sub_q.c @@ -0,0 +1,63 @@ +/* sub_q.c -- Subtract a rational number from an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sub_q (mpfi_ptr a, mpfi_srcptr b, mpq_srcptr c) +{ + int inexact_left, inexact_right, inexact = 0; + + if (!mpq_sgn (c)) { + return mpfi_set (a, b); + } + else if (MPFI_IS_ZERO (b)) { + inexact = mpfi_set_q(a, c); + mpfi_neg (a, a); /* exact */ + return inexact; + } + else { + inexact_left = mpfr_sub_q (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_sub_q (&(a->right), &(b->right), c, MPFI_RNDU); + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } + +} diff --git a/src/sub_si.c b/src/sub_si.c new file mode 100644 index 0000000..cab102b --- /dev/null +++ b/src/sub_si.c @@ -0,0 +1,63 @@ +/* sub_si.c -- Subtract a signed long int from an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sub_si (mpfi_ptr a, mpfi_srcptr b, const long c) +{ + int inexact_left, inexact_right, inexact = 0; + + if (c==0) { + return mpfi_set (a, b); + } + else if (MPFI_IS_ZERO (b)) { + return mpfi_set_si(a, -c); + } + else { + inexact_left = mpfr_sub_si (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_sub_si (&(a->right), &(b->right), c, MPFI_RNDU); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } + +} + diff --git a/src/sub_ui.c b/src/sub_ui.c new file mode 100644 index 0000000..f06de91 --- /dev/null +++ b/src/sub_ui.c @@ -0,0 +1,66 @@ +/* sub_ui.c -- Subtract an unsigned long int from an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sub_ui (mpfi_ptr a, mpfi_srcptr b, const unsigned long c) +{ + int inexact_left, inexact_right, inexact = 0; + + if (c==0) { + return mpfi_set (a, b); + } + else if (MPFI_IS_ZERO (b)) { + inexact = mpfi_set_ui(a, c); + mpfi_neg (a, a); /* exact */ + if (inexact == 1) inexact = 2; + else if (inexact == 2) inexact = 1; + return inexact; + } + else { + inexact_left = mpfr_sub_ui (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_sub_ui (&(a->right), &(b->right), c, MPFI_RNDU); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } + +} diff --git a/src/sub_z.c b/src/sub_z.c new file mode 100644 index 0000000..4a852b0 --- /dev/null +++ b/src/sub_z.c @@ -0,0 +1,67 @@ +/* sub_z.c -- Subtract an integer from an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_sub_z (mpfi_ptr a, mpfi_srcptr b, mpz_srcptr c) +{ + int inexact_left, inexact_right, inexact = 0; + + if (!mpz_sgn(c)) { + return mpfi_set (a, b); + } + else if (MPFI_IS_ZERO (b)) { + inexact = mpfi_set_z(a, c); + mpfi_neg (a, a); /* exact */ + if (inexact == 1) inexact = 2; + else if (inexact == 2) inexact = 1; + return inexact; + } + else { + inexact_left = mpfr_sub_z (&(a->left), &(b->left), c, MPFI_RNDD); + inexact_right = mpfr_sub_z (&(a->right), &(b->right), c, MPFI_RNDU); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } + +} + diff --git a/src/swap.c b/src/swap.c new file mode 100644 index 0000000..288d89e --- /dev/null +++ b/src/swap.c @@ -0,0 +1,34 @@ +/* swap.c -- Swap two intervals. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Swapping the two arguments */ +void +mpfi_swap (mpfi_ptr a, mpfi_ptr b) +{ + mpfr_swap (&(a->left), &(b->left)); + mpfr_swap (&(a->right), &(b->right)); +} diff --git a/src/tan.c b/src/tan.c new file mode 100644 index 0000000..67abf82 --- /dev/null +++ b/src/tan.c @@ -0,0 +1,81 @@ +/* tan.c -- Tangent of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_tan (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + mpz_t z_left, z_right, tmp; + + if (MPFI_NAN_P (b)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_INF_P (b)) { + /* the two endpoints are the same infinite */ + if ( mpfr_cmp (&(b->left), &(b->right)) == 0) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + return 0; + } + + mpz_init (z_left); + mpz_init (z_right); + mpz_init (tmp); + + mpfi_quadrant (z_left, &(b->left)); + mpfi_quadrant (z_right, &(b->right)); + + /* if there is at least one period in b or if b contains a Pi/2 + k*Pi, */ + /* then a = ]-oo, +oo[ */ + mpz_sub (tmp, z_right, z_left); + if ( (mpz_cmp_ui (tmp, 2) >= 0) || + (mpz_even_p (z_left) && mpz_odd_p (z_right)) ) { + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + inexact = 0; + } + + else { /* within one period, tan is increasing */ + inexact_left = mpfr_tan (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_tan (&(a->right), &(b->right), MPFI_RNDU); + if (inexact_left) inexact += 1; + if (inexact_right) inexact += 2; + } + + mpz_clear (z_left); + mpz_clear (z_right); + mpz_clear (tmp); + + return inexact; +} diff --git a/src/tanh.c b/src/tanh.c new file mode 100644 index 0000000..c555652 --- /dev/null +++ b/src/tanh.c @@ -0,0 +1,45 @@ +/* tanh.c -- Hyperbolic tangent of an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_tanh (mpfi_ptr a, mpfi_srcptr b) +{ + int inexact_left, inexact_right, inexact=0; + + inexact_left = mpfr_tanh (&(a->left), &(b->left), MPFI_RNDD); + inexact_right = mpfr_tanh (&(a->right), &(b->right), MPFI_RNDU); + + if ( MPFI_NAN_P (a) ) + MPFR_RET_NAN; + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/ui_div.c b/src/ui_div.c new file mode 100644 index 0000000..09d9d78 --- /dev/null +++ b/src/ui_div.c @@ -0,0 +1,70 @@ +/* ui_div.c -- Divide an unsigned long int by an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_ui_div (mpfi_ptr a, const unsigned long b, mpfi_srcptr c) +{ + mpfr_t tmp; + int inexact_left = 0, inexact_right = 0, inexact = 0; + + if (MPFI_NAN_P (c)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_HAS_ZERO (c)) { /* a = ]-oo, +oo [ */ + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + } + else if (b == 0) { + mpfi_set_ui (a, 0); + } + else { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_ui_div (tmp, b, &(c->right), MPFI_RNDD); + inexact_right = mpfr_ui_div (&(a->right), b, &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); + mpfr_clear (tmp); + } + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/ui_sub.c b/src/ui_sub.c new file mode 100644 index 0000000..962d938 --- /dev/null +++ b/src/ui_sub.c @@ -0,0 +1,65 @@ +/* ui_sub.c -- Subtract an interval from an unsigned long int. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_ui_sub (mpfi_ptr a, const unsigned long b, mpfi_srcptr c) +{ + int inexact_left, inexact_right, inexact=0; + mpfr_t tmp; + + if (MPFI_IS_ZERO (c)) { + return (mpfi_set_ui (a, b)); + } + else if (b == 0) { + return (mpfi_neg (a, c)); + } + else { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_ui_sub (tmp, b, &(c->right), MPFI_RNDD); + inexact_right = mpfr_ui_sub (&(a->right), b, &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } +} diff --git a/src/union.c b/src/union.c new file mode 100644 index 0000000..f1f2f53 --- /dev/null +++ b/src/union.c @@ -0,0 +1,56 @@ +/* union.c -- Union of two intervals. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_union (mpfi_ptr a, mpfi_srcptr b, mpfi_srcptr c) +{ + /* Union of two intervals, without gap: convex hull of the union */ + int inexact_left, inexact_right, inexact=0; + + if ( MPFI_NAN_P (b) || MPFI_NAN_P (c) ) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (mpfr_cmp (&(b->left), &(c->left)) <= 0) + inexact_left = mpfr_set (&(a->left), &(b->left), MPFI_RNDD); + else + inexact_left = mpfr_set (&(a->left), &(c->left), MPFI_RNDD); + + if (mpfr_cmp (&(c->right), &(b->right)) <= 0) + inexact_right = mpfr_set (&(a->right), &(b->right), MPFI_RNDU); + else + inexact_right = mpfr_set (&(a->right), &(c->right), MPFI_RNDU); + + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; +} diff --git a/src/urandom.c b/src/urandom.c new file mode 100644 index 0000000..b6c2a2c --- /dev/null +++ b/src/urandom.c @@ -0,0 +1,99 @@ +/* urandom.c -- Random element in the interval, following a uniform distribution on the reals. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2018 + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and AriC project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +/* Picks randomly a point m in y */ +void +mpfi_urandom (mpfr_ptr m, mpfi_srcptr y, gmp_randstate_t state) +{ + mpfr_prec_t prec, tmp_prec; + mpfr_t diam, fact; + + + if (MPFI_NAN_P(y)) { + mpfr_set_nan (m); + return; + } + + if (mpfr_equal_p (&(y->left), &(y->right))) { + mpfr_set (m, &(y->left), MPFR_RNDN); + return; + } + + prec = mpfr_get_prec (m); + tmp_prec = mpfi_get_prec(y); + if (tmp_prec > prec) + { + prec = tmp_prec; + } + mpfr_init2 (diam, prec); + mpfr_init2 (fact, prec); + + mpfi_diam_abs (diam, y); + mpfr_urandom (fact, state, MPFR_RNDN); /* fact lies between 0 and 1 */ + + if (mpfr_cmp_ui (diam, 1) <= 0) { + /* the picked point lies at a relative distance "fact" of the left + endpoint: m = inf + (sup - inf) * fact */ + mpfr_mul (fact, fact, diam, MPFR_RNDN); + /* FIXME: because of possible cancelation, the random distribution is + not uniform among the floating-point numbers in y */ + mpfr_add (m, &(y->left), fact, MPFR_RNDN); + } + else { + mpfr_exp_t e; + if (mpfr_cmp_abs (&(y->left), &(y->right)) < 0) { + e = mpfr_inf_p (&(y->right)) ? mpfr_get_emax () + : mpfr_get_exp (&(y->right)); + } + else { + e = mpfr_inf_p (&(y->left)) ? mpfr_get_emax () + : mpfr_get_exp (&(y->left)); + } + e += 1; + /* resize fact in [0, 2^e] where e = 1 + max{exp(left), exp(right)} */ + mpfr_mul_2exp (fact, fact, e, MPFR_RNDN); + mpfr_set (m, &(y->left), MPFR_RNDN); + if (mpfr_inf_p (m)) { + mpfr_nextabove (m); + } + /* m may be outside y */ + mpfr_add (m, m, fact, MPFR_RNDN); + } + mpfr_clear (fact); + mpfr_clear (diam); + + /* Ensure that m belongs to y (if the precision is sufficient) */ + if (mpfr_cmp (m, &(y->left)) <= 0) + mpfr_set (m, &(y->left), MPFR_RNDU); + + if (mpfr_cmp (&(y->right), m) <= 0) + mpfr_set (m, &(y->right), MPFR_RNDD); + + /* the "<=" instead of "<" ensures that the sign of m corresponds to the sign of elements in y, + if one of the endpoints of y is a signed 0, and m is also 0. */ +} diff --git a/src/z_div.c b/src/z_div.c new file mode 100644 index 0000000..9a2962c --- /dev/null +++ b/src/z_div.c @@ -0,0 +1,74 @@ +/* z_div.c -- Divide an integer by an interval. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" + +int +mpfi_z_div (mpfi_ptr a, mpz_srcptr b, mpfi_srcptr c) +{ + mpfi_t tmp; + int inexact_set, inexact_div, inexact = 0; + + if (MPFI_NAN_P (c)) { + mpfr_set_nan (&(a->left)); + mpfr_set_nan (&(a->right)); + MPFR_RET_NAN; + } + + if (MPFI_HAS_ZERO (c)) { /* a = ]-oo, +oo [ */ + mpfr_set_inf (&(a->left), -1); + mpfr_set_inf (&(a->right), 1); + return inexact; + } + + if (mpz_sgn (b) == 0) { /* a = [-0, +0] */ + mpfi_set_ui (a, 0); + return inexact; + } + + mpfi_init2 (tmp, mpfi_get_prec (a)); + inexact_set = mpfi_set_z (tmp, b); + inexact_div = mpfi_div (a, tmp, c); + MPFI_CLEAR (tmp); + + if (MPFI_LEFT_IS_INEXACT (inexact_div) + || (inexact_set && !mpfr_inf_p (&a->left) && !mpfr_zero_p (&a->left))) { + /* the first condition MPFI_LEFT_IS_INEXACT (inexact_div) handles, among + others, overflow and underflow cases. + if a->left = infinity in non-overflow case, then a->left is the + quotient of b with a zero endpoint of c, thus it is exact even if tmp + is not exact. + if a->left = 0 in non-underflow case, then either a->left is the + quotient of b with an infinite endpoint of c, or b is zero, thus + a->left is exact. */ + inexact += 1; + } + if (MPFI_RIGHT_IS_INEXACT (inexact_div) + ||(inexact_set && !mpfr_inf_p (&a->right) && !mpfr_zero_p (&a->right))){ + inexact += 2; + } + + return inexact; +} diff --git a/src/z_sub.c b/src/z_sub.c new file mode 100644 index 0000000..79be969 --- /dev/null +++ b/src/z_sub.c @@ -0,0 +1,82 @@ +/* z_sub.c -- Subtract an interval from an integer. + +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2011, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-impl.h" +#include "mpfi_config.h" + +#ifndef HAVE_MPFR_Z_SUB +static int +mpfr_z_sub (mpfr_ptr x, mpz_srcptr z, mpfr_srcptr y, mpfr_rnd_t rnd) +{ + /* mpfr_z_sub does not exist (at least up to version 3.0) */ + + /* Here we use the fact that x and y do not point to the same variable */ + int inex; + + inex = mpfr_sub_z (x, y, z, rnd == MPFI_RNDD ? MPFI_RNDU : MPFI_RNDD); + mpfr_neg (x, x, MPFI_RNDD); + + return -inex; +} +#endif /* HAVE_MPFR_Z_SUB */ + +int +mpfi_z_sub (mpfi_ptr a, mpz_srcptr b, mpfi_srcptr c) +{ + int inexact_left, inexact_right, inexact=0; + mpfr_t tmp; + + if (MPFI_IS_ZERO (c)) { + return (mpfi_set_z (a, b)); + } + else if (!mpz_sgn(b)) { + return (mpfi_neg (a, c)); + } + else { + mpfr_init2 (tmp, mpfr_get_prec (&(a->left))); + inexact_left = mpfr_z_sub (tmp, b, &(c->right), MPFI_RNDD); + inexact_right = mpfr_z_sub (&(a->right), b, &(c->left), MPFI_RNDU); + mpfr_set (&(a->left), tmp, MPFI_RNDD); /* exact */ + mpfr_clear (tmp); + + /* do not allow -0 as lower bound */ + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) { + mpfr_neg (&(a->left), &(a->left), MPFI_RNDU); + } + /* do not allow +0 as upper bound */ + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) { + mpfr_neg (&(a->right), &(a->right), MPFI_RNDD); + } + + if (MPFI_NAN_P (a)) + MPFR_RET_NAN; + if (inexact_left) + inexact += 1; + if (inexact_right) + inexact += 2; + + return inexact; + } +} diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..be7cba5 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,115 @@ +LDADD = libmpfi-tests.la $(top_builddir)/src/.libs/libmpfi.la +AM_CPPFLAGS = -I$(top_srcdir)/src + +check_LTLIBRARIES = libmpfi-tests.la +libmpfi_tests_la_SOURCES = mpfi-tests.h read_data.c random.c \ + type_i.c type_ii.c type_iii.c type_iiii.c type_iu.c type_is.c \ + type_id.c type_if.c type_il.c type_iz.c type_iq.c type_ir.c type_iiu.c \ + type_iis.c type_iid.c type_iiz.c type_iiq.c type_iir.c \ + type_iui.c type_isi.c type_idi.c type_izi.c type_iqi.c \ + type_iri.c type_js.c type_ju.c type_ri.c check_data.c mpfi-tests.c + +#check_PROGRAMS = tabs tacos tacosh tadd tadd_d tadd_fr \ +# tadd_q tadd_si tadd_ui tadd_z tasin tasinh tatan tatan2 \ +# tatanh tbisect tblow tbounded_p tcbrt tcmp tcmp_d \ +# tcmp_fr tcmp_q tcmp_si tcmp_ui tcmp_z tconst_catalan \ +# tconst_euler tconst_log2 tconst_pi tcos tcosh tcot tcoth \ +# tcsc tcsch td_div td_sub tdiam tdiam_abs tdiam_rel tdiv \ +# tdiv_2exp tdiv_2si tdiv_2ui tdiv_d tdiv_ext tdiv_fr tdiv_q \ +# tdiv_si tdiv_ui tdiv_z terror texp texp2 texpm1 tfr_div \ +# tfr_sub tget_d tget_endpoints tget_fr thas_zero thypot \ +# tincrease tinf_p tinit tinits tinit_set tintersect tinterv_d \ +# tinterv_fr tinterv_q tinterv_si tinterv_ui tinterv_z \ +# tinv tio_str tis_empty tis_inside tis_inside_d \ +# tis_inside_fr tis_inside_q tis_inside_si tis_inside_ui \ +# tis_inside_z tis_neg tis_nonneg tis_nonpos tis_pos \ +# tis_strictly_inside tis_strictly_neg tis_strictly_pos \ +# tis_zero tlog tlog10 tlog1p tlog2 tmag tmid tmig tmul \ +# tmul_2exp tmul_2si tmul_2ui tmul_d tmul_fr tmul_q \ +# tmul_si tmul_ui tmul_z tnan_p tneg tput_d tput_fr tput_q \ +# tput_si tput_ui tput_z tq_div tq_sub tround_prec tsec \ +# tsech tset tset_d tset_flt tset_fr tset_ld tset_q tset_si tset_sj tset_str \ +# tset_ui tset_uj tset_z tsi_div tsi_sub tsin tsinh tsqr tsqrt\ +# tsub tsub_d tsub_fr tsub_q tsub_si tsub_ui tsub_z tswap \ +# ttan ttanh tui_div tui_sub tunion tz_div tz_sub \ +# tget_version + +check_PROGRAMS = tabs tacos tacosh tadd tadd_d tadd_fr \ + tadd_q tadd_si tadd_ui tadd_z tasin tasinh tatan tatan2 \ + tatanh tbisect tblow tbounded_p tcbrt tcmp tcmp_d \ + tcmp_fr tcmp_q tcmp_si tcmp_ui tcmp_z tconst_catalan \ + tconst_euler tconst_log2 tconst_pi tcos tcosh tcot tcoth \ + tcsc tcsch td_div td_sub tdiam tdiam_abs tdiam_rel tdiv \ + tdiv_2exp tdiv_2si tdiv_2ui tdiv_d tdiv_ext tdiv_fr tdiv_q \ + tdiv_si tdiv_ui tdiv_z terror texp texp2 texpm1 tfr_div \ + tfr_sub tget_d tget_endpoints tget_fr thas_zero thypot \ + tincrease tinf_p tinit tinits tinit_set tintersect tinterv_d \ + tinterv_fr tinterv_q tinterv_si tinterv_ui tinterv_z \ + tinv tio_str tis_empty tis_inside tis_inside_d \ + tis_inside_fr tis_inside_q tis_inside_si tis_inside_ui \ + tis_inside_z tis_neg tis_nonneg tis_nonpos tis_pos \ + tis_strictly_inside tis_strictly_neg tis_strictly_pos \ + tis_zero tlog tlog10 tlog1p tlog2 tmag tmid tmig tmul \ + tmul_2exp tmul_2si tmul_2ui tmul_d tmul_fr tmul_q \ + tmul_si tmul_ui tmul_z tnan_p tneg tput_d tput_fr tput_q \ + tput_si tput_ui tput_z tq_div tq_sub tround_prec tsec \ + tsech tset tset_d tset_flt tset_fr tset_ld tset_q tset_si tset_str \ + tset_ui tset_z tsi_div tsi_sub tsin tsinh tsqr tsqrt \ + tsub tsub_d tsub_fr tsub_q tsub_si tsub_ui tsub_z tswap \ + ttan ttanh tui_div tui_sub tunion tz_div tz_sub \ + tget_version + +#EXTRA_DIST = abs.dat acos.dat acosh.dat add.dat add_d.dat \ +# add_fr.dat add_q.dat add_si.dat add_ui.dat add_z.dat \ +# asin.dat asinh.dat atan.dat atan2.dat atanh.dat \ +# bisect.dat blow.dat bounded_p.dat cbrt.dat \ +# const_catalan.dat const_euler.dat const_log2.dat \ +# const_pi.dat cos.dat cosh.dat cot.dat coth.dat csc.dat \ +# csch.dat d_div.dat d_sub.dat diam.dat diam_abs.dat \ +# diam_rel.dat div.dat div_2si.dat div_2ui.dat div_d.dat \ +# div_ext.dat div_fr.dat div_q.dat div_si.dat div_ui.dat div_z.dat \ +# exp.dat exp2.dat expm1.dat fr_div.dat fr_sub.dat \ +# has_zero.dat hypot.dat increase.dat inf_p.dat \ +# inp_str.dat intersect.dat inv.dat is_neg.dat \ +# is_nonneg.dat is_nonpos.dat is_pos.dat \ +# is_strictly_neg.dat is_strictly_pos.dat log.dat \ +# log10.dat log1p.dat log2.dat mag.dat mid.dat mig.dat \ +# mul.dat mul_2si.dat mul_2ui.dat mul_d.dat mul_fr.dat \ +# mul_q.dat mul_si.dat mul_ui.dat mul_z.dat nan_p.dat \ +# neg.dat put_d.dat put_fr.dat put_q.dat put_si.dat \ +# put_ui.dat put_z.dat q_div.dat q_sub.dat sec.dat \ +# sech.dat set_d.dat set_flt.dat set_fr.dat set_ld.dat set_q.dat set_si.dat set_sj.dat\ +# set_ui.dat set_uj.dat set_z.dat si_div.dat si_sub.dat sin.dat\ +# sinh.dat sqr.dat sqrt.dat sub.dat sub_d.dat sub_fr.dat \ +# sub_q.dat sub_si.dat sub_ui.dat sub_z.dat tan.dat \ +# tanh.dat ui_div.dat ui_sub.dat union.dat z_div.dat \ +# z_sub.dat + +EXTRA_DIST = abs.dat acos.dat acosh.dat add.dat add_d.dat \ + add_fr.dat add_q.dat add_si.dat add_ui.dat add_z.dat \ + asin.dat asinh.dat atan.dat atan2.dat atanh.dat \ + bisect.dat blow.dat bounded_p.dat cbrt.dat \ + const_catalan.dat const_euler.dat const_log2.dat \ + const_pi.dat cos.dat cosh.dat cot.dat coth.dat csc.dat \ + csch.dat d_div.dat d_sub.dat diam.dat diam_abs.dat \ + diam_rel.dat div.dat div_2si.dat div_2ui.dat div_d.dat \ + div_ext.dat div_fr.dat div_q.dat div_si.dat div_ui.dat div_z.dat \ + exp.dat exp2.dat expm1.dat fr_div.dat fr_sub.dat \ + has_zero.dat hypot.dat increase.dat inf_p.dat \ + inp_str.dat intersect.dat inv.dat is_neg.dat \ + is_nonneg.dat is_nonpos.dat is_pos.dat \ + is_strictly_neg.dat is_strictly_pos.dat log.dat \ + log10.dat log1p.dat log2.dat mag.dat mid.dat mig.dat \ + mul.dat mul_2si.dat mul_2ui.dat mul_d.dat mul_fr.dat \ + mul_q.dat mul_si.dat mul_ui.dat mul_z.dat nan_p.dat \ + neg.dat put_d.dat put_fr.dat put_q.dat put_si.dat \ + put_ui.dat put_z.dat q_div.dat q_sub.dat sec.dat \ + sech.dat set_d.dat set_flt.dat set_fr.dat set_ld.dat set_q.dat set_si.dat \ + set_ui.dat set_z.dat si_div.dat si_sub.dat sin.dat \ + sinh.dat sqr.dat sqrt.dat sub.dat sub_d.dat sub_fr.dat \ + sub_q.dat sub_si.dat sub_ui.dat sub_z.dat tan.dat \ + tanh.dat ui_div.dat ui_sub.dat union.dat z_div.dat \ + z_sub.dat + +TESTS = $(check_PROGRAMS) +CLEANFILES = io_str.tmp diff --git a/tests/abs.dat b/tests/abs.dat new file mode 100644 index 0000000..ec21095 --- /dev/null +++ b/tests/abs.dat @@ -0,0 +1,41 @@ +# data file for mpfi_abs +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 nan +1 +0 53 nan nan 53 +inf nan +0 53 +inf +inf 53 -inf -inf +0 53 +7 +inf 53 -inf -7 +0 53 +0 +inf 53 -inf -0 +0 53 +0 +inf 53 -inf -0 +0 53 +0 +inf 53 -inf +8 +0 53 +0 +inf 53 -inf +inf +0 53 +0 -0 53 +0 -0 +0 53 +0 +8 53 +0 +8 +0 53 +0 +inf 53 +0 +inf +0 53 +0 +8 53 +0 +8 +0 53 +0 +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +0 53 0x123456789p-16 0x123456799p-16 53 0x123456789p-16 0x123456799p-16 +1 12 0x888p+21 0x222p+24 53 0x111111111 0x222p+24 +2 12 0xaaa 0xaabp+4 53 -0xaaa1 -0xaaa +3 12 0xaaa0 0xb6d0 53 -0xb6c1 -0xaaa1 + +0 53 +0 0x123456799p-16 53 -0x123456789p-16 0x123456799p-16 +2 12 +0 0xaabp+4 53 -0xaaa1 0xaaa diff --git a/tests/acos.dat b/tests/acos.dat new file mode 100644 index 0000000..71f87a0 --- /dev/null +++ b/tests/acos.dat @@ -0,0 +1,43 @@ +# data file for mpfi_acos +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 0x3243f6a8885a3p-49 nan 53 nan -0 +0 53 nan 0x1921fb54442d19p-52 53 +0 nan +0 53 0 nan 53 nan +1 +0 53 nan nan 53 +inf nan +0 53 nan nan 53 -inf -inf +0 53 nan nan 53 -inf -7 +0 53 0x3243f6a8885a3p-49 nan 53 -inf -0 +0 53 nan nan 53 -inf +8 +0 53 nan nan 53 -inf +inf +3 53 0x3243f6a8885a3p-49 0x1921fb54442d19p-51 53 -1 -0 +3 53 0x3243f6a8885a3p-49 0x1921fb54442d19p-52 53 +0 -0 +2 53 0 0x1921fb54442d19p-52 53 +0 +1 +0 53 nan 0x1921fb54442d19p-52 53 +0 +8 +0 53 nan 0x1921fb54442d19p-52 53 +0 +inf +0 53 nan nan 53 +inf +inf + +# regular values +0 53 nan nan 53 -6 -4 +0 53 0x10c152382d7365p-51 nan 53 -2 -0.5 +3 53 0x10c152382d7365p-51 0x1921fb54442d19p-51 53 -1 -0.5 +3 53 0x1d2cf5c7c70f0bp-52 0x4d6749be4edb1p-49 53 -0.75 -0.25 +3 53 0x10c152382d7365p-52 0x860a91c16b9b3p-50 53 -0.5 0.5 +3 53 0x1ca94936b98a21p-53 0x151700e0c14b25p-52 53 0.25 0.625 +2 53 0 0x1921fb54442d19p-51 53 -1 1 +0 53 nan 0x1720a392c1d955p-52 53 0.125 17 +0 53 nan nan 53 17 42 +0 53 nan nan 53 -42 17 diff --git a/tests/acosh.dat b/tests/acosh.dat new file mode 100644 index 0000000..4ff3002 --- /dev/null +++ b/tests/acosh.dat @@ -0,0 +1,42 @@ +# data file for mpfi_acosh +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan -0 53 nan +1 +0 53 +inf nan 53 +inf nan +0 53 nan nan 53 -inf -inf +0 53 nan nan 53 -inf -7 +0 53 nan nan 53 -inf -0 +0 53 nan -0 53 -inf +1 +0 53 nan 0x5898db90230cfp-49 53 -inf +8 +0 53 nan +inf 53 -inf +inf +0 53 nan nan 53 -1 -0 +0 53 nan nan 53 +0 -0 +0 53 nan -0 53 +0 +1 +0 53 nan 0x5898db90230cfp-49 53 +0 +8 + +0 53 nan +inf 53 +0 +inf +0 53 +0 +inf 53 +1 +inf +1 53 0x1ecc2caec51609p-53 +inf 53 +1.5 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +0 53 nan nan 53 -6 -4 +0 53 nan 0xf661657628b05p-52 53 -2 1.5 +2 53 +0 0xf661657628b05p-52 53 1 1.5 +3 53 0x1ecc2caec51609p-53 0xf661657628b05p-52 53 1.5 1.5 +3 53 0x544909c66010dp-50 0x799d4ba2a13b5p-48 53 2 1000 diff --git a/tests/add.dat b/tests/add.dat new file mode 100644 index 0000000..24ab557 --- /dev/null +++ b/tests/add.dat @@ -0,0 +1,64 @@ +# data file for mpfi_add +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of second parameter +# 8: precision of second parameter +# 9: left endpoint value of second parameter +# 10: right endpoint value of second parameter + +# special values +0 53 nan nan 53 nan nan 53 -inf -7 +0 53 nan nan 53 nan nan 53 -8 +1 +0 53 nan nan 53 nan nan 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 nan +0 53 nan nan 53 nan nan 53 +5 +inf +0 53 nan nan 53 nan nan 53 +inf +inf +0 53 nan nan 53 nan nan 53 nan -0 +0 53 nan -7 53 nan -0 53 -inf -7 +0 53 nan +1 53 nan -0 53 -8 +1 +0 53 nan +inf 53 nan +inf 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 +7 +0 53 nan nan 53 nan -inf 53 +5 +inf +0 53 nan +inf 53 nan -7 53 +inf +inf +0 53 nan +1 53 nan +1 53 nan -0 +0 53 -inf -inf 53 -inf -inf 53 -inf -inf +0 53 -inf +1 53 -inf -7 53 -1 +8 +0 53 -inf +inf 53 -inf -0 53 +8 +inf +0 53 nan +inf 53 -inf -0 53 +inf +inf +0 53 -inf +16 53 -inf +8 53 +0 +8 +0 53 -inf +inf 53 -inf +inf 53 +0 +8 +0 53 -inf -7 53 +0 -0 53 -inf -7 +0 53 -7 +8 53 +0 +8 53 -7 -0 +0 53 +0 +8 53 +0 -0 53 +0 +8 +0 53 +0 +inf 53 +0 +inf 53 +0 +8 +0 53 +8 +inf 53 +0 -0 53 +8 +inf +0 53 +inf nan 53 +0 +8 53 +inf nan +0 53 -inf +inf 53 +0 -0 53 -inf +inf +0 53 +0 +16 53 +0 +8 53 +0 +8 +0 53 +0 -0 53 +0 -0 53 +0 -0 +0 53 -7 +inf 53 +0 +inf 53 -7 +8 +0 53 +8 nan 53 +0 nan 53 +8 +inf +0 53 +inf +inf 53 +0 +8 53 +inf +inf +0 53 nan +inf 53 +inf +inf 53 -inf +3 +0 53 +inf +inf 53 +inf +inf 53 +0 +inf +0 53 +inf nan 53 +inf +inf 53 +3 nan +0 53 nan nan 53 +inf nan 53 -inf -7 +0 53 +inf nan 53 +inf nan 53 +inf +inf +0 53 +inf nan 53 +inf nan 53 -3 +7 + +# regular values +0 53 -0x1p-1 -0x187p-256 53 -0.375 -0x10187p-256 53 -0.125 0x1p-240 +1 53 -0x10000000000001p-93 0x123456789abcd 53 -0x1p-300 0x123456p+28 53 -0x10000000000000p-93 0x789abcd +2 53 -0x123456791abcdp-17 0x8f596b3002c1bp+947 53 -4 +7 53 -0x123456789abcdp-17 3e300 +3 53 +0x1010101010101p+8 0x8f596b3002c1bp+947 53 0x1000100010001p+8 0x1p+60 53 0x1000100010001 3e300 + +# signed zeros +0 53 +0 +6 53 +4 +8 53 -4 -2 +0 53 -5 -0 53 +4 +8 53 -9 -8 diff --git a/tests/add_d.dat b/tests/add_d.dat new file mode 100644 index 0000000..dfeb992 --- /dev/null +++ b/tests/add_d.dat @@ -0,0 +1,110 @@ +# data file for mpfi_add_d +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +#WARNING: +# double values are read by the test suite with rounding towards minus +# infinity to a machine-dependant precision (whereas the mpfi data are read +# at the given precision with rounding to the nearest). +# So as to ensure portability, use test values that are representable with a +# 53 bit-significand which corresponds to the minimum default precision for +# a double in the test suite. + +# special values +0 53 nan nan 53 nan nan -0x170ef54646d497p-109 +0 53 nan nan 53 nan nan 0.0 +0 53 nan nan 53 nan nan 0x170ef54646d497p-109 +0 53 nan -inf 53 nan -inf -0x114b37f4b51f71p-107 +0 53 nan -inf 53 nan -inf 0.0 +0 53 nan -inf 53 nan -inf 0x114b37f4b51f71p-107 +0 53 nan -0x1c000000000007p-50 53 nan -7 -0xfc339ab0a6b53p-99 +0 53 nan -7 53 nan -7 0.0 +0 53 nan -0 53 nan -7 7.0 +0 53 nan -15 53 nan -0 -15.0 +0 53 nan -0 53 nan -0 0.0 +0 53 nan 15 53 nan -0 15.0 +0 53 nan 0xfffffffffffffp-52 53 nan +1 -0xb2b3ece0a4ef9p-103 +0 53 nan 1 53 nan +1 0.0 +0 53 nan 0x8000000000001p-51 53 nan +1 0xb2b3ece0a4ef9p-103 +0 53 nan +inf 53 nan +inf -0x5acae5c4b6e51p-101 +0 53 nan +inf 53 nan +inf 0.0 +0 53 nan +inf 53 nan +inf 0x5acae5c4b6e51p-101 +0 53 -inf -inf 53 -inf -inf -0x170ef54646d497p-108 +0 53 -inf -inf 53 -inf -inf 0.0 +0 53 -inf -inf 53 -inf -inf 0x170ef54646d497p-108 +2 53 -inf -7 53 -inf -7 -0x170ef54646d497p-107 +0 53 -inf -7 53 -inf -7 0.0 +2 53 -inf -0x1bffffffffffffp-50 53 -inf -7 0x170ef54646d497p-107 +0 53 -inf -8.0e-17 53 -inf -0 -0x170ef54646d497p-106 +0 53 -inf -0 53 -inf -0 0.0 +0 53 -inf 0x170ef54646d497p-106 53 -inf -0 0x170ef54646d497p-106 +2 53 -inf -0x16345785d89fff00 53 -inf 8 -0x16345785d8a00000 +0 53 -inf 8 53 -inf 8 0.0 +2 53 -inf 0x16345785d8a00100 53 -inf 8 0x16345785d8a00000 +0 53 -inf +inf 53 -inf +inf -0x170ef54646d497p-105 +0 53 -inf +inf 53 -inf +inf 0.0e-17 +0 53 -inf +inf 53 -inf +inf +0x170ef54646d497p-105 +0 53 -inf nan 53 -inf nan -0x170ef54646d497p-104 +0 53 -inf nan 53 -inf nan 0.0e-17 +0 53 -inf nan 53 -inf nan +0x170ef54646d497p-104 + +0 53 -0x170ef54646d497p-109 -0x170ef54646d497p-109 + 53 +0 -0 -0x170ef54646d497p-109 +0 53 +0 -0 + 53 +0 -0 0.0 +0 53 0x170ef54646d497p-109 0x170ef54646d497p-109 + 53 +0 -0 0x170ef54646d497p-109 +2 53 -0x114b37f4b51f71p-107 8 + 53 +0 8 -0x114b37f4b51f71p-107 +0 53 +0 8 + 53 +0 8 0.0 +2 53 0x114b37f4b51f7p-103 0x10000000000001p-49 + 53 +0 8 0x114b37f4b51f7p-103 +0 53 -0x50b45a75f7e81p-104 +inf + 53 +0 +inf -0x50b45a75f7e81p-104 +0 53 +0 +inf + 53 +0 +inf 0.0 +0 53 0x142d169d7dfa03p-106 +inf + 53 +0 +inf 0x142d169d7dfa03p-106 + +0 53 +inf +inf 53 +inf +inf -0x170ef54646d497p-109 +0 53 +inf +inf 53 +inf +inf 0.0 +0 53 +inf +inf 53 +inf +inf 0x170ef54646d497p-109 +0 53 +inf nan 53 +inf nan -0x170ef54646d497p-109 +0 53 +inf nan 53 +inf nan 0.0 +0 53 +inf nan 53 +inf nan 0x170ef54646d497p-109 + +# regular values +0 53 -0x1fb53d14aa9c2fp-47 -0x18353d14aa9c2fp-47 + 53 -32 -17 -0xfb53d14aa9c2fp-47 +0 53 +0 0x7353d14aa9c2fp-47 + 53 -0xfb53d14aa9c2fp-47 -17 0xfb53d14aa9c2fp-47 +0 53 -0x104ac2eb5563d1p-48 -0 + 53 -32 -0xfb53d14aa9c2fp-48 0xfb53d14aa9c2fp-48 + +0 53 0x15b456789abcdfp-48 0x123456789abd17p-4 + 53 0x123456789abcdfp-48 0x123456789abcdfp-4 3.5 +1 53 0x3923456789abcdp-52 0x123456789abd17p-4 + 53 0x123456789abcdfp-56 0x123456789abcdfp-4 3.5 +2 53 0x18p-4 0x101a3456789abdp-44 + 53 -0xff 0x123456789abcdfp-52 256.5 +3 53 0xfff8p-4 0x10018p-4 + 53 -0x1fffffffffffffp-52 -0x1p-550 4097.5 + +0 53 0xeb456789abcdfp-48 0x123456789abca7p-4 + 53 0x123456789abcdfp-48 0x123456789abcdfp-4 -3.5 +1 53 -0x36dcba98765434p-52 0x123456789abca7p-4 + 53 0x123456789abcdfp-56 0x123456789abcdfp-4 -3.5 +2 53 -0x1ff8p-4 -0xff5cba9876543p-44 + 53 -0xff 0x123456789abcdfp-52 -256.5 +3 53 -0x10038p-4 -0x10018p-4 + 53 -0x1fffffffffffffp-52 -0x1p-550 -4097.5 diff --git a/tests/add_fr.dat b/tests/add_fr.dat new file mode 100644 index 0000000..12dd83b --- /dev/null +++ b/tests/add_fr.dat @@ -0,0 +1,114 @@ +# data file for mpfi_add_fr +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan 53 -0x170ef54646d497p-109 +0 53 nan nan 53 nan nan 53 -0 +0 53 nan nan 53 nan nan 53 0x170ef54646d497p-109 +0 53 nan -inf 53 nan -inf 53 -0x114b37f4b51f71p-107 +0 53 nan -inf 53 nan -inf 53 +0 +0 53 nan -inf 53 nan -inf 53 0x114b37f4b51f71p-107 +0 53 nan -0x1c000000000007p-50 53 nan -7 53 -0xfc339ab0a6b53p-99 +0 53 nan -7 53 nan -7 53 -0 +0 53 nan -0 53 nan -7 53 7.0 +0 53 nan -15 53 nan -0 53 -15.0 +0 53 nan -0 53 nan -0 53 +0 +0 53 nan 15 53 nan -0 53 15.0 +0 53 nan 0xfffffffffffffp-52 53 nan +1 53 -0xb2b3ece0a4ef9p-103 +0 53 nan 1 53 nan +1 53 -0 +0 53 nan 0x8000000000001p-51 53 nan +1 53 0xb2b3ece0a4ef9p-103 +0 53 nan +inf 53 nan +inf 53 -0x5acae5c4b6e51p-101 +0 53 nan +inf 53 nan +inf 53 +0 +0 53 nan +inf 53 nan +inf 53 0x5acae5c4b6e51p-101 +0 53 -inf -inf 53 -inf -inf 53 -0x170ef54646d497p-108 +0 53 -inf -inf 53 -inf -inf 53 +0 +0 53 -inf -inf 53 -inf -inf 53 0x170ef54646d497p-108 +2 53 -inf -7 53 -inf -7 53 -0x170ef54646d497p-107 +0 53 -inf -7 53 -inf -7 53 -0 +2 53 -inf -0x1bffffffffffffp-50 53 -inf -7 53 0x170ef54646d497p-107 +0 53 -inf -8.0e-17 53 -inf -0 53 -0x170ef54646d497p-106 +0 53 -inf -0 53 -inf -0 53 +0 +0 53 -inf 0x170ef54646d497p-106 53 -inf -0 53 0x170ef54646d497p-106 +2 53 -inf -0x16345785d89fff00 53 -inf 8 53 -0x16345785d8a00000 +0 53 -inf 8 53 -inf 8 53 -0 +2 53 -inf 0x16345785d8a00100 53 -inf 8 53 0x16345785d8a00000 +0 53 -inf +inf 53 -inf +inf 53 -0x170ef54646d497p-105 +0 53 -inf +inf 53 -inf +inf 53 +0 +0 53 -inf +inf 53 -inf +inf 53 +0x170ef54646d497p-105 +0 53 -inf nan 53 -inf nan 53 -0x170ef54646d497p-104 +0 53 -inf nan 53 -inf nan 53 -0 +0 53 -inf nan 53 -inf nan 53 +0x170ef54646d497p-104 + +1 53 -0x10000000000001p-49 -0x114b37f4b51f71p-107 + 53 -8 -0 53 -0x114b37f4b51f71p-107 +0 53 -8 -0 + 53 -8 -0 53 -0 +1 53 -8 0x114b37f4b51f71p-107 + 53 -8 -0 53 0x114b37f4b51f71p-107 +0 53 -0x170ef54646d497p-109 -0x170ef54646d497p-109 + 53 +0 -0 53 -0x170ef54646d497p-109 +0 53 +0 -0 + 53 +0 -0 53 +0 +0 53 0x170ef54646d497p-109 0x170ef54646d497p-109 + 53 +0 -0 53 0x170ef54646d497p-109 +2 53 -0x114b37f4b51f71p-107 8 + 53 +0 8 53 -0x114b37f4b51f71p-107 +0 53 +0 8 + 53 +0 8 53 -0 +2 53 0x114b37f4b51f7p-103 0x10000000000001p-49 + 53 +0 8 53 0x114b37f4b51f7p-103 +0 53 -0x50b45a75f7e81p-104 +inf + 53 +0 +inf 53 -0x50b45a75f7e81p-104 +0 53 +0 +inf + 53 +0 +inf 53 +0 +0 53 0x142d169d7dfa03p-106 +inf + 53 +0 +inf 53 0x142d169d7dfa03p-106 +1 53 0x1fffffffffffffp-50 +inf + 53 8 +inf 53 -0x114b37f4b51f71p-107 +0 53 8 +inf + 53 8 +inf 53 +0 +1 53 8 +inf + 53 8 +inf 53 0x114b37f4b51f71p-107 + +0 53 +inf +inf 53 +inf +inf 53 -0x170ef54646d497p-109 +0 53 +inf +inf 53 +inf +inf 53 -0 +0 53 +inf +inf 53 +inf +inf 53 0x170ef54646d497p-109 +0 53 +inf nan 53 +inf nan 53 -0x170ef54646d497p-109 +0 53 +inf nan 53 +inf nan 53 +0 +0 53 +inf nan 53 +inf nan 53 0x170ef54646d497p-109 + +# regular values +0 53 -0x1fb53d14aa9c2fp-47 -0x18353d14aa9c2fp-47 + 53 -32 -17 53 -0xfb53d14aa9c2fp-47 +0 53 +0 0x7353d14aa9c2fp-47 + 53 -0xfb53d14aa9c2fp-47 -17 53 0xfb53d14aa9c2fp-47 +0 53 -0x104ac2eb5563d1p-48 -0 + 53 -32 -0xfb53d14aa9c2fp-48 53 0xfb53d14aa9c2fp-48 + +0 53 0x15b456789abcdfp-48 0x123456789abd17p-4 + 53 0x123456789abcdfp-48 0x123456789abcdfp-4 53 3.5 +1 53 0x3923456789abcdp-52 0x123456789abd17p-4 + 53 0x123456789abcdfp-56 0x123456789abcdfp-4 53 3.5 +2 53 0x18p-4 0x101a3456789abdp-44 + 53 -0xff 0x123456789abcdfp-52 53 256.5 +3 53 0xfff8p-4 0x10018p-4 + 53 -0x1fffffffffffffp-52 -0x1p-550 53 4097.5 + +0 53 0xeb456789abcdfp-48 0x123456789abca7p-4 + 53 0x123456789abcdfp-48 0x123456789abcdfp-4 53 -3.5 +1 53 -0x36dcba98765434p-52 0x123456789abca7p-4 + 53 0x123456789abcdfp-56 0x123456789abcdfp-4 53 -3.5 +2 53 -0x1ff8p-4 -0xff5cba9876543p-44 + 53 -0xff 0x123456789abcdfp-52 53 -256.5 +3 53 -0x10038p-4 -0x10018p-4 + 53 -0x1fffffffffffffp-52 -0x1p-550 53 -4097.5 diff --git a/tests/add_q.dat b/tests/add_q.dat new file mode 100644 index 0000000..7169b83 --- /dev/null +++ b/tests/add_q.dat @@ -0,0 +1,88 @@ +# data file for mpfi_add_q +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1/1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1/1 +0 53 nan -inf 53 nan -inf -3/1 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3/1 +0 53 nan -14 53 nan -7 -7/1 +0 53 nan -7 53 nan -7 0 +0 53 nan -0 53 nan -7 7/1 +0 53 nan -15 53 nan -0 -15/1 +0 53 nan -0 53 nan -0 0 +0 53 nan +15 53 nan -0 15/1 +0 53 nan -30 53 nan +1 -31/1 +0 53 nan +1 53 nan +1 0 +0 53 nan +32 53 nan +1 31/1 +0 53 nan +inf 53 nan +inf -63/1 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63/1 +0 53 -inf -inf 53 -inf -inf -2/1 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2/1 +0 53 -inf -11 53 -inf -7 -4/1 +0 53 -inf -7 53 -inf -7 0 +0 53 -inf -3 53 -inf -7 4/1 +0 53 -inf -8 53 -inf -0 -8/1 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf +8 53 -inf -0 8/1 +0 53 -inf -8 53 -inf +8 -16/1 +0 53 -inf +8 53 -inf +8 0 +0 53 -inf +24 53 -inf +8 16/1 +0 53 -inf +inf 53 -inf +inf -32/1 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32/1 +0 53 -inf nan 53 -inf nan -64/1 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan 64/1 +0 53 -1 -1 53 +0 -0 -1/1 +0 53 +0 -0 53 +0 -0 0 +0 53 +1 +1 53 +0 -0 1/1 +0 53 -3 +5 53 +0 +8 -3/1 +0 53 +0 +8 53 +0 +8 0 +0 53 +3 +11 53 +0 +8 3/1 +0 53 -7 +inf 53 +0 +inf -7/1 +0 53 +0 +inf 53 +0 +inf 0 +0 53 +7 +inf 53 +0 +inf 7/1 +0 53 +inf +inf 53 +inf +inf -1/1 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1/1 +0 53 +inf nan 53 +inf nan -1/1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1/1 + +# regular values +0 53 -64 -49 53 -32 -17 -32/1 +0 53 +0 +15 53 -32 -17 32/1 +0 53 -15 -0 53 -32 -17 17/1 + +0 53 0x153456789abcdfp-48 0x123456789abce2 + 53 0x123456789abcdfp-48 0x123456789abcdf 3/1 +1 53 0x3123456789abcdp-52 0x123456789abce2 + 53 0x123456789abcdfp-56 0x123456789abcdf 3/1 +2 53 1 0x10123456789abdp-44 + 53 -0xff 0x123456789abcdfp-52 256/1 +3 53 0xfff 0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 0x1001/1 + +0 53 0xf3456789abcdfp-48 0x123456789abcdc + 53 0x123456789abcdfp-48 0x123456789abcdf -3/1 +1 53 -0x2edcba98765433p-52 0x123456789abcdc + 53 0x123456789abcdfp-56 0x123456789abcdf -3/1 +2 53 -0x1ff -0xfedcba9876543p-44 + 53 -0xff 0x123456789abcdfp-52 -256/1 +3 53 -0x1003 -0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 -0x1001/1 diff --git a/tests/add_si.dat b/tests/add_si.dat new file mode 100644 index 0000000..f8670ba --- /dev/null +++ b/tests/add_si.dat @@ -0,0 +1,88 @@ +# data file for mpfi_add_si +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan -inf 53 nan -inf -3 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3 +0 53 nan -14 53 nan -7 -7 +0 53 nan -7 53 nan -7 0 +0 53 nan -0 53 nan -7 7 +0 53 nan -15 53 nan -0 -15 +0 53 nan -0 53 nan -0 0 +0 53 nan +15 53 nan -0 15 +0 53 nan -30 53 nan +1 -31 +0 53 nan +1 53 nan +1 0 +0 53 nan +32 53 nan +1 31 +0 53 nan +inf 53 nan +inf -63 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63 +0 53 -inf -inf 53 -inf -inf -2 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf +2 +0 53 -inf -11 53 -inf -7 -4 +0 53 -inf -7 53 -inf -7 0 +0 53 -inf -3 53 -inf -7 4 +0 53 -inf -8 53 -inf -0 -8 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf +8 53 -inf -0 8 +0 53 -inf -8 53 -inf +8 -16 +0 53 -inf +8 53 -inf +8 0 +0 53 -inf +24 53 -inf +8 16 +0 53 -inf +inf 53 -inf +inf -32 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf +32 +0 53 -inf nan 53 -inf nan -64 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan +64 +0 53 -1 -1 53 +0 -0 -1 +0 53 +0 -0 53 +0 -0 0 +0 53 +1 +1 53 +0 -0 1 +0 53 -3 +5 53 +0 +8 -3 +0 53 +0 +8 53 +0 +8 0 +0 53 +3 +11 53 +0 +8 3 +0 53 -7 +inf 53 +0 +inf -7 +0 53 +0 +inf 53 +0 +inf 0 +0 53 +7 +inf 53 +0 +inf 7 +0 53 +inf +inf 53 +inf +inf -1 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 +inf nan 53 +inf nan -1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1 + +# regular values +0 53 -64 -49 53 -32 -17 -32 +0 53 +0 +15 53 -32 -17 32 +0 53 -15 -0 53 -32 -17 17 + +0 53 0x153456789abcdfp-48 0x123456789abce2 + 53 0x123456789abcdfp-48 0x123456789abcdf 3 +1 53 0x3123456789abcdp-52 0x123456789abce2 + 53 0x123456789abcdfp-56 0x123456789abcdf 3 +2 53 1 0x10123456789abdp-44 + 53 -0xff 0x123456789abcdfp-52 256 +3 53 0xfff 0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 0x1001 + +0 53 0xf3456789abcdfp-48 0x123456789abcdc + 53 0x123456789abcdfp-48 0x123456789abcdf -3 +1 53 -0x2edcba98765433p-52 0x123456789abcdc + 53 0x123456789abcdfp-56 0x123456789abcdf -3 +2 53 -0x1ff -0xfedcba9876543p-44 + 53 -0xff 0x123456789abcdfp-52 -256 +3 53 -0x1003 -0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 -0x1001 diff --git a/tests/add_ui.dat b/tests/add_ui.dat new file mode 100644 index 0000000..e812c38 --- /dev/null +++ b/tests/add_ui.dat @@ -0,0 +1,61 @@ +# data file for mpfi_add_ui +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3 +0 53 nan -7 53 nan -7 0 +0 53 nan -0 53 nan -7 7 +0 53 nan -0 53 nan -0 0 +0 53 nan +15 53 nan -0 15 +0 53 nan +1 53 nan +1 0 +0 53 nan +32 53 nan +1 31 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 1 +0 53 -inf -7 53 -inf -7 0 +0 53 -inf -6 53 -inf -7 1 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf +2 53 -inf -0 2 +0 53 -inf +8 53 -inf +8 0 +0 53 -inf +12 53 -inf +8 4 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 4 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan 8 +0 53 +0 -0 53 +0 -0 0 +0 53 +1 +1 53 +0 -0 1 +0 53 +0 +8 53 +0 +8 0 +0 53 +3 +11 53 +0 +8 3 +0 53 +0 +inf 53 +0 +inf 0 +0 53 +7 +inf 53 +0 +inf 7 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1 + +# regular values +0 53 +0 +15 53 -32 -17 32 +0 53 -15 -0 53 -32 -17 17 + +0 53 0x153456789abcdfp-48 0x123456789abce2 + 53 0x123456789abcdfp-48 0x123456789abcdf 3 +1 53 0x3123456789abcdp-52 0x123456789abce2 + 53 0x123456789abcdfp-56 0x123456789abcdf 3 +2 53 1 0x10123456789abdp-44 + 53 -0xff 0x123456789abcdfp-52 256 +3 53 0xfff 0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 0x1001 diff --git a/tests/add_z.dat b/tests/add_z.dat new file mode 100644 index 0000000..0218f30 --- /dev/null +++ b/tests/add_z.dat @@ -0,0 +1,88 @@ +# data file for mpfi_add_z +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan -inf 53 nan -inf -3 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3 +0 53 nan -14 53 nan -7 -7 +0 53 nan -7 53 nan -7 0 +0 53 nan -0 53 nan -7 7 +0 53 nan -15 53 nan -0 -15 +0 53 nan -0 53 nan -0 0 +0 53 nan +15 53 nan -0 15 +0 53 nan -30 53 nan +1 -31 +0 53 nan +1 53 nan +1 0 +0 53 nan +32 53 nan +1 31 +0 53 nan +inf 53 nan +inf -63 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63 +0 53 -inf -inf 53 -inf -inf -2 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2 +0 53 -inf -11 53 -inf -7 -4 +0 53 -inf -7 53 -inf -7 0 +0 53 -inf -3 53 -inf -7 4 +0 53 -inf -8 53 -inf -0 -8 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf +8 53 -inf -0 8 +0 53 -inf -8 53 -inf +8 -16 +0 53 -inf +8 53 -inf +8 0 +0 53 -inf +24 53 -inf +8 16 +0 53 -inf +inf 53 -inf +inf -32 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32 +0 53 -inf nan 53 -inf nan -64 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan 64 +0 53 -1 -1 53 +0 -0 -1 +0 53 +0 -0 53 +0 -0 0 +0 53 +1 +1 53 +0 -0 1 +0 53 -3 +5 53 +0 +8 -3 +0 53 +0 +8 53 +0 +8 0 +0 53 +3 +11 53 +0 +8 3 +0 53 -7 +inf 53 +0 +inf -7 +0 53 +0 +inf 53 +0 +inf 0 +0 53 +7 +inf 53 +0 +inf 7 +0 53 +inf +inf 53 +inf +inf -1 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 +inf nan 53 +inf nan -1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1 + +# regular values +0 53 -64 -49 53 -32 -17 -32 +0 53 +0 +15 53 -32 -17 32 +0 53 -15 -0 53 -32 -17 17 + +0 53 0x153456789abcdfp-48 0x123456789abce2 + 53 0x123456789abcdfp-48 0x123456789abcdf 3 +1 53 0x3123456789abcdp-52 0x123456789abce2 + 53 0x123456789abcdfp-56 0x123456789abcdf 3 +2 53 1 0x10123456789abdp-44 + 53 -0xff 0x123456789abcdfp-52 256 +3 53 0xfff 0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 0x1001 + +0 53 0xf3456789abcdfp-48 0x123456789abcdc + 53 0x123456789abcdfp-48 0x123456789abcdf -3 +1 53 -0x2edcba98765433p-52 0x123456789abcdc + 53 0x123456789abcdfp-56 0x123456789abcdf -3 +2 53 -0x1ff -0xfedcba9876543p-44 + 53 -0xff 0x123456789abcdfp-52 -256 +3 53 -0x1003 -0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 -0x1001 diff --git a/tests/asin.dat b/tests/asin.dat new file mode 100644 index 0000000..ce29ae2 --- /dev/null +++ b/tests/asin.dat @@ -0,0 +1,43 @@ +# data file for mpfi_asin +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan -0 53 nan -0 +0 53 +0 nan 53 +0 nan +0 53 nan 0x1921fb54442d19p-52 53 nan +1 +0 53 nan nan 53 +inf nan +0 53 nan nan 53 -inf -inf +0 53 nan nan 53 -inf -7 +0 53 nan -0 53 -inf -0 +0 53 nan nan 53 -inf +8 +0 53 nan nan 53 -inf +inf +1 53 -0x1921fb54442d19p-52 -0 53 -1 -0 +0 53 +0 -0 53 +0 -0 +2 53 +0 0x1921fb54442d19p-52 53 +0 +1 +0 53 +0 nan 53 +0 +8 +0 53 +0 nan 53 +0 +inf +0 53 nan nan 53 +inf +inf + +# regular values +0 53 nan nan 53 -6 -4 +0 53 nan -0x10c152382d7365p-53 53 -2 -0.5 +3 53 -0x1921fb54442d19p-52 -0x10c152382d7365p-53 53 -1 -0.5 +3 53 -0x1b235315c680ddp-53 -0x102be9ce0b87cdp-54 53 -0.75 -0.25 +3 53 -0x860a91c16b9b3p-52 0x860a91c16b9b3p-52 53 -0.5 0.5 +3 53 0x102be9ce0b87cdp-54 0x159aad71ced00fp-53 53 0.25 0.625 +3 53 -0x1921fb54442d19p-52 0x1921fb54442d19p-52 53 -1 1 +0 53 0x8055f06094f0fp-54 nan 53 0.125 17 +0 53 nan nan 53 17 42 +0 53 nan nan 53 -42 17 diff --git a/tests/asinh.dat b/tests/asinh.dat new file mode 100644 index 0000000..8e26976 --- /dev/null +++ b/tests/asinh.dat @@ -0,0 +1,43 @@ +# data file for mpfi_asinh +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan -inf 53 nan -inf +0 53 -0xa9394648daf8fp-50 nan 53 -7 nan +0 53 nan -0 53 nan -0 +0 53 +0 nan 53 +0 nan +0 53 nan 0x1c34366179d427p-53 53 nan +1 +0 53 +inf nan 53 +inf nan +0 53 -inf -inf 53 -inf -inf +2 53 -inf -0x152728c91b5f1dp-51 53 -inf -7 +0 53 -inf -0 53 -inf -0 +2 53 -inf 0x58d8dc657eaf5p-49 53 -inf +8 +0 53 -inf +inf 53 -inf +inf +1 53 -0x1c34366179d427p-53 -0 53 -1 -0 +0 53 +0 -0 53 +0 -0 +2 53 +0 0x1c34366179d427p-53 53 +0 +1 +2 53 +0 0x58d8dc657eaf5p-49 53 +0 +8 +0 53 +0 +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +3 53 -0x4fbca919fe219p-49 -0x10c1f8a6e80eebp-51 53 -6 -4 +3 53 -0x2e32430627a11p-49 -0x1ecc2caec51609p-54 53 -2 -0.5 +3 53 -0x1c34366179d427p-53 -0x1ecc2caec51609p-54 53 -1 -0.5 +3 53 -0x162e42fefa39fp-49 -0xfd67d91ccf31bp-54 53 -0.75 -0.25 +3 53 -0xf661657628b05p-53 0xf661657628b05p-53 53 -0.5 0.5 +3 53 0xfd67d91ccf31bp-54 0x4b89d40b2fecdp-51 53 0.25 0.625 +3 53 -0x1c34366179d427p-53 0x1c34366179d427p-53 53 -1 1 +3 53 0xff5685b4cb4b9p-55 0xe1be0ba541ef7p-50 53 0.125 17 +3 53 0x1c37c174a83dedp-51 0x8dca6976ad6bdp-49 53 17 42 +3 53 -0x8dca6976ad6bdp-49 0xe1be0ba541ef7p-50 53 -42 17 diff --git a/tests/atan.dat b/tests/atan.dat new file mode 100644 index 0000000..48360c9 --- /dev/null +++ b/tests/atan.dat @@ -0,0 +1,43 @@ +# data file for mpfi_atan +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan -0x3243f6a8885a3p-49 53 nan -inf +0 53 -0x16dcc57bb565fdp-52 nan 53 -7 nan +0 53 nan -0 53 nan -0 +0 53 +0 nan 53 +0 nan +0 53 nan 0x1921fb54442d19p-53 53 nan +1 +0 53 0x3243f6a8885a3p-49 nan 53 +inf nan +3 53 -0x1921fb54442d19p-52 -0x3243f6a8885a3p-49 53 -inf -inf +3 53 -0x1921fb54442d19p-52 -0x5b7315eed597fp-50 53 -inf -7 +1 53 -0x1921fb54442d19p-52 -0 53 -inf -0 +3 53 -0x1921fb54442d19p-52 0xb924fd54cb511p-51 53 -inf +8 +3 53 -0x1921fb54442d19p-52 0x1921fb54442d19p-52 53 -inf +inf +1 53 -0x1921fb54442d19p-53 -0 53 -1 -0 +0 53 +0 -0 53 +0 -0 +2 53 +0 0x1921fb54442d19p-53 53 +0 +1 +2 53 +0 0xb924fd54cb511p-51 53 +0 +8 +2 53 +0 0x1921fb54442d19p-52 53 +0 +inf +3 53 0x3243f6a8885a3p-49 0x1921fb54442d19p-52 53 +inf +inf + +# regular values +3 53 -0x167d8863bc99bdp-52 -0x54da32547a73fp-50 53 -6 -4 +3 53 -0x11b6e192ebbe45p-52 -0x1dac670561bb4fp-54 53 -2 -0.5 +3 53 -0x1921fb54442d19p-53 -0x1dac670561bb4fp-54 53 -1 -0.5 +3 53 -0xa4bc7d1934f71p-52 -0x1f5b75f92c80ddp-55 53 -0.75 -0.25 +3 53 -0x1dac670561bb5p-50 0x1dac670561bb5p-50 53 -0.5 0.5 +3 53 0x1f5b75f92c80ddp-55 0x47802eaf7bfadp-51 53 0.25 0.625 +3 53 -0x1921fb54442d19p-53 0x1921fb54442d19p-53 53 -1 1 +3 53 0x1fd5ba9aac2f6dp-56 0x1831516233f561p-52 53 0.125 17 +3 53 0xc18a8b119fabp-47 0x18c079f3350d27p-52 53 17 42 +3 53 -0x18c079f3350d27p-52 0x1831516233f561p-52 53 -42 17 diff --git a/tests/atan2.dat b/tests/atan2.dat new file mode 100644 index 0000000..cc2247d --- /dev/null +++ b/tests/atan2.dat @@ -0,0 +1,54 @@ +# data file for mpfi_atan2 +# +# for a description of the fields: see add.dat + +# special values +0 53 nan nan 53 nan nan 53 -inf -7 +0 53 nan nan 53 nan nan 53 -8 +1 +0 53 nan nan 53 nan nan 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 nan +0 53 nan nan 53 nan nan 53 +5 +inf +0 53 nan nan 53 nan nan 53 +inf +inf +0 53 nan nan 53 nan nan 53 nan -0 +0 53 nan nan 53 nan -0 53 -inf -7 +0 53 nan nan 53 nan -0 53 -8 +1 +0 53 nan nan 53 nan +inf 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 +7 +0 53 nan nan 53 nan -inf 53 +5 +inf +0 53 nan nan 53 nan -7 53 +inf +inf +0 53 nan nan 53 nan +1 53 nan -0 +3 53 -0x12d97c7f3321d3p-51 -0x96cbe3f9990e9p-50 53 -inf -inf 53 -inf -inf +3 53 -0x6d9cc4b34bd0dp-50 -0x1700a7c5784633p-53 53 -inf -7 53 -1 +8 +1 53 -0x1921fb54442d19p-52 -0 53 -inf -0 53 +8 +inf +1 53 -0x1921fb54442d19p-53 -0 53 -inf -0 53 +inf +inf +3 53 -0x1921fb54442d19p-52 0x1921fb54442d19p-52 53 -inf +8 53 +0 +8 +3 53 -0x1921fb54442d19p-52 0x1921fb54442d19p-52 53 -inf +inf 53 +0 +8 +3 53 -0x1921fb54442d19p-51 0x1921fb54442d19p-51 53 +0 -0 53 -inf -7 +3 53 0x3243f6a8885a3p-49 0x1921fb54442d19p-51 53 +0 +8 53 -7 -0 +0 53 +0 -0 53 +0 -0 53 +0 +8 +2 53 +0 0x1921fb54442d19p-52 53 +0 +inf 53 +0 +8 +0 53 +0 -0 53 +0 -0 53 +8 +inf +0 53 nan nan 53 +0 +8 53 +inf nan +3 53 -0x1921fb54442d19p-51 0x1921fb54442d19p-51 53 +0 -0 53 -inf +inf +2 53 +0 0x1921fb54442d19p-51 53 +0 +8 53 -7 +8 +3 53 -0x1921fb54442d19p-51 0x1921fb54442d19p-51 53 +0 -0 53 +0 -0 +2 53 +0 0x1921fb54442d19p-52 53 +0 +inf 53 +0 +8 +0 53 nan nan 53 +0 nan 53 +8 +inf +0 53 +0 -0 53 +0 +8 53 +inf +inf +3 53 0x3243f6a8885a3p-49 0x12d97c7f3321d3p-51 53 +inf +inf 53 -inf +3 +3 53 0x3243f6a8885a3p-50 0x1921fb54442d19p-52 53 +inf +inf 53 +0 +inf +0 53 nan nan 53 +inf +inf 53 +3 nan +0 53 nan nan 53 +inf nan 53 -inf -7 +0 53 nan nan 53 +inf nan 53 +inf +inf +0 53 nan nan 53 +inf nan 53 -3 +7 + +# regular values +3 53 -0x191f6c4c09a81bp-51 -0x1a12a5465464cfp-52 53 -17 -5 53 -4002 -1 +3 12 -0xc9p-6 -0x2bfp-9 53 -17 -5 53 -4002 1 +3 53 -0x1831516233f561p-52 -0xa3c20ea13f5e5p-61 12 -17 -5 53 1 4002 +3 12 -0xc19p-11 0xafdp-11 12 -17 5 53 1 4002 +3 53 0xa3c20ea13f5e5p-61 0x1831516233f561p-52 53 5 17 12 1 4002 +3 12 0x2bfp-9 0xc9p-6 53 5 17 12 -4002 1 +3 53 0x1a12a5465464cfp-52 0x191f6c4c09a81bp-51 12 5 17 12 -4002 -1 +3 12 -0xc91p-10 0xc91p-10 12 -17 5 12 -4002 -1 +3 53 -0x1921fb54442d19p-51 0x1921fb54442d19p-51 53 -17 5 53 -4002 1 \ No newline at end of file diff --git a/tests/atanh.dat b/tests/atanh.dat new file mode 100644 index 0000000..6ec0f04 --- /dev/null +++ b/tests/atanh.dat @@ -0,0 +1,46 @@ +# data file for mpfi_atanh +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 -inf nan 53 -1 nan +0 53 nan -0 53 nan -0 +0 53 +0 nan 53 +0 nan +0 53 nan +inf 53 nan +1 +0 53 nan nan 53 +inf nan +0 53 nan nan 53 -inf -inf +0 53 nan nan 53 -inf -7 +0 53 nan -0x8c9f53d568185p-52 53 -inf -0.5 +0 53 nan -0 53 -inf -0 +0 53 nan +inf 53 -inf +1 +0 53 nan nan 53 -inf +8 +0 53 nan nan 53 -inf +inf +0 53 -inf -0 53 -1 -0 +0 53 +0 -0 53 +0 -0 +0 53 +0 +inf 53 +0 +1 +0 53 +0 nan 53 +0 +8 +0 53 +0 nan 53 +0 +inf +0 53 nan nan 53 +inf +inf + +# regular values +0 53 nan nan 53 -6 -4 +0 53 nan -0x8c9f53d568185p-52 53 -2 -0.5 +2 53 -inf -0x8c9f53d568185p-52 53 -1 -0.5 +3 53 -0x3e44e55c64b4bp-50 -0x1058aefa811451p-54 53 -0.75 -0.25 +3 53 -0x1193ea7aad030bp-53 0x1193ea7aad030bp-53 53 -0.5 0.5 +3 53 0x1058aefa811451p-54 0x2eec3bb76c2b3p-50 53 0.25 0.625 +0 53 -inf +inf 53 -1 1 +1 53 0x1015891c9eaef7p-55 +inf 53 0.125 1 +0 53 0x1015891c9eaef7p-55 nan 53 0.125 17 +0 53 nan nan 53 17 42 +0 53 nan nan 53 -42 17 diff --git a/tests/bisect.dat b/tests/bisect.dat new file mode 100644 index 0000000..b75e18c --- /dev/null +++ b/tests/bisect.dat @@ -0,0 +1,60 @@ +# data file for mpfi_bisect +# +# column fields: +# 1: return value +# 2: precision of left half +# 3: left endpoint value of left half +# 4: right endpoint value of left half +# 5: precision of right half +# 6: left endpoint value of right half +# 7: right endpoint value of right half +# +# 8: precision of input argument +# 9: left endpoint value of input argument +# 10: right endpoint value of input argument +# + +# special values +0 53 nan nan 53 nan nan 53 nan -inf +0 53 nan nan 53 nan nan 53 nan -8 +0 53 nan nan 53 nan nan 53 -8 nan +0 53 nan nan 53 nan nan 53 nan -0 +0 53 nan nan 53 nan nan 53 +0 nan +0 53 nan nan 53 nan nan 53 nan 5 +0 53 nan nan 53 nan nan 53 5 nan +0 53 nan nan 53 nan nan 53 nan +inf +0 53 nan nan 53 nan nan 53 nan nan +0 53 -inf -inf 53 nan nan 53 -inf -inf +0 53 -inf -8 53 nan nan 53 -inf -8 +0 53 -inf -0 53 nan nan 53 -inf -0 +0 53 -inf 5 53 nan nan 53 -inf 5 +0 53 -inf +inf 53 nan nan 53 -inf +inf +0 53 nan nan 53 nan nan 53 -inf nan +0 53 -8 -4 53 -4 -0 53 -8 -0 +0 53 +0 -0 53 +0 -0 53 +0 -0 +0 53 +0 2.5 53 2.5 5 53 +0 5 +0 53 +0 +inf 53 nan nan 53 +0 +inf +0 53 5 +inf 53 nan nan 53 5 +inf +0 53 +inf +inf 53 nan nan 53 +inf +inf +0 53 nan nan 53 nan nan 53 +inf nan + +# regular values +# same precision: [2, 2^53] -> [2, 2^52+1] u [2^52+1, 2^53] +0 53 2 0x10000000000001 + 53 0x10000000000001 0x1p+53 + 53 2 0x1p+53 + +# double rounding error: it should be [1, 2^53+2] u [2^53, 2^54] +- 52 1 0x1p+53 + 52 0x1p+53 0x1p+54 + 53 1 0x1p+54 + +# double rounding error: it should be [1, 2^52+1] u [2^52, 2^53] +- 53 1 0x1p+52 + 2 0x1p+52 0x1p+53 + 2 1 0x1p+53 + +# double rounding error: it should be [-1, 8] u [7, 16] ++ 2 -1 8 + 3 8 16 + 2 -1 16 diff --git a/tests/blow.dat b/tests/blow.dat new file mode 100644 index 0000000..a602225 --- /dev/null +++ b/tests/blow.dat @@ -0,0 +1,106 @@ +# data file for mpfi_blow +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of second parameter +# 8: second parameter value + +#WARNING: +# double values are read by the test suite with rounding towards minus +# infinity to a machine-dependant precision (whereas the mpfi data are read +# at the given precision with rounding to the nearest). +# So as to ensure portability, use test values that are representable with a +# 53 bit-significand which corresponds to the minimum default precision for +# a double in the test suite. + +# special values +0 53 nan nan 53 nan nan -0x170ef54646d497p-109 +0 53 nan nan 53 nan nan 0.0 +0 53 nan nan 53 nan nan 0x170ef54646d497p-109 +0 53 nan nan 53 nan -inf -0x114b37f4b51f71p-107 +0 53 nan nan 53 nan -inf 0.0 +0 53 nan nan 53 nan -inf 0x114b37f4b51f71p-107 +0 53 nan nan 53 nan -7 -0xfc339ab0a6b53p-99 +0 53 nan nan 53 nan -7 0.0 +0 53 nan nan 53 nan -7 7.0 +0 53 nan nan 53 nan -0 -15.0 +0 53 nan nan 53 nan -0 0.0 +0 53 nan nan 53 nan -0 15.0 +0 53 nan nan 53 nan +1 -0xb2b3ece0a4ef9p-103 +0 53 nan nan 53 nan +1 0.0 +0 53 nan nan 53 nan +1 0xb2b3ece0a4ef9p-103 +0 53 nan nan 53 nan +inf -0x5acae5c4b6e51p-101 +0 53 nan nan 53 nan +inf 0.0 +0 53 nan nan 53 nan +inf 0x5acae5c4b6e51p-101 + +#no definite center in infinite intervals +0 53 nan nan 53 -inf -inf -0x170ef54646d497p-108 +0 53 nan nan 53 -inf -inf 0.0 +0 53 nan nan 53 -inf -inf 0x170ef54646d497p-108 +0 53 -inf nan 53 -inf -7 -0x170ef54646d497p-107 +0 53 -inf nan 53 -inf -7 0.0 +0 53 -inf nan 53 -inf -7 0x170ef54646d497p-107 +0 53 -inf nan 53 -inf -0 -0x170ef54646d497p-106 +0 53 -inf nan 53 -inf -0 0.0 +0 53 -inf nan 53 -inf -0 0x170ef54646d497p-106 +0 53 -inf nan 53 -inf 8 -0x16345785d8a00000 +0 53 -inf nan 53 -inf 8 0.0 +0 53 -inf nan 53 -inf 8 0x16345785d8a00000 +0 53 nan nan 53 -inf +inf -0x170ef54646d497p-105 +0 53 nan nan 53 -inf +inf 0.0e-17 +0 53 nan nan 53 -inf +inf +0x170ef54646d497p-105 +0 53 nan nan 53 -inf nan -0x170ef54646d497p-104 +0 53 nan nan 53 -inf nan 0.0e-17 +0 53 nan nan 53 -inf nan +0x170ef54646d497p-104 + +0 53 +0 -0 + 53 +0 -0 -0x170ef54646d497p-109 +0 53 +0 -0 + 53 +0 -0 0.0 +0 53 +0 -0 + 53 +0 -0 0x170ef54646d497p-109 +3 53 -0x1p-49 0x10000000000001p-49 + 53 +0 8 -0x3p-53 +3 53 -0x1p-50 0x10000000000001p-49 + 53 +0 8 -0x1p-53 +3 53 -0x1p-50 0x10000000000001p-49 + 53 +0 8 -0x114b37f4b51f71p-107 +0 53 +0 8 + 53 +0 8 0.0 +0 53 -1 9 + 53 +0 8 0.25 +3 53 -0x1p-50 0x10000000000001p-49 + 53 +0 8 0x114b37f4b51f7p-103 + +#no definite center in infinite intervals +0 53 nan +inf 53 +0 +inf -0x50b45a75f7e81p-104 +0 53 nan +inf 53 +0 +inf 0.0 +0 53 nan +inf 53 +0 +inf 0x142d169d7dfa03p-106 +0 53 nan nan 53 +inf +inf -0x170ef54646d497p-109 +0 53 nan nan 53 +inf +inf 0.0 +0 53 nan nan 53 +inf +inf 0x170ef54646d497p-109 +0 53 nan nan 53 +inf nan -0x170ef54646d497p-109 +0 53 nan nan 53 +inf nan 0.0 +0 53 nan nan 53 +inf nan 0x170ef54646d497p-109 + +# regular values +0 53 -48 -0 + 53 -32 -16 -2.0 +3 53 -0x10000000000002p-51 0x10000000000001p-51 + 53 -0x10000000000001p-52 1 1.0 + +0 04 -8 8 + 53 -1 1 7.0 +1 04 -18 3 + 53 -15 1 0.25 + +0 53 0 4 + 53 0x3p-1 0x5p-1 3.0 +2 53 0x1p-1 0x10000000000002 + 53 0x1 0x10000000000001 0x1p-52 diff --git a/tests/bounded_p.dat b/tests/bounded_p.dat new file mode 100644 index 0000000..5fdea77 --- /dev/null +++ b/tests/bounded_p.dat @@ -0,0 +1,41 @@ +# data file for mpfi_bounded_p +# +# column fields: +# 1: return value (0: false, +: true) +# 2: precision of argument +# 3: left endpoint value of argument +# 4: right endpoint value of argument +# + +# special values +0 53 nan -inf +0 53 nan -8 +0 53 -8 nan +0 53 nan -0 +0 53 +0 nan +0 53 nan 5 +0 53 5 nan +0 53 nan +inf +0 53 nan nan +0 53 -inf -inf +0 53 -inf -8 +0 53 -inf -0 +0 53 -inf 5 +0 53 -inf +inf +0 53 -inf nan ++ 53 -8 -0 ++ 53 +0 -0 ++ 53 +0 5 +0 53 +0 +inf +0 53 5 +inf +0 53 +inf +inf +0 53 +inf nan + +# regular values ++ 8 -34 -17 ++ 8 -8 -1 ++ 8 -34 17 ++ 53 -0x1921fb54442d18p-51 0x1921fb54442d19p-51 ++ 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 ++ 53 +8 +0x7fffffffffffbp+51 ++ 53 +0x1fffffffffffffp-53 2 diff --git a/tests/cbrt.dat b/tests/cbrt.dat new file mode 100644 index 0000000..5317ff9 --- /dev/null +++ b/tests/cbrt.dat @@ -0,0 +1,31 @@ +# data file for mpfi_cbrt +# +# column fields: see neg.dat + +# special values +0 53 nan nan 53 nan nan +0 53 nan -inf 53 nan -inf +0 53 -4 nan 53 -64 nan +0 53 nan -0 53 nan -0 +0 53 +0 nan 53 +0 nan +0 53 nan +1 53 nan +1 +0 53 +inf nan 53 +inf nan +0 53 -inf -inf 53 -inf -inf +0 53 -inf -5 53 -inf -125 +0 53 -inf -0 53 -inf -0 +0 53 -inf +4 53 -inf +64 +0 53 -inf +inf 53 -inf +inf +0 53 +0 -0 53 +0 -0 +0 53 +0 +3 53 +0 +27 +0 53 +0 +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +0 53 4 5 + 53 0x40 0x7d +1 53 -0x2e5e58c0083b7bp-154 6 + 53 -0x1856e4be527197p-354 0xd8 +2 53 -3 0x23f19d36b0a0bbp-459 + 53 -0x1b 0x16acbb5e3f08a3p-1270 +3 53 0x2b8172e535d44dp-385 0x24cbd1c55aaa1p-258 + 53 0x141a9019a2184dp-1047 0xc29c78c66ac0fp-678 diff --git a/tests/check_data.c b/tests/check_data.c new file mode 100644 index 0000000..37617ed --- /dev/null +++ b/tests/check_data.c @@ -0,0 +1,47 @@ +/* check_data.c -- Tests from data file. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +/* public main function */ + +void +check_data (mpfi_function_ptr function, const char *file_name) +{ + FILE *fp; + + fp = open_file (file_name); + init_reading (fp); + + while (nextchar != EOF) { + function->read_line (function, fp); + function->check_line (function); + } + + close_file (fp); +} diff --git a/tests/const_catalan.dat b/tests/const_catalan.dat new file mode 100644 index 0000000..51ad54d --- /dev/null +++ b/tests/const_catalan.dat @@ -0,0 +1,5 @@ +# data file for mpfi_const_catalan +# +3 1021 + 0x1d4f9713e8135d08a42b045c6fa65a18c7d887c270385ff012944c7cb4799aedf29b80b148ddd8b0b1f249acc7ee73885d92bf1b425e2d7f8b176418fe40c74d8dedbca019729e6b19fbd908570a3eef7b44aa5059c124142ffe9fe8ce71f1cb4f8dcd131eb40305a86eb34ead01a038d186f000a276751baeccd35f2335d9dp-1017 + 0x1d4f9713e8135d08a42b045c6fa65a18c7d887c270385ff012944c7cb4799aedf29b80b148ddd8b0b1f249acc7ee73885d92bf1b425e2d7f8b176418fe40c74d8dedbca019729e6b19fbd908570a3eef7b44aa5059c124142ffe9fe8ce71f1cb4f8dcd131eb40305a86eb34ead01a038d186f000a276751baeccd35f2335d9d1p-1021 diff --git a/tests/const_euler.dat b/tests/const_euler.dat new file mode 100644 index 0000000..5977673 --- /dev/null +++ b/tests/const_euler.dat @@ -0,0 +1,5 @@ +# data file for mpfi_const_euler +# +3 1021 + 0x12788cfc6fb618f49a37c7f0202a596ad439d9875ecb980321807be68e135ff7b1c96b3f40753e1dda0c93996c420afa220ad5d226426b411c8768ce7ae975fd4b1bd70f1990dae67b7cf7e702a966d9f152da2acf133555c1813a9916d6f70dfa543d43bcc5ff0c87d8f84e304f2ee44bcd585e17ac38e8d2c2a85479c77d4bp-1021 + 0x49e233f1bed863d268df1fc080a965ab50e7661d7b2e600c8601ef9a384d7fdec725acfd01d4f87768324e65b1082be8882b57489909ad04721da339eba5d7f52c6f5c3c66436b99edf3df9c0aa59b67c54b68ab3c4cd5570604ea645b5bdc37e950f50ef317fc321f63e138c13cbb912f3561785eb0e3a34b0aa151e71df53p-1019 diff --git a/tests/const_log2.dat b/tests/const_log2.dat new file mode 100644 index 0000000..764f201 --- /dev/null +++ b/tests/const_log2.dat @@ -0,0 +1,5 @@ +# data file for mpfi_const_log2 +# +3 1021 + 0x2c5c85fdf473de6af278ece600fcbdabd03cd0c99ca62d8b628345d6e2eabe8af9ee1d881b7aeb26156554bed2be86c43b4bab8d704e085109d5ceca445a6e094fa5b2858892ba3146b2f6844c5f0e1fae7aa6f0ec4d980ec95be83b1d95fdd2dcb3a1ec67595232bd77e9af4e0c0c921957e861cbc838e8b68b65f143cff57p-1018 + 0x162e42fefa39ef35793c7673007e5ed5e81e6864ce5316c5b141a2eb71755f457cf70ec40dbd75930ab2aa5f695f43621da5d5c6b827042884eae765222d3704a7d2d942c4495d18a3597b42262f870fd73d53787626cc0764adf41d8ecafee96e59d0f633aca9195ebbf4d7a70606490cabf430e5e41c745b45b2f8a1e7fab9p-1021 diff --git a/tests/const_pi.dat b/tests/const_pi.dat new file mode 100644 index 0000000..4cb4799 --- /dev/null +++ b/tests/const_pi.dat @@ -0,0 +1,5 @@ +# data file for mpfi_const_pi +# +3 1021 + 0x1921fb54442d18469898cc51701b839a252049c1114cf98e804177d4c76273644a29410f31c6809bbdf2a33679a748636605614dbe4be286e9fc26adadaa3848bc90b6aecc4bcfd8de89885d34c6fdad617feb96de80d6fdbdc70d7f6b5133f4b5d3e4822f8963fcc9250cca3d9c8b67b8400f97142c77e0b31b4906c38aba73p-1019 + 0x6487ed5110b4611a62633145c06e0e68948127044533e63a0105df531d89cd9128a5043cc71a026ef7ca8cd9e69d218d98158536f92f8a1ba7f09ab6b6a8e122f242dabb312f3f637a262174d31bf6b585ffae5b7a035bf6f71c35fdad44cfd2d74f9208be258ff324943328f6722d9ee1003e5c50b1df82cc6d241b0e2ae9dp-1017 diff --git a/tests/cos.dat b/tests/cos.dat new file mode 100644 index 0000000..477f20b --- /dev/null +++ b/tests/cos.dat @@ -0,0 +1,73 @@ +# data file for mpfi_cos +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 -inf nan +0 53 nan nan 53 -inf -inf +0 53 -1 1 53 -inf -7 +0 53 -1 1 53 -inf -0 +0 53 -1 1 53 -inf +8 +0 53 -1 1 53 -inf +inf +1 53 0x114a280fb5068bp-53 1 53 -1 -0 +0 53 1 1 53 +0 -0 +1 53 0x114a280fb5068bp-53 1 53 +0 +1 +0 53 -1 1 53 +0 +8 +0 53 -1 1 53 +0 +inf +0 53 nan nan 53 +inf +inf + +# regular values +3 53 -0x1aa22657537205p-54 0x1c1528065b7d5p-49 53 -2 -0.5 +3 53 0x114a280fb5068bp-53 0xf80aa4fbef751p-52 53 -1 -0.25 +1 53 0x1c1528065b7d4fp-53 1 53 -0.5 0.5 +0 53 -1 1 53 -4.5 0.625 +3 53 -1 0x4528a03ed41a3p-51 53 1 0x3243f6a8885a3p-48 +0 53 -1 1 53 0.125 17 +0 53 -1 1 53 17 42 + +0 53 -1 1 53 -7 1 +0 53 -1 1 53 -7 -0 +0 53 -1 1 53 -7 -1 +0 53 -1 1 53 -7 -2 +0 53 -1 1 53 -7 -3 +1 53 -0x14eaa606db24c1p-53 1 53 -7 -4 +1 53 0x122785706b4ad9p-54 1 53 -7 -5 +1 53 0x181ff79ed92017p-53 1 53 -7 -6 +3 53 0x181ff79ed92017p-53 0x181ff79ed92018p-53 53 -7 -7 + +0 53 -1 1 53 -6 1 +0 53 -1 1 53 -6 -0 +2 53 -1 0x1eb9b7097822f6p-53 53 -6 -1 +2 53 -1 0x1eb9b7097822f6p-53 53 -6 -2 +2 53 -1 0x1eb9b7097822f6p-53 53 -6 -3 +3 53 -0x14eaa606db24c1p-53 0x1eb9b7097822f6p-53 53 -6 -4 +3 53 0x122785706b4ad9p-54 0x1eb9b7097822f6p-53 53 -6 -5 +3 53 0x1eb9b7097822f5p-53 0x1eb9b7097822f6p-53 53 -6 -6 + +0 53 -1 1 53 -5 1 +0 53 -1 1 53 -5 -0 +2 53 -1 0x114a280fb5068cp-53 53 -5 -1 +2 53 -1 0x122785706b4adap-54 53 -5 -2 +2 53 -1 0x122785706b4adap-54 53 -5 -3 +3 53 -0x14eaa606db24c1p-53 0x122785706b4adap-54 53 -5 -4 +3 53 0x122785706b4ad9p-54 0x122785706b4adap-54 53 -5 -5 + +0 53 -1 1 53 -4 1 +0 53 -1 1 53 -4 -0 +2 53 -1 0x114a280fb5068cp-53 53 -4 -1 +2 53 -1 -0x1aa22657537204p-54 53 -4 -2 +2 53 -1 -0x14eaa606db24c0p-53 53 -4 -3 +3 53 -0x14eaa606db24c1p-53 -0x14eaa606db24c0p-53 53 -4 -4 diff --git a/tests/cosh.dat b/tests/cosh.dat new file mode 100644 index 0000000..4eb4896 --- /dev/null +++ b/tests/cosh.dat @@ -0,0 +1,37 @@ +# data file for mpfi_cosh +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 -inf nan +0 53 +inf +inf 53 -inf -inf +1 53 0x11228949ba3a8bp-43 +inf 53 -inf -7 +0 53 1 +inf 53 -inf -0 +0 53 1 +inf 53 -inf +8 +0 53 1 +inf 53 -inf +inf +2 53 1 0x18b07551d9f551p-52 53 -1 -0 +0 53 1 1 53 +0 -0 +2 53 1 0x18b07551d9f551p-52 53 +0 +1 +2 53 1 0x1749eaa93f4e77p-42 53 +0 +8 +0 53 1 +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +2 53 1 0x10200aac16db6fp-52 53 -0.125 -0 +2 53 1 0x120ac1862ae8d1p-52 53 0 0x10000000000001p-53 +3 53 0x99d310a496b6dp-51 0x1681ceb0641359p-47 53 -4.5 -0.625 +3 53 0x18b07551d9f55p-48 0x1422a497d6185fp-49 53 1 3 +3 53 0x1709348c0ea503p-29 0x3ffffffffffa34p+968 53 17 0xb145bb71d3dbp-38 diff --git a/tests/cot.dat b/tests/cot.dat new file mode 100644 index 0000000..cf1a15d --- /dev/null +++ b/tests/cot.dat @@ -0,0 +1,50 @@ +# data file for mpfi_cot +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 -inf nan +0 53 nan nan 53 -inf -inf +0 53 -inf +inf 53 -inf -7 +0 53 -inf +inf 53 -inf -0 +0 53 -inf +inf 53 -inf +8 +0 53 -inf +inf 53 -inf +inf +0 53 -inf +inf 53 -8 -0 +2 53 -inf 0xe07cf2eb32f0bp-49 53 -3 -0 +2 53 -inf -0x148c05d04e1cfdp-53 53 -1 -0 +0 53 nan nan 53 +0 -0 +1 53 0x148c05d04e1cfdp-53 +inf 53 +0 +1 +1 53 -0xe07cf2eb32f0bp-49 +inf 53 +0 +3 +0 53 -inf +inf 53 +0 +8 +0 53 -inf +inf 53 +0 +inf +0 53 nan nan 53 +inf +inf + +# regular values + +3 53 0x1d4a42e92faa4dp-54 0xe07cf2eb32f0bp-49 53 -3 -2 +3 53 0x5cb3b399d747fp-103 0xe07cf2eb32f0bp-49 + 53 -3 -0x1921fb54442d19p-52 +0 53 -inf +inf + 53 -2 0x1921fb54442d19p-52 +3 53 0xea4d6bf23e051p-51 0x1fd549f047f2bbp-50 53 0.125 0.5 +3 53 -0x172cece675d1fdp-105 0x1fd549f047f2bbp-50 + 53 0.125 0x1921fb54442d19p-52 +0 53 -inf +inf + 53 0x1921fb54442d19p-52 4 +3 53 -0x1d02967c31cdb5p-1 0x1ba35ba1c6b75dp-53 + 53 4 0x3243f6a8885a3p-47 +3 53 0x148c05d04e1fb7p-53 0x1cefdde7c84c27p-4 + 53 0x13a28c59d5433bp-44 0x9d9462ceaa19dp-43 diff --git a/tests/coth.dat b/tests/coth.dat new file mode 100644 index 0000000..336ad71 --- /dev/null +++ b/tests/coth.dat @@ -0,0 +1,41 @@ +# data file for mpfi_coth +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 -inf nan +0 53 -1 -1 53 -inf -inf +1 53 -0x100001be6c882fp-52 -1 53 -inf -7 +# Note: mpfr_coth(+/- 0) returned a wrong value up to mpfr-2.4.2 +0 53 -inf -1 53 -inf -0 +0 53 -inf +inf 53 -inf +8 +0 53 -inf +inf 53 -inf +inf +2 53 -inf -0x1000003c6ab7e7p-52 53 -8 -0 +2 53 -inf -0x10145b3cc9964bp-52 53 -3 -0 +2 53 -inf -0x150231499b6b1dp-52 53 -1 -0 +0 53 -inf +inf 53 +0 -0 +1 53 0x150231499b6b1dp-52 +inf 53 +0 +1 +1 53 0x10145b3cc9964bp-52 +inf 53 +0 +3 +1 53 0x1000003c6ab7e7p-52 +inf 53 +0 +8 +0 53 1 +inf 53 +0 +inf +0 53 1 1 53 +inf +inf + +# regular values +0 53 -inf +inf 53 -3 2 +3 53 -0x1000003c6ab7e8p-52 -0x100000011b4865p-52 53 -10 -8 +3 53 0x1000000000000fp-52 0x100001be6c882fp-52 53 7 17 +3 53 0x114fc6ceb099bdp-51 0x10005554fa502fp-46 + 53 0x10000000000001p-58 0x10000000000001p-53 diff --git a/tests/csc.dat b/tests/csc.dat new file mode 100644 index 0000000..6bcbc9c --- /dev/null +++ b/tests/csc.dat @@ -0,0 +1,149 @@ +# data file for mpfi_csc +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 -inf nan +0 53 nan nan 53 -inf -inf +0 53 -inf +inf 53 -inf -7 +0 53 -inf +inf 53 -inf -0 +0 53 -inf +inf 53 -inf 8 +0 53 -inf +inf 53 -inf +inf +0 53 -inf +inf 53 -8 -0 +0 53 -inf -1 53 -3 -0 + +2 53 -inf -0x1303aa9620b223p-52 53 -1 -0 + +0 53 -inf +inf 53 +0 -0 + +1 53 0x1303aa9620b223p-52 +inf 53 +0 +1 + +0 53 1 +inf 53 +0 3 +0 53 -inf +inf 53 +0 8 +0 53 -inf +inf 53 +0 +inf +0 53 nan nan 53 +inf +inf + +# regular values +0 53 -inf +inf 53 -6 7 +0 53 -inf +inf 53 -6 6 +0 53 -inf +inf 53 -6 5 +0 53 -inf +inf 53 -6 4 +0 53 -inf +inf 53 -6 3 +0 53 -inf +inf 53 -6 2 +0 53 -inf +inf 53 -6 1 +0 53 -inf +inf 53 -6 -0 +0 53 -inf +inf 53 -6 -1 +0 53 -inf +inf 53 -6 -2 +0 53 -inf +inf 53 -6 -3 +2 53 1 0x1ca19615f903dap-51 53 -6 -4 +3 53 0x10af73f9df86b7p-52 0x1ca19615f903dap-51 53 -6 -5 +3 53 0x1ca19615f903d9p-51 0x1ca19615f903dap-51 53 -6 -6 + +0 53 -inf +inf 53 -5 7 +0 53 -inf +inf 53 -5 6 +0 53 -inf +inf 53 -5 5 +0 53 -inf +inf 53 -5 4 +0 53 -inf +inf 53 -5 3 +0 53 -inf +inf 53 -5 2 +0 53 -inf +inf 53 -5 1 +0 53 -inf +inf 53 -5 -0 +0 53 -inf +inf 53 -5 -1 +0 53 -inf +inf 53 -5 -2 +0 53 -inf +inf 53 -5 -3 +2 53 1 0x15243e8b2f4642p-52 53 -5 -4 +3 53 0x10af73f9df86b7p-52 0x10af73f9df86b8p-52 53 -5 -5 + +0 53 -inf +inf 53 -4 7 +0 53 -inf +inf 53 -4 6 +0 53 -inf +inf 53 -4 5 +0 53 -inf +inf 53 -4 4 +0 53 -inf +inf 53 -4 3 +0 53 -inf +inf 53 -4 2 +0 53 -inf +inf 53 -4 1 +0 53 -inf +inf 53 -4 -0 +0 53 -inf +inf 53 -4 -1 +0 53 -inf +inf 53 -4 -2 +0 53 -inf +inf 53 -4 -3 +3 53 0x15243e8b2f4641p-52 0x15243e8b2f4642p-52 53 -4 -4 + +0 53 -inf +inf 53 -3 7 +0 53 -inf +inf 53 -3 6 +0 53 -inf +inf 53 -3 5 +0 53 -inf +inf 53 -3 4 +0 53 -inf +inf 53 -3 3 +0 53 -inf +inf 53 -3 2 +0 53 -inf +inf 53 -3 1 +0 53 -inf -1 53 -3 -0 +1 53 -0x1c583c440ab0dap-50 -1 53 -3 -1 +3 53 -0x1c583c440ab0dap-50 -0x119893a272f912p-52 53 -3 -2 +3 53 -0x1c583c440ab0dap-50 -0x1c583c440ab0d9p-50 53 -3 -3 + +0 53 -inf +inf 53 -2 7 +0 53 -inf +inf 53 -2 6 +0 53 -inf +inf 53 -2 5 +0 53 -inf +inf 53 -2 4 +0 53 -inf +inf 53 -2 3 +0 53 -inf +inf 53 -2 2 +0 53 -inf +inf 53 -2 1 +0 53 -inf -1 53 -2 -0 +1 53 -0x1303aa9620b224p-52 -1 53 -2 -1 +3 53 -0x119893a272f913p-52 -0x119893a272f912p-52 53 -2 -2 + +0 53 -inf +inf 53 -1 7 +0 53 -inf +inf 53 -1 6 +0 53 -inf +inf 53 -1 5 +0 53 -inf +inf 53 -1 4 +0 53 -inf +inf 53 -1 3 +0 53 -inf +inf 53 -1 2 +0 53 -inf +inf 53 -1 1 +2 53 -inf -0x1303aa9620b223p-52 53 -1 -0 +3 53 -0x1303aa9620b224p-52 -0x1303aa9620b223p-52 53 -1 -1 + +0 53 -inf +inf 53 1 7 +0 53 -inf +inf 53 1 6 +0 53 -inf +inf 53 1 5 +0 53 -inf +inf 53 1 4 +2 53 1 0x1c583c440ab0dap-50 53 1 3 +2 53 1 0x1303aa9620b224p-52 53 1 2 +3 53 0x1303aa9620b223p-52 0x1303aa9620b224p-52 53 1 1 + +0 53 -inf +inf 53 2 7 +0 53 -inf +inf 53 2 6 +0 53 -inf +inf 53 2 5 +0 53 -inf +inf 53 2 4 +3 53 0x119893a272f912p-52 0x1c583c440ab0dap-50 53 2 3 +3 53 0x119893a272f912p-52 0x119893a272f913p-52 53 2 2 + +0 53 -inf +inf 53 3 7 +0 53 -inf +inf 53 3 6 +0 53 -inf +inf 53 3 5 +0 53 -inf +inf 53 3 4 +3 53 0x1c583c440ab0d9p-50 0x1c583c440ab0dap-50 53 3 3 + +0 53 -inf +inf 53 4 7 +1 53 -0x1ca19615f903dap-51 -1 53 4 6 +1 53 -0x15243e8b2f4642p-52 -1 53 4 5 +3 53 -0x15243e8b2f4642p-52 -0x15243e8b2f4641p-52 53 4 4 + +0 53 -inf +inf 53 5 7 +3 53 -0x1ca19615f903dap-51 -0x10af73f9df86b7p-52 53 5 6 +3 53 -0x10af73f9df86b8p-52 -0x10af73f9df86b7p-52 53 5 5 + +0 53 -inf +inf 53 6 7 +3 53 -0x1ca19615f903dap-51 -0x1ca19615f903d9p-51 53 6 6 + +3 53 +0x185a86a4ceb06cp-52 +0x185a86a4ceb06dp-52 53 7 7 + diff --git a/tests/csch.dat b/tests/csch.dat new file mode 100644 index 0000000..b65313b --- /dev/null +++ b/tests/csch.dat @@ -0,0 +1,40 @@ +# data file for mpfi_csch +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 -inf nan +0 53 +0 -0 53 -inf -inf +1 53 -0x1de16d3cffcd54p-62 -0 53 -inf -7 +0 53 -inf -0 53 -inf -0 +0 53 -inf +inf 53 -inf +8 +0 53 -inf +inf 53 -inf +inf +2 53 -inf -0x15fc212d92371ap-63 53 -8 -0 +2 53 -inf -0x198de80929b901p-56 53 -3 -0 +2 53 -inf -0x1b3ab8a78b90c0p-53 53 -1 -0 +0 53 -inf +inf 53 +0 -0 +1 53 0x1b3ab8a78b90c0p-53 +inf 53 +0 +1 +1 53 0x198de80929b901p-56 +inf 53 +0 +3 +1 53 0x15fc212d92371ap-63 +inf 53 +0 +8 +0 53 +0 +inf 53 +0 +inf +0 53 +0 -0 53 +inf +inf + +# regular values +0 53 -inf +inf 53 -3 2 +3 53 -0x15fc212d92371bp-63 -0x17cd79b63733a0p-66 53 -10 -8 +3 53 0x1639e3175a68a7p-76 0x1de16d3cffcd54p-62 53 7 17 +3 53 0x1eb45dc88defeap-52 0x3fff555693e722p-48 + 53 0x10000000000001p-58 0x10000000000001p-53 diff --git a/tests/d_div.dat b/tests/d_div.dat new file mode 100644 index 0000000..7c2af26 --- /dev/null +++ b/tests/d_div.dat @@ -0,0 +1,86 @@ +# data file for mpfi_d_div +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: first parameter value +# 6: precision of second parameter +# 7: left endpoint value of second parameter +# 8: right endpoint value of second parameter + +#WARNING: +# double values are read by the test suite with rounding towards minus +# infinity to a machine-dependant precision (whereas the mpfi data are read +# at the given precision with rounding to the nearest). +# So as to ensure portability, use test values that are representable with a +# 53 bit-significand which corresponds to the minimum default precision for +# a double in the test suite. + +# special values +0 53 nan nan -0x170ef54646d497p-109 53 nan nan +0 53 nan nan 0.0 53 nan nan +0 53 nan nan 0x170ef54646d497p-109 53 nan nan +0 53 nan nan -0x114b37f4b51f71p-107 53 nan -inf +0 53 nan nan 0.0 53 nan -inf +0 53 nan nan 0x114b37f4b51f71p-107 53 nan -inf +0 53 nan nan -0xfc339ab0a6b53p-99 53 nan -7 +0 53 nan nan 0.0 53 nan -7 +0 53 nan nan 7.0 53 nan -7 +0 53 nan nan -15.0 53 nan -0 +0 53 nan nan 0.0 53 nan -0 +0 53 nan nan 15.0 53 nan -0 +0 53 nan nan -0xb2b3ece0a4ef9p-103 53 nan 1 +0 53 nan nan 0.0 53 nan 1 +0 53 nan nan 0xb2b3ece0a4ef9p-103 53 nan 1 +0 53 nan nan -0x5acae5c4b6e51p-101 53 nan +inf +0 53 nan nan 0.0 53 nan +inf +0 53 nan nan 0x5acae5c4b6e51p-101 53 nan +inf +0 53 +0 -0 -0x170ef54646d497p-108 53 -inf -inf +0 53 +0 -0 0.0 53 -inf -inf +0 53 +0 -0 0x170ef54646d497p-108 53 -inf -inf +2 53 +0 0x1a5a3ce29a1787p-110 -0x170ef54646d496p-107 53 -inf -7 +0 53 +0 -0 0.0 53 -inf -7 +1 53 -0x1a5a3ce29a1787p-110 -0 0x170ef54646d496p-107 53 -inf -7 +0 53 +0 +inf -0x170ef54646d497p-106 53 -inf -0 +0 53 +0 -0 0.0 53 -inf -0 +0 53 -inf -0 0x170ef54646d497p-106 53 -inf -0 +0 53 -inf +inf -0x16345785d8a00000 53 -inf 8 +0 53 -inf +inf 0.0 53 -inf 8 +0 53 -inf +inf 0x16345785d8a00000 53 -inf 8 +0 53 -inf +inf -0x170ef54646d497p-105 53 -inf +inf +0 53 -inf +inf 0.0e-17 53 -inf +inf +0 53 -inf +inf +0x170ef54646d497p-105 53 -inf +inf +0 53 nan nan -0x170ef54646d497p-104 53 -inf nan +0 53 nan nan 0.0e-17 53 -inf nan +0 53 nan nan +0x170ef54646d497p-104 53 -inf nan +0 53 -inf +inf -0x170ef54646d497p-109 53 +0 -0 +0 53 +0 -0 0.0 53 +0 -0 +0 53 -inf +inf 0x170ef54646d497p-109 53 +0 -0 +2 53 -inf -0x13c3ada9f391a5p-110 -0x114b37f4b51f71p-107 53 +0 7 +0 53 +0 -0 0.0 53 +0 7 +1 53 0x13c3ada9f391a5p-110 +inf 0x114b37f4b51f71p-107 53 +0 7 +0 53 -inf -0 -0x50b45a75f7e81p-104 53 +0 +inf +0 53 +0 -0 0.0 53 +0 +inf +0 53 +0 +inf 0x142d169d7dfa03p-106 53 +0 +inf +0 53 +0 -0 -0x170ef54646d497p-109 53 +inf +inf +0 53 +0 -0 0.0 53 +inf +inf +0 53 +0 -0 0x170ef54646d497p-109 53 +inf +inf +0 53 nan nan -0x170ef54646d497p-109 53 +inf nan +0 53 nan nan 0.0 53 +inf nan +0 53 nan nan 0x170ef54646d497p-109 53 +inf nan + +# regular values +0 53 -inf +inf -2.5 53 -8 8 + +0 53 0x5p-4 0.5 -2.5 53 -8 -5 +1 53 -0x1999999999999ap-56 -0x1p-4 -2.5 53 25 40 +2 53 0x5p-5 0x16db6db6db6db7p-54 -2.5 53 -16 -7 +3 53 -0x1d1745d1745d18p-55 -0x11e6efe35b4cfap-58 -2.5 53 11 143 + +0 53 0x1p-4 4 33.125 53 8.28125 530 +1 53 -0x11111111111112p-56 -0x1p-4 33.125 53 -530 -496.875 +2 53 0.125 0x13a12f684bda13p-53 33.125 53 54 265 +3 53 0x13a12f684bda12p-53 0x14627627627628p-53 33.125 53 52 54 diff --git a/tests/d_sub.dat b/tests/d_sub.dat new file mode 100644 index 0000000..4785876 --- /dev/null +++ b/tests/d_sub.dat @@ -0,0 +1,122 @@ +# data file for mpfi_d_sub +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +#WARNING: +# double values are read by the test suite with rounding towards minus +# infinity to a machine-dependant precision (whereas the mpfi data are read +# at the given precision with rounding to the nearest). +# So as to ensure portability, use test values that are representable with a +# 53 bit-significand which corresponds to the minimum default precision for +# a double in the test suite. + +# special values +0 53 nan nan -0x170ef54646d497p-109 53 nan nan +0 53 nan nan 0.0 53 nan nan +0 53 nan nan 0x170ef54646d497p-109 53 nan nan +0 53 +inf nan -0x114b37f4b51f71p-107 53 nan -inf +0 53 +inf nan 0.0 53 nan -inf +0 53 +inf nan 0x114b37f4b51f71p-107 53 nan -inf +0 53 0x1bfffffffffff8p-50 nan -0xfc339ab0a6b53p-99 53 nan -7 +0 53 7 nan 0.0 53 nan -7 +0 53 0x1c000000000007p-50 nan 0xfc339ab0a6b53p-99 53 nan -7 +0 53 -15 nan -15.0 53 nan -0 +0 53 +0 nan 0.0 53 nan -0 +0 53 15 nan 15.0 53 nan -0 +0 53 -0x8000000000001p-51 nan -0xb2b3ece0a4ef9p-103 53 nan 1 +0 53 -1 nan 0.0 53 nan 1 +0 53 -0xfffffffffffffp-52 nan 0xb2b3ece0a4ef9p-103 53 nan 1 +0 53 -inf nan -0x5acae5c4b6e51p-101 53 nan +inf +0 53 -inf nan 0.0 53 nan +inf +0 53 -inf nan 0x5acae5c4b6e51p-101 53 nan +inf +0 53 +inf +inf -0x170ef54646d497p-108 53 -inf -inf +0 53 +inf +inf 0.0 53 -inf -inf +0 53 +inf +inf 0x170ef54646d497p-108 53 -inf -inf +1 53 0x1bffffffffffffp-50 +inf -0x170ef54646d497p-107 53 -inf -7 +0 53 7 +inf 0.0 53 -inf -7 +1 53 7 +inf 0x170ef54646d497p-107 53 -inf -7 +0 53 -0x170ef54646d497p-96 +inf -0x170ef54646d497p-96 53 -inf -0 +0 53 +0 +inf 0.0 53 -inf -0 +0 53 0x170ef54646d497p-96 +inf 0x170ef54646d497p-96 53 -inf -0 +1 53 -0x16345785d8a00100 +inf -0x16345785d8a00000 53 -inf 8 +0 53 -8 +inf 0.0 53 -inf 8 +1 53 0x16345785d89fff00 +inf 0x16345785d8a00000 53 -inf 8 +0 53 -inf +inf -0x170ef54646d497p-105 53 -inf +inf +0 53 -inf +inf 0.0e-17 53 -inf +inf +0 53 -inf +inf 0x170ef54646d497p-105 53 -inf +inf +0 53 nan +inf -0x170ef54646d497p-104 53 -inf nan +0 53 nan +inf 0.0e-17 53 -inf nan +0 53 nan +inf 0x170ef54646d497p-104 53 -inf nan +0 53 -0x170ef54646d497p-109 -0x170ef54646d497p-109 + -0x170ef54646d497p-109 + 53 +0 -0 +0 53 +0 -0 0.0 53 +0 -0 +0 53 0x170ef54646d497p-109 0x170ef54646d497p-109 + 0x170ef54646d497p-109 + 53 +0 -0 +1 53 -0x10000000000001p-49 -0x114b37f4b51f71p-107 + -0x114b37f4b51f71p-107 + 53 +0 8 +0 53 -8 -0 0.0 53 +0 8 +1 53 -8 0x114b37f4b51f71p-107 + 0x114b37f4b51f71p-107 + 53 +0 8 +0 53 -inf -0x50b45a75f7e81p-104 + -0x50b45a75f7e81p-104 + 53 +0 +inf +0 53 -inf -0 0.0 53 +0 +inf +0 53 -inf -0x142d169d7dfa03p-106 + -0x142d169d7dfa03p-106 + 53 +0 +inf +0 53 -inf -inf 0x142d169d7dfa03p-106 53 +inf +inf +0 53 -inf -inf -0x170ef54646d497p-109 53 +inf +inf +0 53 -inf -inf 0.0 53 +inf +inf +0 53 nan -inf 0x170ef54646d497p-109 53 +inf nan +0 53 nan -inf -0x170ef54646d497p-109 53 +inf nan +0 53 nan -inf 0.0 53 +inf nan + +# regular values +0 53 -0x1fb53d14aa9c2fp-47 -0x18353d14aa9c2fp-47 + -0xfb53d14aa9c2fp-47 + 53 17 32 +0 53 +0 0x7353d14aa9c2fp-47 + 0xfb53d14aa9c2fp-47 + 53 17 0xfb53d14aa9c2fp-47 +0 53 -0x104ac2eb5563d1p-48 -0 + 0xfb53d14aa9c2fp-48 + 53 0xfb53d14aa9c2fp-48 32 + +0 53 0x15b456789abcdfp-48 0x123456789abd17p-4 + 3.5 + 53 -0x123456789abcdfp-4 -0x123456789abcdfp-48 +1 53 0x3923456789abcdp-52 0x123456789abd17p-4 + 3.5 + 53 -0x123456789abcdfp-4 -0x123456789abcdfp-56 +2 53 0x18p-4 0x101a3456789abdp-44 + 256.5 + 53 -0x123456789abcdfp-52 0xff +3 53 0xfff8p-4 0x10018p-4 + 4097.5 + 53 0x1p-550 0x1fffffffffffffp-52 + +0 53 0xeb456789abcdfp-48 0x123456789abca7p-4 + -3.5 + 53 -0x123456789abcdfp-4 -0x123456789abcdfp-48 +1 53 -0x36dcba98765434p-52 0x123456789abca7p-4 + -3.5 + 53 -0x123456789abcdfp-4 -0x123456789abcdfp-56 +2 53 -0x1ff8p-4 -0xff5cba9876543p-44 + -256.5 + 53 -0x123456789abcdfp-52 0xff +3 53 -0x10038p-4 -0x10018p-4 + -4097.5 + 53 0x1p-550 0x1fffffffffffffp-52 diff --git a/tests/diam.dat b/tests/diam.dat new file mode 100644 index 0000000..2e61bf0 --- /dev/null +++ b/tests/diam.dat @@ -0,0 +1,55 @@ +# data file for mpfi_diam +# +# column fields: +# 1: error direction (0: result is exact, +: result is overestimated) +# 2: precision of result +# 3: value of result +# +# 5: precision of argument +# 6: left endpoint value of argument +# 7: right endpoint value of argument +# + +# special values +0 53 nan 53 nan -inf +0 53 nan 53 nan -8 +0 53 nan 53 -8 nan +0 53 nan 53 nan -0 +0 53 nan 53 +0 nan +0 53 nan 53 nan 5 +0 53 nan 53 +5 nan +0 53 nan 53 nan +inf +0 53 nan 53 nan nan +0 53 nan 53 -inf -inf +0 53 nan 53 -inf -8 +0 53 +inf 53 -inf -0 +0 53 +inf 53 -inf 5 +0 53 +inf 53 -inf +inf +0 53 nan 53 -inf nan +0 53 +inf 53 -inf -0 +0 53 +8 53 -8 -0 +0 53 -0 53 +0 -0 # should it be +0? +0 53 +5 53 +0 5 +0 53 +inf 53 +0 +inf +0 53 nan 53 +0 nan +0 53 nan 53 +inf +inf +0 53 nan 53 +inf nan + +# regular values ++ 53 0x15555555555556p-53 + 53 -34 -17 + ++ 4 0xcp-4 53 -34 -17 +0 53 51 53 -34 17 ++ 4 52 53 -34 17 + +0 53 +0x123456789abcdp-2 + 53 +0 +0x123456789abcdp-2 ++ 53 0x145f306dc9c883p-105 + 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 ++ 53 0x145f306dc9c883p-105 + 53 -0x1921fb54442d19p-51 -0x1921fb54442d18p-51 ++ 53 0x13333333333338p-52 + 53 -4 -0x7fffffffffffdp-51 ++ 53 0x18e38e38e38e3fp-52 + 53 -8 -0x7fffffffffffbp-51 diff --git a/tests/diam_abs.dat b/tests/diam_abs.dat new file mode 100644 index 0000000..e1e7424 --- /dev/null +++ b/tests/diam_abs.dat @@ -0,0 +1,40 @@ +# data file for mpfi_diam_abs +# +# column fields: +# 1: error direction (0: result is exact, +: result is overestimated) +# 2: precision of result +# 3: value of result +# +# 5: precision of argument +# 6: left endpoint value of argument +# 7: right endpoint value of argument +# + +# special values +0 53 nan 53 nan -inf +0 53 nan 53 nan -8 +0 53 nan 53 -8 nan +0 53 nan 53 nan -0 +0 53 nan 53 +0 nan +0 53 nan 53 nan 5 +0 53 nan 53 +5 nan +0 53 nan 53 nan +inf +0 53 nan 53 nan nan +0 53 nan 53 -inf -inf +0 53 +inf 53 -inf -8 +0 53 +inf 53 -inf -0 +0 53 +inf 53 -inf 5 +0 53 +inf 53 -inf +inf +0 53 nan 53 -inf nan +0 53 +inf 53 -inf -0 +0 53 +8 53 -8 -0 +0 53 -0 53 +0 -0 # should it be +0? +0 53 +5 53 +0 5 +0 53 +inf 53 +0 +inf +0 53 nan 53 +0 nan +0 53 nan 53 +inf +inf +0 53 nan 53 +inf nan + +# regular values +0 53 17 53 -34 -17 ++ 4 18 53 -34 -17 diff --git a/tests/diam_rel.dat b/tests/diam_rel.dat new file mode 100644 index 0000000..fa46066 --- /dev/null +++ b/tests/diam_rel.dat @@ -0,0 +1,51 @@ +# data file for mpfi_diam_rel +# +# column fields: +# 1: error direction (0: result is exact, +: result is overestimated) +# 2: precision of result +# 3: value of result +# +# 5: precision of argument +# 6: left endpoint value of argument +# 7: right endpoint value of argument +# + +# special values +0 53 nan 53 nan -inf +0 53 nan 53 nan -8 +0 53 nan 53 -8 nan +0 53 nan 53 nan -0 +0 53 nan 53 +0 nan +0 53 nan 53 nan 5 +0 53 nan 53 +5 nan +0 53 nan 53 nan +inf +0 53 nan 53 nan nan +0 53 nan 53 -inf -inf +0 53 nan 53 -inf -8 +0 53 nan 53 -inf -0 +0 53 nan 53 -inf 5 +0 53 nan 53 -inf +inf +0 53 nan 53 -inf nan +0 53 nan 53 -inf -0 +0 53 +2 53 -8 -0 +0 53 nan 53 +0 -0 +0 53 +2 53 +0 5 +0 53 nan 53 +0 +inf +0 53 nan 53 +0 nan +0 53 nan 53 +inf +inf +0 53 nan 53 +inf nan + +# regular values +0 53 2 53 +0 +0x123456789abcdp-2 ++ 53 0x145f306dc9c883p-105 + 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 ++ 53 0x145f306dc9c883p-105 + 53 -0x1921fb54442d19p-51 -0x1921fb54442d18p-51 ++ 53 0x13333333333338p-52 + 53 -4 -0x7fffffffffffdp-51 ++ 53 0x18e38e38e38e3fp-52 + 53 -8 -0x7fffffffffffbp-51 ++ 53 6 + 53 -0x1fffffffffffffp-53 2 ++ 53 0x1ffffffffffffep-51 + 53 -0x1ffffffffffffap-53 3 \ No newline at end of file diff --git a/tests/div.dat b/tests/div.dat new file mode 100644 index 0000000..d8d1bad --- /dev/null +++ b/tests/div.dat @@ -0,0 +1,199 @@ +# data file for mpfi_div +# +# for a description of the fields: see add.dat + +# special values +0 53 nan nan 53 nan nan 53 -inf -7 +0 53 nan nan 53 nan nan 53 -8 +1 +0 53 nan nan 53 nan nan 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 nan +0 53 nan nan 53 nan nan 53 +5 +inf +0 53 nan nan 53 nan nan 53 +inf +inf +0 53 nan nan 53 nan nan 53 nan -0 +0 53 nan nan 53 nan -0 53 -inf -7 +0 53 nan nan 53 nan -0 53 -8 +1 +0 53 nan nan 53 nan +inf 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 +7 +0 53 nan nan 53 nan -inf 53 +5 +inf +0 53 nan nan 53 nan -7 53 +inf +inf +0 53 nan nan 53 nan +1 53 nan -0 +0 53 nan nan 53 -inf -inf 53 -inf -inf +0 53 -inf +inf 53 -inf -7 53 -1 +8 +0 53 -inf -0 53 -inf -0 53 +8 +inf +0 53 nan -0 53 -inf -0 53 +inf +inf +0 53 -inf +inf 53 -inf +8 53 +0 +8 +0 53 -inf +inf 53 -inf +inf 53 +0 +8 +0 53 +0 -0 53 +0 -0 53 -inf -7 +0 53 -inf -0 53 +0 +8 53 -7 -0 +0 53 +0 +inf 53 +0 -0 53 +0 +8 +0 53 +0 +inf 53 +0 +inf 53 +0 +8 +0 53 +0 -0 53 +0 -0 53 +8 +inf +0 53 nan nan 53 +0 +8 53 +inf nan +0 53 -inf +inf 53 +0 -0 53 -inf +inf +0 53 -inf +inf 53 +0 +8 53 -7 +8 +0 53 nan +inf 53 +0 -0 53 +0 -0 +0 53 +0 +inf 53 +0 +inf 53 +0 +8 +0 53 nan nan 53 +0 nan 53 +8 +inf +0 53 +0 -0 53 +0 +8 53 +inf +inf +0 53 -inf +inf 53 +inf +inf 53 -inf +3 +0 53 nan +inf 53 +inf +inf 53 +0 +inf +0 53 nan nan 53 +inf +inf 53 +3 nan +0 53 nan nan 53 +inf nan 53 -inf -7 +0 53 nan nan 53 +inf nan 53 +inf +inf +0 53 nan nan 53 +inf nan 53 -3 +7 + +# regular value +0 53 0x69 0xd14fad + 53 -0x75bcd15 -0x754e + 53 -0x11e -0x9 +1 53 0x7.0ef61537b1704p-12 0xd14fad + 53 -0x75bcd15 -0x1.489c07caba163p-4 + 53 -0x2.e8e36e560704ap+4 -0x9 +2 53 0x69p-16 0x2.30ee5eef9c36cp+4 + 53 -0x1.02f0415f9f596p+0 -0x754ep-16 + 53 -0x11e -0x7.62ce64fbacd2cp-8 +3 53 0x7.0ef61537b1704p-8 0x2.30ee5eef9c36cp+4 + 53 -0x1.02f0415f9f596p+0 -0x1.489c07caba163p-4 + 53 -0x2.e8e36e560704ap+0 -0x7.62ce64fbacd2cp-8 +0 53 0xff +inf + 53 -0xacbp+256 -0x6f9 + 53 -0x7 -0 +1 53 0x9.e9f24790445fp-4 +inf + 53 -0x100 -0xe.bb80d0a0824ep-4 + 53 -0x1.7c6d760a831fap+0 -0 +0 53 -inf +inf + 53 -0x1.25f2d73472753p+0 -0x9.9a19fd3c1fc18p-4 + 53 -0x9.3b0c8074ccc18p-4 +0x4.788df5d72af78p-4 +0 53 -inf -5 + 53 -100 -15 + 53 +0 +3 +2 53 -inf -0x1.fd8457415f917p+0 + 53 -2 -0x1.25f2d73472753p+0 + 53 +0 +0x9.3b0c8074ccc18p-4 +0 53 -0x480b3b -0x69 + 53 -0x123456789 -0x754ep+4 + 53 0x40b 0x11ep+4 +1 53 -0x2.f5008d2df94ccp-4 -0x69p-254 + 53 -0xd.67775e4b8588p-4 -0x754ep-53 + 53 0x4.887091874ffc8p+0 0x11ep+201 +2 53 -0x480b3bp+17 -0xa.fc5e7338f3e4p+0 + 53 -0x123456789 -0x1.b0a62934c76e9p+0 + 53 0x40bp-17 0x2.761ec797697a4p-4 +3 53 -0x2.f5008d2df94ccp+4 -0xa.fc5e7338f3e4p-8 + 53 -0xd.67775e4b8588p+0 -0x1.b0a62934c76e9p+0 + 53 0x4.887091874ffc8p-4 0x2.761ec797697a4p+4 + +0 53 +0 0xd14fad + 53 -0x75bcd15 -0 + 53 -0x90 -0x9 +2 53 +0 0x1.4fdb41a33d6cep+4 + 53 -0x1.4298b2138f2a7p-4 -0 + 53 -0x1p-8 -0xf.5e4900c9c19fp-12 +0 53 +0 +inf + 53 -0xeeeeeeeee -0 + 53 -0xaaaaaaaaa -0 +0 53 -inf +inf + 53 -0x1.25f2d73472753p+0 -0 + 53 -0x9.3b0c8074ccc18p-4 +0x4.788df5d72af78p-4 +0 53 -inf -0 + 53 -0xeeeeeeeee -0 + 53 +0 +0x3 +0 53 -0xd14fad -0 + 53 -0x75bcd15 -0 + 53 0x9 0x90 +1 53 -0x1.4fdb41a33d6cep+4 -0 + 53 -0x1.4298b2138f2a7p-4 -0 + 53 0xf.5e4900c9c19fp-12 0x9 + +0 53 -0x1280 0xd14fad + 53 -0x75bcd15 0xa680 + 53 -0xaf6 -0x9 +1 53 -0x1.c71c71c71c71d 2 + 53 -0x12 0x10 + 53 -0xbbbbbbbbbb -0x9 +2 53 -0x69p-16 0xe.525982af70c9p-12 + 53 -0x1 0x754ep-16 + 53 -0xcccccccccc -0x11e +3 53 -0x8.85e40b3c3f63p+0 0xe.071cbfa1de788p-4 + 53 -0xb.5b90b4d32136p-4 0x6.e694ac6767394p+0 + 53 -0xddddddddddd -0xc.f459be9e80108p-4 +0 53 -inf +inf + 53 -0xacbp+256 0x6f9 + 53 -0x7 -0 +0 53 -inf +inf + 53 -0x1.25f2d73472753p+0 +0x9.9a19fd3c1fc18p-4 + 53 -0x9.3b0c8074ccc18p-4 +0x4.788df5d72af78p-4 +0 53 -inf +inf + 53 +0 +15 + 53 -3 +3 +0 53 -0x69 0xbaffep+12 + 53 -0x754e 0xd0e9dc4p+12 + 53 0x11e 0xbbb +1 53 -0xe.525982af70c9p-8 0xbaffep+12 + 53 -0x10 0xd0e9dc4p+12 + 53 0x11e 0xbbb +2 53 -0x69 0xe.525982af70c9p-2 + 53 -0x754e 0x1p+10 + 53 0x11e 0xbbb +3 53 -0xf.3d2f5db8ec728p-4 0x1.cf8fa732de129p+0 + 53 -0x1.18333622af827p+0 0x2.14b836907297p+0 + 53 0x1.263147d1f4bcbp+0 0x111 + +0 53 -0xd14fad -0 + 53 +0 0x75bcd15 + 53 -0xa -0x9 +1 53 -0x1.e1bb896bfda07p+0 -0 + 53 +0 0x1.acbf1702af6edp+0 + 53 -0x0.f -0xe.3d7a59e2bdacp-4 +0 53 -inf -0 + 53 +0 0xa + 53 -0x9 -0 +0 53 -inf +inf + 53 +0 0xa + 53 -1 +1 +0 53 +0 0xd14fad + 53 +0 0x75bcd15 + 53 +0x9 +0xa +2 53 +0 0x9.deb65b02baep-4 + 53 +0 0x1.5f6b03dc8c66fp+0 + 53 +0x2.39ad24e812dcep+0 0xa + +0 53 -0xd14fad -0x69 + 53 0x754e 0x75bcd15 + 53 -0x11e -0x9 +1 53 -0x7.02d3edfbc8b6p+0 -0x69p-16 + 53 0x754ep-16 0x1.008a3accc766dp+4 + 53 -0x11e -0x2.497403b31d32ap+0 +2 53 -0xd14fad -0x7.52680a49e5d68p-8 + 53 0x9.ac412ff1f1478p-4 0x75bcd15 + 53 -0x1.5232c83a0e726p+4 -0x9 +3 53 -0x5.c1d97d57d81ccp+0 -0x2.c9a600c455f5ap+0 + 53 0xe.1552a314d629p-4 0x1.064c5adfd0042p+0 + 53 -0x5.0d4d319a50b04p-4 -0x2.d8f51df1e322ep-4 +0 53 -inf -0x69 + 53 0x754e 0xeeee + 53 -0x11e -0 +2 53 -inf -0x1.df1cc82e6a583p-4 + 53 0x1.a9016514490e6p-4 0xeeee + 53 -0xe.316e87be0b24p-4 -0 +0 53 -inf +inf + 53 5 6 + 53 -0x5.0d4d319a50b04p-4 0x2.d8f51df1e322ep-4 +0 53 0x69 +inf + 53 0x754e +0xeeeee + 53 +0 +0x11e +1 53 0x1.2a4fcda56843p+0 +inf + 53 0x1.7f03f2a978865p+0 0xeeeee + 53 +0 0x1.48b08624606b9p+0 +0 53 0xb2 0x93d + 53 0x5efc1492 0x1ba2dc763 + 53 0x2fdd1f 0x889b71 +1 53 0x2.120d75be74b54p-12 0x93dp+20 + 53 0x1.d7c06f9ff0706p-8 0x1ba2dc763 + 53 0x2fdd1fp-20 0xe.3d7a59e2bdacp+0 +2 53 0xb.2p-8 0x7.02d3edfbc8b6p-4 + 53 0x5.efc1492p-4 0x1.008a3accc766dp+0 + 53 0x2.497403b31d32ap+0 0x8.89b71p+0 +3 53 0xa.f3518768b206p-8 0x7.0e2acad54859cp+0 + 53 0x8.440e7d65be6bp-8 0x3.99982e9eae09ep+0 + 53 0x8.29fa8d0659e48p-4 0xc.13d2fd762e4a8p-4 diff --git a/tests/div_2si.dat b/tests/div_2si.dat new file mode 100644 index 0000000..09e559d --- /dev/null +++ b/tests/div_2si.dat @@ -0,0 +1,71 @@ +# data file for mpfi_div_2si +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan -inf 53 nan -inf -3 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3 +0 53 nan -28 53 nan -7 -2 +0 53 nan -7 53 nan -7 0 +0 53 nan -1.75 53 nan -7 2 +0 53 nan -0 53 nan -0 -15 +0 53 nan -0 53 nan -0 0 +0 53 nan -0 53 nan -0 15 +0 53 nan 8 53 nan 1 -3 +0 53 nan 1 53 nan 1 0 +0 53 nan .125 53 nan 1 3 +0 53 nan +inf 53 nan +inf -63 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63 +0 53 -inf -inf 53 -inf -inf -2 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2 +0 53 -inf -16 53 -inf -1 -4 +0 53 -inf -1 53 -inf -1 0 +0 53 -inf -.125 53 -inf -1 3 +0 53 -inf -0 53 -inf -0 -8 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8 +0 53 -inf 128 53 -inf 8 -4 +0 53 -inf 8 53 -inf 8 0 +0 53 -inf 0.5 53 -inf 8 4 +0 53 -inf +inf 53 -inf +inf -32 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32 +0 53 -inf nan 53 -inf nan -64 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan 64 +0 53 +0 -0 53 +0 -0 -1 +0 53 +0 -0 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1 +0 53 +0 128 53 +0 8 -4 +0 53 +0 8 53 +0 8 0 +0 53 +0 0.5 53 +0 8 4 +0 53 +0 +inf 53 +0 +inf -7 +0 53 +0 +inf 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7 +0 53 +inf +inf 53 +inf +inf -1 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 +inf nan 53 +inf nan -1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1 + +# regular values +0 53 -0x20p+32 -0x11p+32 + 53 -32 -17 -32 +0 53 0x11p-32 0x20p-32 + 53 17 32 32 diff --git a/tests/div_2ui.dat b/tests/div_2ui.dat new file mode 100644 index 0000000..2137284 --- /dev/null +++ b/tests/div_2ui.dat @@ -0,0 +1,54 @@ +# data file for mpfi_div_2ui +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3 +0 53 nan -7 53 nan -7 0 +0 53 nan -1.75 53 nan -7 2 +0 53 nan -0 53 nan -0 0 +0 53 nan -0 53 nan -0 15 +0 53 nan 1 53 nan 1 0 +0 53 nan .125 53 nan 1 3 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2 +0 53 -inf -1 53 -inf -1 0 +0 53 -inf -.25 53 -inf -1 2 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8 +0 53 -inf 8 53 -inf 8 0 +0 53 -inf 0.5 53 -inf 8 4 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan 64 +0 53 +0 -0 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1 +0 53 +0 8 53 +0 8 0 +0 53 +0 .5 53 +0 8 4 +0 53 +0 +inf 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1 + +# regular values +0 53 -0x20p-32 -0x11p-32 + 53 -32 -17 32 +0 53 0x123456789abcdfp-78 0x123456789abcdfp-25 + 53 0x123456789abcdfp-53 0x123456789abcdf 25 diff --git a/tests/div_d.dat b/tests/div_d.dat new file mode 100644 index 0000000..2ad1bd5 --- /dev/null +++ b/tests/div_d.dat @@ -0,0 +1,92 @@ +# data file for mpfi_div_d +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +#WARNING: +# double values are read by the test suite with rounding towards minus +# infinity to a machine-dependant precision (whereas the mpfi data are read +# at the given precision with rounding to the nearest). +# So as to ensure portability, use test values that are representable with a +# 53 bit-significand which corresponds to the minimum default precision for +# a double in the test suite. + +# special values +0 53 nan nan 53 nan nan -0x170ef54646d497p-109 +0 53 nan nan 53 nan nan 0.0 +0 53 nan nan 53 nan nan 0x170ef54646d497p-109 +0 53 nan nan 53 nan -inf -0x114b37f4b51f71p-107 +0 53 nan nan 53 nan -inf 0.0 +0 53 nan nan 53 nan -inf 0x114b37f4b51f71p-107 +0 53 nan nan 53 nan -7 -0xfc339ab0a6b53p-99 +0 53 nan nan 53 nan -7 0.0 +0 53 nan nan 53 nan -7 7.0 +0 53 nan nan 53 nan -0 -15.0 +0 53 nan nan 53 nan -0 0.0 +0 53 nan nan 53 nan -0 15.0 +0 53 nan nan 53 nan +1 -0xb2b3ece0a4ef9p-103 +0 53 nan nan 53 nan +1 0.0 +0 53 nan nan 53 nan +1 0xb2b3ece0a4ef9p-103 +0 53 nan nan 53 nan +inf -0x5acae5c4b6e51p-101 +0 53 nan nan 53 nan +inf 0.0 +0 53 nan nan 53 nan +inf 0x5acae5c4b6e51p-101 +0 53 +inf +inf 53 -inf -inf -0x170ef54646d497p-108 +0 53 -inf +inf 53 -inf -inf 0.0 +0 53 -inf -inf 53 -inf -inf 0x170ef54646d497p-108 +0 53 1 +inf 53 -inf -7 -7.0 +0 53 -inf +inf 53 -inf -7 0.0 +0 53 -inf -1 53 -inf -7 7.0 +0 53 +0 +inf 53 -inf -0 -0x170ef54646d497p-106 +0 53 -inf nan 53 -inf -0 0.0 +0 53 -inf -0 53 -inf -0 0x170ef54646d497p-106 +1 53 -0x15555555555556p-51 +inf 53 -inf 8 -3.0 +0 53 -inf +inf 53 -inf 8 0.0 +2 53 -inf 0x15555555555556p-51 53 -inf 8 3.0 +0 53 -inf +inf 53 -inf +inf -0x170ef54646d497p-105 +0 53 -inf +inf 53 -inf +inf 0.0e-17 +0 53 -inf +inf 53 -inf +inf +0x170ef54646d497p-105 +0 53 nan nan 53 -inf nan -0x170ef54646d497p-104 +0 53 nan nan 53 -inf nan 0.0e-17 +0 53 nan nan 53 -inf nan +0x170ef54646d497p-104 +0 53 +0 -0 53 +0 -0 -0x170ef54646d497p-109 +0 53 nan nan 53 +0 -0 0.0 +0 53 +0 -0 53 +0 -0 0x170ef54646d497p-109 +1 53 -0x1d9b1f5d20d556p+5 -0 53 +0 8 -0x114b37f4b51f71p-107 +0 53 nan +inf 53 +0 8 0.0 +2 53 +0 0x1d9b1f5d20d556p+5 53 +0 8 0x114b37f4b51f71p-107 +0 53 -inf -0 53 +0 +inf -0x50b45a75f7e81p-104 +0 53 nan +inf 53 +0 +inf 0.0 +0 53 +0 +inf 53 +0 +inf 0x142d169d7dfa03p-106 +0 53 -inf -inf 53 +inf +inf -0x170ef54646d497p-109 +0 53 -inf +inf 53 +inf +inf 0.0 +0 53 +inf +inf 53 +inf +inf 0x170ef54646d497p-109 +0 53 nan nan 53 +inf nan -0x170ef54646d497p-109 +0 53 nan nan 53 +inf nan 0.0 +0 53 nan nan 53 +inf nan 0x170ef54646d497p-109 + +# regular values +0 53 0x10000000000001p-53 0x10000000000001p-20 + 53 -0x10000000000001p-20 -0x10000000000001p-53 -1 +1 53 -0x10000000000001p-19 -1 + 53 -0x10000000000002p-20 -0x10000000000001p-53 0x10000000000001p-53 +2 53 -0x1p+33 -0x1000001fffffffp-52 + 53 -0x10000000000001p-20 -0x10000020000001p-53 0x10000000000001p-53 +3 53 -0x10000000000001p-19 -0x1000001fffffffp-52 + 53 -0x10000000000002p-20 -0x10000020000001p-53 0x10000000000001p-53 + +0 53 -0x1p-7 0x1p-53 + 53 -0x123456789abcdfp-53 0x123456789abcdfp-7 -0x123456789abcdf +1 53 -0x1c200000000002p-106 0x1p-53 + 53 -0x123456789abcdfp-53 0x10000000000001p-53 -0x123456789abcdf +2 53 -0x1p-7 0x1c200000000001p-105 + 53 -1 0x123456789abcdfp-7 -0x123456789abcdf +3 53 -0x1c200000000002p-106 0x1c200000000001p-105 + 53 -1 0x10000000000001p-53 -0x123456789abcdf diff --git a/tests/div_fr.dat b/tests/div_fr.dat new file mode 100644 index 0000000..ba8be7d --- /dev/null +++ b/tests/div_fr.dat @@ -0,0 +1,84 @@ +# data file for mpfi_div_fr +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan 53 -0x170ef54646d497p-109 +0 53 nan nan 53 nan nan 53 -0 +0 53 nan nan 53 nan nan 53 0x170ef54646d497p-109 +0 53 nan nan 53 nan -inf 53 -0x114b37f4b51f71p-107 +0 53 nan nan 53 nan -inf 53 +0 +0 53 nan nan 53 nan -inf 53 0x114b37f4b51f71p-107 +0 53 nan nan 53 nan -7 53 -0xfc339ab0a6b53p-99 +0 53 nan nan 53 nan -7 53 -0 +0 53 nan nan 53 nan -7 53 7.0 +0 53 nan nan 53 nan -0 53 -15.0 +0 53 nan nan 53 nan -0 53 +0 +0 53 nan nan 53 nan -0 53 15.0 +0 53 nan nan 53 nan +1 53 -0xb2b3ece0a4ef9p-103 +0 53 nan nan 53 nan +1 53 -0 +0 53 nan nan 53 nan +1 53 0xb2b3ece0a4ef9p-103 +0 53 nan nan 53 nan +inf 53 -0x5acae5c4b6e51p-101 +0 53 nan nan 53 nan +inf 53 +0 +0 53 nan nan 53 nan +inf 53 0x5acae5c4b6e51p-101 +0 53 +inf +inf 53 -inf -inf 53 -0x170ef54646d497p-108 +0 53 -inf +inf 53 -inf -inf 53 +0 +0 53 -inf -inf 53 -inf -inf 53 0x170ef54646d497p-108 +1 53 0x136dcc951d8bffp+5 +inf 53 -inf -7 53 -0x170ef54646d497p-107 +0 53 -inf +inf 53 -inf -7 53 -0 +2 53 -inf -0x136dcc951d8bffp+5 53 -inf -7 53 0x170ef54646d497p-107 +0 53 +0 +inf 53 -inf -0 53 -0x170ef54646d497p-106 +0 53 -inf nan 53 -inf -0 53 +0 +0 53 -inf -0 53 -inf -0 53 0x170ef54646d497p-106 +1 53 -0x170ef54646d497p-110 +inf 53 -inf 8 53 -0x16345785d8a00000 +0 53 -inf +inf 53 -inf 8 53 -0 +2 53 -inf 0x170ef54646d497p-110 53 -inf 8 53 0x16345785d8a00000 +0 53 -inf +inf 53 -inf +inf 53 -0x170ef54646d497p-105 +0 53 -inf +inf 53 -inf +inf 53 +0 +0 53 -inf +inf 53 -inf +inf 53 +0x170ef54646d497p-105 +0 53 nan nan 53 -inf nan 53 -0x170ef54646d497p-104 +0 53 nan nan 53 -inf nan 53 -0 +0 53 nan nan 53 -inf nan 53 +0x170ef54646d497p-104 +0 53 +0 -0 53 +0 -0 53 -0x170ef54646d497p-109 +0 53 nan +inf 53 +0 -0 53 +0 +0 53 +0 -0 53 +0 -0 53 0x170ef54646d497p-109 +1 53 -0x1d9b1f5d20d556p+1 -0 53 +0 8 53 -0x114b37f4b51f71p-103 +0 53 nan +inf 53 +0 8 53 -0 +2 53 +0 +0x1d9b1f5d20d556p+1 53 +0 8 53 0x114b37f4b51f71p-103 +0 53 -inf -0 53 +0 +inf 53 -0x50b45a75f7e81p-104 +0 53 nan +inf 53 +0 +inf 53 +0 +0 53 +0 +inf 53 +0 +inf 53 0x142d169d7dfa03p-106 +0 53 -inf -inf 53 +inf +inf 53 -0x170ef54646d497p-109 +0 53 -inf +inf 53 +inf +inf 53 -0 +0 53 +inf +inf 53 +inf +inf 53 0x170ef54646d497p-109 +0 53 nan nan 53 +inf nan 53 -0x170ef54646d497p-109 +0 53 nan nan 53 +inf nan 53 +0 +0 53 nan nan 53 +inf nan 53 0x170ef54646d497p-109 + +# regular values +0 53 0x10000000000001p-53 0x10000000000001p-20 + 53 -0x10000000000001p-20 -0x10000000000001p-53 53 -1 +1 53 -0x10000000000001p-19 -1 + 53 -0x10000000000002p-20 -0x10000000000001p-53 53 0x10000000000001p-53 +2 53 -0x1p+33 -0x1000001fffffffp-52 + 53 -0x10000000000001p-20 -0x10000020000001p-53 53 0x10000000000001p-53 +3 53 -0x10000000000001p-19 -0x1000001fffffffp-52 + 53 -0x10000000000002p-20 -0x10000020000001p-53 53 0x10000000000001p-53 + +0 53 -0x1p-7 0x1p-53 + 53 -0x123456789abcdfp-53 0x123456789abcdfp-7 53 -0x123456789abcdf +1 53 -0x1c200000000002p-106 0x1p-53 + 53 -0x123456789abcdfp-53 0x10000000000001p-53 53 -0x123456789abcdf +2 53 -0x1p-7 0x1c200000000001p-105 + 53 -1 0x123456789abcdfp-7 53 -0x123456789abcdf +3 53 -0x1c200000000002p-106 0x1c200000000001p-105 + 53 -1 0x10000000000001p-53 53 -0x123456789abcdf diff --git a/tests/div_q.dat b/tests/div_q.dat new file mode 100644 index 0000000..23c14a8 --- /dev/null +++ b/tests/div_q.dat @@ -0,0 +1,99 @@ +# data file for mpfi_div_q +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1/1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1/1 +0 53 nan nan 53 nan -inf -3/1 +0 53 nan nan 53 nan -inf 0 +0 53 nan nan 53 nan -inf 3/1 +0 53 nan nan 53 nan -7 -7/1 +0 53 nan nan 53 nan -7 0 +0 53 nan nan 53 nan -7 7/1 +0 53 nan nan 53 nan -0 -15/1 +0 53 nan nan 53 nan -0 0 +0 53 nan nan 53 nan -0 15/1 +0 53 nan nan 53 nan 1 -31/1 +0 53 nan nan 53 nan 1 0 +0 53 nan nan 53 nan 1 31/1 +0 53 nan nan 53 nan +inf -63/1 +0 53 nan nan 53 nan +inf 0 +0 53 nan nan 53 nan +inf 63/1 +0 53 +inf +inf 53 -inf -inf -2/1 +0 53 -inf +inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2/1 + +1 53 0x12492492492492p-53 +inf + 53 -inf -4 -7/1 +0 53 -inf +inf 53 -inf -7 0 +2 53 -inf -0x12492492492492p-53 + 53 -inf -4 7/1 + +0 53 +0 +inf 53 -inf -0 -8/1 +0 53 -inf nan 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8/1 +0 53 -0.5 +inf 53 -inf 8 -16/1 +0 53 -inf +inf 53 -inf 8 0 +0 53 -inf 0.5 53 -inf 8 16/1 +0 53 -inf +inf 53 -inf +inf -32/1 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32/1 +0 53 nan nan 53 -inf nan -64/1 +0 53 nan nan 53 -inf nan 0 +0 53 nan nan 53 -inf nan 64/1 +0 53 +0 -0 53 +0 -0 -1/1 +0 53 nan nan 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1/1 + +1 53 -0x1aaaaaaaaaaaabp-49 -0 + 53 +0 8 -3/5 +0 53 nan +inf 53 +0 8 0 +2 53 +0 +0x1aaaaaaaaaaaabp-49 + 53 +0 8 3/5 + +0 53 -inf -0 53 +0 +inf -7/1 +0 53 nan +inf 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7/1 +0 53 -inf -inf 53 +inf +inf -1/1 +0 53 -inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1/1 +0 53 nan nan 53 +inf nan -1/1 +0 53 nan nan 53 +inf nan 0 +0 53 nan nan 53 +inf nan 1/1 + +# regular values +0 53 0x55p-5 5 + 53 -32 -17 -32/5 +0 53 -5 -0x55p-5 + 53 -32 -17 32/5 +1 53 -0x12d2d2d2d2d2d3p-49 -5 + 53 -32 -17 17/5 + +0 53 0x123456789abcdfp-61 0x123456789abcdfp-8 + 53 0x123456789abcdfp-53 0x123456789abcdf 256/1 +1 53 0x15555555555555p-54 1 + 53 1 3 3/1 +2 53 -3 0x15555555555556p-54 + 53 -9 1 3/1 +3 53 -0x1aaaaaaaaaaaabp-49 0x1aaaaaaaaaaaabp-49 + 53 -8 8 3/5 + +0 53 -0x45600 -0x12300 + 53 0x123 0x456 -1/256 +1 53 -0x15555555555556p-54 8 + 53 -24 1 -3/1 +2 53 -8 0x15555555555556p-54 + 53 -1 24 -3/1 +3 53 -0x1aaaaaaaaaaaabp-49 0x1aaaaaaaaaaaabp-49 + 53 -8 8 -3/5 diff --git a/tests/div_si.dat b/tests/div_si.dat new file mode 100644 index 0000000..de17ed2 --- /dev/null +++ b/tests/div_si.dat @@ -0,0 +1,91 @@ +# data file for mpfi_div_si +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan nan 53 nan -inf -3 +0 53 nan nan 53 nan -inf 0 +0 53 nan nan 53 nan -inf 3 +0 53 nan nan 53 nan -7 -7 +0 53 nan nan 53 nan -7 0 +0 53 nan nan 53 nan -7 7 +0 53 nan nan 53 nan -0 -15 +0 53 nan nan 53 nan -0 0 +0 53 nan nan 53 nan -0 15 +0 53 nan nan 53 nan 1 -31 +0 53 nan nan 53 nan 1 0 +0 53 nan nan 53 nan 1 31 +0 53 nan nan 53 nan +inf -63 +0 53 nan nan 53 nan +inf 0 +0 53 nan nan 53 nan +inf 63 +0 53 +inf +inf 53 -inf -inf -2 +0 53 -inf +inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf +2 +0 53 .25 +inf 53 -inf -1 -4 +0 53 -inf +inf 53 -inf -1 0 +0 53 -inf -.25 53 -inf -1 4 +0 53 +0 +inf 53 -inf -0 -8 +0 53 -inf nan 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8 +0 53 -0.5 +inf 53 -inf +8 -16 +0 53 -inf +inf 53 -inf +8 0 +0 53 -inf 0.5 53 -inf +8 16 +0 53 -inf +inf 53 -inf +inf -32 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf +32 +0 53 nan nan 53 -inf nan -64 +0 53 nan nan 53 -inf nan 0 +0 53 nan nan 53 -inf nan +64 +0 53 +0 -0 53 +0 -0 -1 +0 53 nan nan 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1 +0 53 -2 -0 53 +0 +8 -4 +0 53 nan +inf 53 +0 +8 0 +0 53 +0 2 53 +0 +8 4 +0 53 -inf -0 53 +0 +inf -7 +0 53 nan +inf 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7 +0 53 -inf -inf 53 +inf +inf -1 +0 53 -inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 nan nan 53 +inf nan -1 +0 53 nan nan 53 +inf nan 0 +0 53 nan nan 53 +inf nan 1 + +# regular values +0 53 0x11p-5 1 + 53 -32 -17 -32 +0 53 -1 -0x11p-5 + 53 -32 -17 32 +1 53 -0x1e1e1e1e1e1e1fp-52 -1 + 53 -32 -17 17 + +0 53 0x123456789abcdfp-61 0x123456789abcdfp-8 + 53 0x123456789abcdfp-53 0x123456789abcdf 256 +1 53 0x15555555555555p-54 1 + 53 1 3 3 +2 53 -3 0x15555555555556p-54 + 53 -9 1 3 +3 53 -0x1ccccccccccccdp-52 0x1ccccccccccccdp-52 + 53 -9 9 5 + +0 53 -0x456p-8 -0x123p-8 + 53 0x123 0x456 -256 +1 53 -0x15555555555556p-54 8 + 53 -24 1 -3 +2 53 -8 0x15555555555556p-54 + 53 -1 24 -3 +3 53 -0x12344444567889p-50 -0x12344444567888p-69 + 53 -0x123456789abcdfp-34 -0x123456789abcdfp-53 0x10001 diff --git a/tests/div_ui.dat b/tests/div_ui.dat new file mode 100644 index 0000000..fda3cd3 --- /dev/null +++ b/tests/div_ui.dat @@ -0,0 +1,63 @@ +# data file for mpfi_div_ui +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan nan 53 nan -inf 0 +0 53 nan nan 53 nan -inf 3 +0 53 nan nan 53 nan -7 0 +0 53 nan nan 53 nan -7 7 +0 53 nan nan 53 nan -0 0 +0 53 nan nan 53 nan -0 15 +0 53 nan nan 53 nan 1 0 +0 53 nan nan 53 nan 1 31 +0 53 nan nan 53 nan +inf 0 +0 53 nan nan 53 nan +inf 63 +0 53 -inf +inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf +2 +0 53 -inf +inf 53 -inf -1 0 +0 53 -inf -.25 53 -inf -1 4 +0 53 -inf nan 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8 +0 53 -inf +inf 53 -inf +8 0 +0 53 -inf 0.5 53 -inf +8 16 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf +32 +0 53 nan nan 53 -inf nan 0 +0 53 nan nan 53 -inf nan +64 +0 53 nan nan 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1 +0 53 nan +inf 53 +0 +8 0 +0 53 +0 2 53 +0 +8 4 +0 53 nan +inf 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7 +0 53 -inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 nan nan 53 +inf nan 0 +0 53 nan nan 53 +inf nan 1 + +# regular values +0 53 -1 -0x11p-5 + 53 -32 -17 32 +1 53 -0x1e1e1e1e1e1e1fp-52 -1 + 53 -32 -17 17 + +0 53 0x123456789abcdfp-61 0x123456789abcdfp-8 + 53 0x123456789abcdfp-53 0x123456789abcdf 256 +1 53 0x15555555555555p-54 1 + 53 1 3 3 +2 53 -3 0x15555555555556p-54 + 53 -9 1 3 +3 53 -0x1ccccccccccccdp-52 0x1ccccccccccccdp-52 + 53 -9 9 5 diff --git a/tests/div_z.dat b/tests/div_z.dat new file mode 100644 index 0000000..f978f0f --- /dev/null +++ b/tests/div_z.dat @@ -0,0 +1,100 @@ +# data file for mpfi_div_z +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan nan 53 nan -inf -3 +0 53 nan nan 53 nan -inf 0 +0 53 nan nan 53 nan -inf 3 +0 53 nan nan 53 nan -7 -7 +0 53 nan nan 53 nan -7 0 +0 53 nan nan 53 nan -7 7 +0 53 nan nan 53 nan -0 -15 +0 53 nan nan 53 nan -0 0 +0 53 nan nan 53 nan -0 15 +0 53 nan nan 53 nan 1 -31 +0 53 nan nan 53 nan 1 0 +0 53 nan nan 53 nan 1 31 +0 53 nan nan 53 nan +inf -63 +0 53 nan nan 53 nan +inf 0 +0 53 nan nan 53 nan +inf 63 +0 53 +inf +inf 53 -inf -inf -2 +0 53 -inf +inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2 + +1 53 0x12492492492492p-53 +inf + 53 -inf -4 -7 +0 53 -inf +inf 53 -inf -7 0 +2 53 -inf -0x12492492492492p-53 + 53 -inf -4 7 + +0 53 +0 +inf 53 -inf -0 -8 +0 53 -inf nan 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8 +0 53 -0.5 +inf 53 -inf +8 -16 +0 53 -inf +inf 53 -inf +8 0 +0 53 -inf 0.5 53 -inf +8 16 +0 53 -inf +inf 53 -inf +inf -32 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32 +0 53 nan nan 53 -inf nan -64 +0 53 nan nan 53 -inf nan 0 +0 53 nan nan 53 -inf nan 64 +0 53 +0 -0 53 +0 -0 -1 +0 53 nan nan 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1 + +# the precision of the result is to small for the mpz value +1 4 -0x10p-11 -0 + 53 +0 8 -1025 +0 53 nan +inf 53 +0 8 0 +2 4 +0 0x10p-11 + 53 +0 8 1025 + +0 53 -inf -0 53 +0 +inf -7 +0 53 nan +inf 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7 +0 53 -inf -inf 53 +inf +inf -1 +0 53 -inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 nan nan 53 +inf nan -1 +0 53 nan nan 53 +inf nan 0 +0 53 nan nan 53 +inf nan 1 + +# regular values +0 53 0x11p-5 1 + 53 -32 -17 -32 +0 53 -1 -0x11p-5 + 53 -32 -17 32 +1 53 -0x1e1e1e1e1e1e1fp-52 -1 + 53 -32 -17 17 + +0 53 0x123456789abcdfp-61 0x123456789abcdfp-8 + 53 0x123456789abcdfp-53 0x123456789abcdf 256 +1 53 0x15555555555555p-54 1 + 53 1 3 3 +2 53 -3 0x15555555555556p-54 + 53 -9 1 3 +3 53 -0x1ccccccccccccdp-52 0x1ccccccccccccdp-52 + 53 -9 9 5 + +0 53 -0x456p-8 -0x123p-8 + 53 0x123 0x456 -256 +1 53 -0x15555555555556p-54 8 + 53 -24 1 -3 +2 53 -8 0x15555555555556p-54 + 53 -1 24 -3 +3 53 -0x12344444567889p-50 -0x12344444567888p-69 + 53 -0x123456789abcdfp-34 -0x123456789abcdfp-53 0x10001 diff --git a/tests/exp.dat b/tests/exp.dat new file mode 100644 index 0000000..f780ac4 --- /dev/null +++ b/tests/exp.dat @@ -0,0 +1,36 @@ +# data file for mpfi_exp +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan -0 53 nan -inf +0 53 0x1de16b9c24a98ep-63 nan 53 -7 nan +0 53 nan 1 53 nan -0 +0 53 1 nan 53 +0 nan +0 53 nan 0x15bf0a8b14576ap-51 53 nan +1 +0 53 +inf nan 53 +inf nan +0 53 +0 -0 53 -inf -inf +2 53 +0 0x1de16b9c24a98fp-63 53 -inf -7 +0 53 +0 1 53 -inf -0 +2 53 +0 0x15bf0a8b14576ap-51 53 -inf +1 +0 53 +0 +inf 53 -inf +inf +0 53 1 1 53 +0 -0 +2 53 1 0x15bf0a8b14576ap-51 53 +0 +1 +0 53 1 +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +3 53 0x1766b45dd84f17p-230 0x1639e3175a689dp-77 53 -123 -17 +3 53 0x1c3d6a24ed8221p-53 0x148b5e3c3e8187p-52 53 -0.125 0.25 +1 53 0x1c3d6a24ed8221p-53 1 53 -0.125 -0 +2 53 1 0x148b5e3c3e8187p-52 53 +0 0.25 +3 53 0x10000000000140p-52 0x10000000000161p-52 53 0xap-47 0xbp-47 diff --git a/tests/exp2.dat b/tests/exp2.dat new file mode 100644 index 0000000..2d663c3 --- /dev/null +++ b/tests/exp2.dat @@ -0,0 +1,37 @@ +# data file for mpfi_exp2 +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan -0 53 nan -inf +0 53 0.5 nan 53 -1 nan +0 53 nan 1 53 nan -0 +0 53 1 nan 53 +0 nan +0 53 nan 2 53 nan 1 +0 53 +inf nan 53 +inf nan +0 53 +0 -0 53 -inf -inf +0 53 +0 0.5 53 -inf -1 +0 53 +0 1 53 -inf -0 +0 53 +0 2 53 -inf 1 +0 53 +0 +inf 53 -inf +inf +0 53 1 1 53 +0 -0 +0 53 1 2 53 +0 +1 +0 53 1 +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +0 53 0x1p-123 0x1p-17 53 -123 -17 +0 53 0x1p-7 0x1p+7 53 -7 7 +3 53 0x1d5818dcfba487p-53 0x1306fe0a31b716p-52 53 -0.125 0.25 +1 53 0x1d5818dcfba487p-53 1 53 -0.125 -0 +2 53 1 0x1306fe0a31b716p-52 53 +0 0.25 +3 53 0x100000000000ddp-52 0x100000000000f4p-52 53 0xap-47 0xbp-47 diff --git a/tests/expm1.dat b/tests/expm1.dat new file mode 100644 index 0000000..09a0336 --- /dev/null +++ b/tests/expm1.dat @@ -0,0 +1,36 @@ +# data file for mpfi_expm1 +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan -1 53 nan -inf +0 53 -0x1ff887a518f6d6p-53 nan 53 -7 nan +0 53 nan -0 53 nan -0 +0 53 +0 nan 53 +0 nan +0 53 nan 0x1b7e151628aed3p-52 53 nan 1 +0 53 +inf nan 53 +inf nan +0 53 -1 -1 53 -inf -inf +2 53 -1 -0x1ff887a518f6d5p-53 53 -inf -7 +0 53 -1 -0 53 -inf -0 +2 53 -1 0x1b7e151628aed3p-52 53 -inf 1 +0 53 -1 +inf 53 -inf +inf +0 53 +0 -0 53 +0 -0 +2 53 +0 0x1b7e151628aed3p-52 53 +0 1 +0 53 +0 +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +3 53 -0x1ffffffffffffep-53 -0x1ffffffffffffdp-53 53 -36 -36 +3 53 -0x1e14aed893eef4p-56 0x122d78f0fa061ap-54 53 -0.125 0.25 +1 53 -0x1e14aed893eef4p-56 -0 53 -0.125 -0 +2 53 +0 0x122d78f0fa061ap-54 53 +0 0.25 +3 53 0x140000000000c8p-96 0x160000000000f3p-96 53 0xap-47 0xbp-47 diff --git a/tests/fr_div.dat b/tests/fr_div.dat new file mode 100644 index 0000000..4fffdfb --- /dev/null +++ b/tests/fr_div.dat @@ -0,0 +1,79 @@ +# data file for mpfi_fr_div +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: value of first parameter +# 7: precision of second parameter +# 8: left endpoint value of second parameter +# 9: right endpoint value of second parameter + +# special values +0 53 nan nan 53 -0x170ef54646d497p-109 53 nan nan +0 53 nan nan 53 0.0 53 nan nan +0 53 nan nan 53 0x170ef54646d497p-109 53 nan nan +0 53 nan nan 53 -0x114b37f4b51f71p-107 53 nan -inf +0 53 nan nan 53 0.0 53 nan -inf +0 53 nan nan 53 0x114b37f4b51f71p-107 53 nan -inf +0 53 nan nan 53 -0xfc339ab0a6b53p-99 53 nan -7 +0 53 nan nan 53 0.0 53 nan -7 +0 53 nan nan 53 7.0 53 nan -7 +0 53 nan nan 53 -15.0 53 nan -0 +0 53 nan nan 53 0.0 53 nan -0 +0 53 nan nan 53 15.0 53 nan -0 +0 53 nan nan 53 -0xb2b3ece0a4ef9p-103 53 nan 1 +0 53 nan nan 53 0.0 53 nan 1 +0 53 nan nan 53 0xb2b3ece0a4ef9p-103 53 nan 1 +0 53 nan nan 53 -0x5acae5c4b6e51p-101 53 nan +inf +0 53 nan nan 53 0.0 53 nan +inf +0 53 nan nan 53 0x5acae5c4b6e51p-101 53 nan +inf +0 53 +0 -0 53 -0x170ef54646d497p-108 53 -inf -inf +0 53 +0 -0 53 0.0 53 -inf -inf +0 53 +0 -0 53 0x170ef54646d497p-108 53 -inf -inf +2 53 +0 0x1a5a3ce29a1787p-110 53 -0x170ef54646d496p-107 53 -inf -7 +0 53 +0 -0 53 0.0 53 -inf -7 +1 53 -0x1a5a3ce29a1787p-110 -0 53 0x170ef54646d496p-107 53 -inf -7 +0 53 +0 +inf 53 -0x170ef54646d497p-106 53 -inf -0 +0 53 +0 -0 53 0.0 53 -inf -0 +0 53 -inf -0 53 0x170ef54646d497p-106 53 -inf -0 +0 53 -inf +inf 53 -0x16345785d8a00000 53 -inf 8 +0 53 -inf +inf 53 0.0 53 -inf 8 +0 53 -inf +inf 53 0x16345785d8a00000 53 -inf 8 +0 53 -inf +inf 53 -0x170ef54646d497p-105 53 -inf +inf +0 53 -inf +inf 53 0.0e-17 53 -inf +inf +0 53 -inf +inf 53 +0x170ef54646d497p-105 53 -inf +inf +0 53 nan nan 53 -0x170ef54646d497p-104 53 -inf nan +0 53 nan nan 53 0.0e-17 53 -inf nan +0 53 nan nan 53 +0x170ef54646d497p-104 53 -inf nan +0 53 -inf +inf 53 -0x170ef54646d497p-109 53 +0 -0 +0 53 +0 -0 53 0.0 53 +0 -0 +0 53 -inf +inf 53 0x170ef54646d497p-109 53 +0 -0 +2 53 -inf -0x13c3ada9f391a5p-110 53 -0x114b37f4b51f71p-107 53 +0 7 +0 53 +0 -0 53 0.0 53 +0 7 +1 53 0x13c3ada9f391a5p-110 +inf 53 0x114b37f4b51f71p-107 53 +0 7 +0 53 -inf -0 53 -0x50b45a75f7e81p-104 53 +0 +inf +0 53 +0 -0 53 0.0 53 +0 +inf +0 53 +0 +inf 53 0x142d169d7dfa03p-106 53 +0 +inf +0 53 +0 -0 53 -0x170ef54646d497p-109 53 +inf +inf +0 53 +0 -0 53 0.0 53 +inf +inf +0 53 +0 -0 53 0x170ef54646d497p-109 53 +inf +inf +0 53 nan nan 53 -0x170ef54646d497p-109 53 +inf nan +0 53 nan nan 53 0.0 53 +inf nan +0 53 nan nan 53 0x170ef54646d497p-109 53 +inf nan + +# regular values +0 53 -inf +inf 53 -2.5 53 -8 8 + +0 53 0x5p-4 0.5 53 -2.5 53 -8 -5 +1 53 -0x1999999999999ap-56 -0x1p-4 53 -2.5 53 25 40 +2 53 0x5p-5 0x16db6db6db6db7p-54 53 -2.5 53 -16 -7 +3 53 -0x1d1745d1745d18p-55 -0x11e6efe35b4cfap-58 53 -2.5 53 11 143 + +0 53 0x1p-4 4 53 33.125 53 8.28125 530 +1 53 -0x11111111111112p-56 -0x1p-4 53 33.125 53 -530 -496.875 +2 53 0.125 0x13a12f684bda13p-53 53 33.125 53 54 265 +3 53 0x13a12f684bda12p-53 0x14627627627628p-53 53 33.125 53 52 54 diff --git a/tests/fr_sub.dat b/tests/fr_sub.dat new file mode 100644 index 0000000..02904d8 --- /dev/null +++ b/tests/fr_sub.dat @@ -0,0 +1,115 @@ +# data file for mpfi_fr_sub +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: value of first parameter +# 7: precision of second parameter +# 8: left endpoint value of second parameter +# 9: right endpoint value of second parameter + +# special values +0 53 nan nan 53 -0x170ef54646d497p-109 53 nan nan +0 53 nan nan 53 0.0 53 nan nan +0 53 nan nan 53 0x170ef54646d497p-109 53 nan nan +0 53 +inf nan 53 -0x114b37f4b51f71p-107 53 nan -inf +0 53 +inf nan 53 0.0 53 nan -inf +0 53 +inf nan 53 0x114b37f4b51f71p-107 53 nan -inf +0 53 0x1bfffffffffff8p-50 nan 53 -0xfc339ab0a6b53p-99 53 nan -7 +0 53 7 nan 53 0.0 53 nan -7 +0 53 0x1c000000000007p-50 nan 53 0xfc339ab0a6b53p-99 53 nan -7 +0 53 -15 nan 53 -15.0 53 nan -0 +0 53 +0 nan 53 0.0 53 nan -0 +0 53 15 nan 53 15.0 53 nan -0 +0 53 -0x8000000000001p-51 nan 53 -0xb2b3ece0a4ef9p-103 53 nan 1 +0 53 -1 nan 53 0.0 53 nan 1 +0 53 -0xfffffffffffffp-52 nan 53 0xb2b3ece0a4ef9p-103 53 nan 1 +0 53 -inf nan 53 -0x5acae5c4b6e51p-101 53 nan +inf +0 53 -inf nan 53 0.0 53 nan +inf +0 53 -inf nan 53 0x5acae5c4b6e51p-101 53 nan +inf +0 53 +inf +inf 53 -0x170ef54646d497p-108 53 -inf -inf +0 53 +inf +inf 53 0.0 53 -inf -inf +0 53 +inf +inf 53 0x170ef54646d497p-108 53 -inf -inf +1 53 0x1bffffffffffffp-50 +inf 53 -0x170ef54646d497p-107 53 -inf -7 +0 53 7 +inf 53 0.0 53 -inf -7 +1 53 7 +inf 53 0x170ef54646d497p-107 53 -inf -7 +0 53 -0x170ef54646d497p-96 +inf 53 -0x170ef54646d497p-96 53 -inf -0 +0 53 +0 +inf 53 0.0 53 -inf -0 +0 53 0x170ef54646d497p-96 +inf 53 0x170ef54646d497p-96 53 -inf -0 +1 53 -0x16345785d8a00100 +inf 53 -0x16345785d8a00000 53 -inf 8 +0 53 -8 +inf 53 0.0 53 -inf 8 +1 53 0x16345785d89fff00 +inf 53 0x16345785d8a00000 53 -inf 8 +0 53 -inf +inf 53 -0x170ef54646d497p-105 53 -inf +inf +0 53 -inf +inf 53 0.0e-17 53 -inf +inf +0 53 -inf +inf 53 0x170ef54646d497p-105 53 -inf +inf +0 53 nan +inf 53 -0x170ef54646d497p-104 53 -inf nan +0 53 nan +inf 53 0.0e-17 53 -inf nan +0 53 nan +inf 53 0x170ef54646d497p-104 53 -inf nan +0 53 -0x170ef54646d497p-109 -0x170ef54646d497p-109 + 53 -0x170ef54646d497p-109 + 53 +0 -0 +0 53 +0 -0 53 0.0 53 +0 -0 +0 53 0x170ef54646d497p-109 0x170ef54646d497p-109 + 53 0x170ef54646d497p-109 + 53 +0 -0 +1 53 -0x10000000000001p-49 -0x114b37f4b51f71p-107 + 53 -0x114b37f4b51f71p-107 + 53 +0 8 +0 53 -8 -0 53 0.0 53 +0 8 +1 53 -8 0x114b37f4b51f71p-107 + 53 0x114b37f4b51f71p-107 + 53 +0 8 +0 53 -inf -0x50b45a75f7e81p-104 + 53 -0x50b45a75f7e81p-104 + 53 +0 +inf +0 53 -inf -0 53 0.0 53 +0 +inf +0 53 -inf -0x142d169d7dfa03p-106 + 53 -0x142d169d7dfa03p-106 + 53 +0 +inf +0 53 -inf -inf 53 0x142d169d7dfa03p-106 53 +inf +inf +0 53 -inf -inf 53 -0x170ef54646d497p-109 53 +inf +inf +0 53 -inf -inf 53 0.0 53 +inf +inf +0 53 nan -inf 53 0x170ef54646d497p-109 53 +inf nan +0 53 nan -inf 53 -0x170ef54646d497p-109 53 +inf nan +0 53 nan -inf 53 0.0 53 +inf nan + +# regular values +0 53 -0x1fb53d14aa9c2fp-47 -0x18353d14aa9c2fp-47 + 53 -0xfb53d14aa9c2fp-47 + 53 17 32 +0 53 +0 0x7353d14aa9c2fp-47 + 53 0xfb53d14aa9c2fp-47 + 53 17 0xfb53d14aa9c2fp-47 +0 53 -0x104ac2eb5563d1p-48 -0 + 53 0xfb53d14aa9c2fp-48 + 53 0xfb53d14aa9c2fp-48 32 + +0 53 0x15b456789abcdfp-48 0x123456789abd17p-4 + 53 3.5 + 53 -0x123456789abcdfp-4 -0x123456789abcdfp-48 +1 53 0x3923456789abcdp-52 0x123456789abd17p-4 + 53 3.5 + 53 -0x123456789abcdfp-4 -0x123456789abcdfp-56 +2 53 0x18p-4 0x101a3456789abdp-44 + 53 256.5 + 53 -0x123456789abcdfp-52 0xff +3 53 0xfff8p-4 0x10018p-4 + 53 4097.5 + 53 0x1p-550 0x1fffffffffffffp-52 + +0 53 0xeb456789abcdfp-48 0x123456789abca7p-4 + 53 -3.5 + 53 -0x123456789abcdfp-4 -0x123456789abcdfp-48 +1 53 -0x36dcba98765434p-52 0x123456789abca7p-4 + 53 -3.5 + 53 -0x123456789abcdfp-4 -0x123456789abcdfp-56 +2 53 -0x1ff8p-4 -0xff5cba9876543p-44 + 53 -256.5 + 53 -0x123456789abcdfp-52 0xff +3 53 -0x10038p-4 -0x10018p-4 + 53 -4097.5 + 53 0x1p-550 0x1fffffffffffffp-52 diff --git a/tests/has_zero.dat b/tests/has_zero.dat new file mode 100644 index 0000000..2e17c54 --- /dev/null +++ b/tests/has_zero.dat @@ -0,0 +1,42 @@ +# data file for mpfi_has_zero +# +# column fields: +# 1: return value (0: false, +: true) +# 2: precision of argument +# 3: left endpoint value of argument +# 4: right endpoint value of argument +# + +# special values +0 53 nan -inf +0 53 nan -8 +0 53 -8 nan +0 53 nan -0 +0 53 +0 nan +0 53 nan 5 +0 53 5 nan +0 53 nan +inf +0 53 nan nan +0 53 -inf -inf +0 53 -inf -8 ++ 53 -inf -0 ++ 53 -inf 5 ++ 53 -inf +inf +0 53 -inf nan ++ 53 -8 -0 ++ 53 +0 -0 ++ 53 +0 5 ++ 53 +0 +inf +0 53 5 +inf +0 53 +inf +inf +0 53 +inf nan + +# regular values +0 8 -34 -17 +0 8 -8 -8 ++ 8 -34 17 ++ 53 -0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 64 +8 +8 +0 53 +8 +0x7fffffffffffbp+51 +0 53 +0x1fffffffffffffp-53 2 diff --git a/tests/hypot.dat b/tests/hypot.dat new file mode 100644 index 0000000..e47f990 --- /dev/null +++ b/tests/hypot.dat @@ -0,0 +1,73 @@ +# data file for mpfi_hypot +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of second parameter +# 8: precision of second parameter +# 9: left endpoint value of second parameter +# 10: right endpoint value of second parameter + +# special values +0 53 +inf +inf 53 nan nan 53 -inf -inf +0 53 nan nan 53 nan nan 53 -inf -7 +0 53 nan nan 53 nan nan 53 -8 +1 +0 53 nan nan 53 nan nan 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 nan +0 53 nan nan 53 nan nan 53 5 +inf +0 53 +inf +inf 53 nan nan 53 +inf +inf +0 53 nan nan 53 nan nan 53 nan -0 +0 53 +inf +inf 53 nan -0 53 -inf -inf +0 53 nan nan 53 nan -0 53 -inf -7 +0 53 nan nan 53 nan -0 53 -8 1 +0 53 nan nan 53 nan +inf 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 7 +0 53 nan nan 53 nan -inf 53 5 +inf +0 53 +inf +inf 53 nan -7 53 +inf +inf +0 53 nan nan 53 nan 1 53 nan -0 +0 53 +inf +inf 53 -inf -inf 53 -inf -inf +0 53 7 +inf 53 -inf -7 53 -1 8 +0 53 8 +inf 53 -inf -0 53 8 +inf +0 53 +inf +inf 53 -inf -0 53 +inf +inf +0 53 +0 +inf 53 -inf 8 53 +0 8 +0 53 +0 +inf 53 -inf +inf 53 +0 8 +0 53 7 +inf 53 +0 -0 53 -inf -7 +0 53 +0 5 53 +0 3 53 -4 -0 +0 53 +0 8 53 +0 -0 53 +0 8 +0 53 +0 +inf 53 +0 +inf 53 +0 8 +0 53 8 +inf 53 +0 -0 53 8 +inf +0 53 nan nan 53 +0 8 53 +inf nan +0 53 +0 +inf 53 +0 -0 53 -inf +inf +0 53 +0 13 53 +0 5 53 +0 12 +0 53 +0 -0 53 +0 -0 53 +0 -0 +0 53 +0 +inf 53 +0 +inf 53 -7 8 +0 53 nan nan 53 +0 nan 53 8 +inf +0 53 +inf +inf 53 +0 8 53 +inf +inf +0 53 +inf +inf 53 +inf +inf 53 -inf 3 +0 53 +inf +inf 53 +inf +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf 53 3 nan +0 53 nan nan 53 +inf nan 53 -inf -7 +0 53 +inf +inf 53 +inf nan 53 +inf +inf +0 53 nan nan 53 +inf nan 53 -3 7 + +# regular values +0 53 13 37 + 53 -12 -5 + 53 -35 -12 + +1 53 0x1854bfb363dc39p-50 25 + 53 6 7 + 53 1 24 + +2 53 0 0x19f625847a5899p-48 + 53 -4 +7 + 53 -25 3 + +3 53 0x113463fa37014dp-49 0x125b89092b8fc0p-47 + 53 0x1854bfb363dc39p-50 0x19f625847a5899p-48 + 53 0x1854bfb363dc39p-50 0x19f625847a5899p-48 diff --git a/tests/increase.dat b/tests/increase.dat new file mode 100644 index 0000000..c4b482a --- /dev/null +++ b/tests/increase.dat @@ -0,0 +1,104 @@ +# data file for mpfi_increase +# +# fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: precision of argument +# 9: value of argument + +# special values +53 nan nan 0 53 nan nan 53 -0x170ef54646d497p-109 +53 nan nan 0 53 nan nan 53 -0 +53 nan nan 0 53 nan nan 53 0x170ef54646d497p-109 +53 nan -inf 0 53 nan -inf 53 -0x114b37f4b51f71p-107 +53 nan -inf 0 53 nan -inf 53 +0 +53 nan -inf 0 53 nan -inf 53 0x114b37f4b51f71p-107 +53 nan -7 0 53 nan -7 53 -0 +53 nan -0 0 53 nan -0 53 7 +53 nan 1 0 53 nan 1 53 3 +53 nan +inf 0 53 nan +inf 53 -0x5acae5c4b6e51p-101 +53 nan +inf 0 53 nan +inf 53 +0 +53 nan +inf 0 53 nan +inf 53 0x5acae5c4b6e51p-101 + +53 -inf -inf 0 53 -inf -inf 53 -0x170ef54646d497p-108 +53 -inf -inf 0 53 -inf -inf 53 +0 +53 -inf -inf 0 53 -inf -inf 53 0x170ef54646d497p-108 +53 -inf -inf 0 53 nan nan 53 nan +53 -inf -7 0 53 -inf -8 53 -1 +53 -inf -7 0 53 -inf -6 53 1 +53 -inf -0x1bffffffffffffp-50 2 53 -inf -7 53 -0x170ef54646d497p-102 +53 -inf -0x170ef54646d497p-106 0 53 -inf -0 53 0x170ef54646d497p-106 +53 -inf -0 0 53 -inf -0 53 +0 +53 -inf 0x170ef54646d497p-106 0 53 -inf -0 53 -0x170ef54646d497p-106 +53 -inf -0x16345785d89ff8 0 53 -inf 8 53 0x16345785d8a000 +53 -inf 8 0 53 -inf 8 53 -0 +53 -inf 0x16345785d89ff0p-52 0 53 -inf 8 53 0x69cba87a276010p-52 +53 -inf +inf 0 53 -inf +inf 53 -0x170ef54646d497p-105 +53 -inf +inf 0 53 -inf +inf 53 +0 +53 -inf +inf 0 53 -inf +inf 53 +0x170ef54646d497p-105 +53 -inf nan 0 53 -inf nan 53 -0x170ef54646d497p-104 +53 -inf nan 0 53 -inf nan 53 -0 +53 -inf nan 0 53 -inf nan 53 +0x170ef54646d497p-104 + + 53 -0x170ef54646d497p-109 -0x170ef54646d497p-109 +0 53 -0x2e1dea8c8da92ep-109 -0 53 0x170ef54646d497p-109 + 53 +0 -0 +0 53 +0 -0 53 +0 + 53 0x170ef54646d497p-109 0x170ef54646d497p-109 +0 53 +0 0x2e1dea8c8da92ep-109 53 0x170ef54646d497p-109 + 53 +0 8 +0 53 +0 8 53 -0 + 53 -0x10000000000001p-49 -0x114b37f4b51f7p-103 +1 53 -0x10000000000002p-49 -0 53 0x114b37f4b51f7p-103 + 53 +0 -0 +0 53 nan nan 53 nan + + 53 -0x50b45a75f7e81p-104 +inf +0 53 +0 +inf 53 -0x50b45a75f7e81p-104 + 53 +0 +inf +0 53 +0 +inf 53 +0 + 53 0x142d169d7dfa03p-106 +inf +0 53 +0 +inf 53 0x142d169d7dfa03p-106 + +53 +inf +inf 0 53 +inf +inf 53 -0x170ef54646d497p-109 +53 +inf +inf 0 53 +inf +inf 53 -0 +53 +inf +inf 0 53 +inf +inf 53 0x170ef54646d497p-109 +53 +inf +inf 0 53 nan nan 53 nan +53 +inf nan 0 53 +inf nan 53 -0x170ef54646d497p-109 +53 +inf nan 0 53 +inf nan 53 +0 +53 +inf nan 0 53 +inf nan 53 0x170ef54646d497p-109 + +# regular values + 53 -0x10000000000001p-12 -0x10000000000001p-52 +0 53 -0x10000000001001p-12 -0x00000000000001p-52 53 1 + 53 -0x10000000000001 -0x10000000000001p-52 +1 53 -0x10000000000003 -0 53 0x10000000000001p-52 + 53 -0x10000000000001p-12 -0x10000000000001p-52 +2 53 -0x1000000000f001p-12 0xe 53 0xf + 53 -0x10000000000001p-12 -0x10000000000001p-52 +3 53 -0x10000000100003p-12 0xff001001000000p-48 53 0x100001001p-24 + + 53 -0x10000000000001p-52 0x10000000000001p-52 +0 53 -0x10000000000001p-51 0x10000000000001p-51 53 0x10000000000001p-52 + 53 -0x10000000000001p-12 0x10000000000001p-52 +1 53 -0x10000000001002p-12 0x10000000000001p-51 53 0x10000000000001p-52 + 53 -0x114b37f4b51f71p-107 8 +2 53 +0 8 53 -0x114b37f4b51f71p-107 + 53 -1 1 +3 53 -3 3 54 0x3fffffffffffffp-53 + + 53 0x10000000000001p-48 0x10000000000001 +0 53 0x0f000000000001p-48 0x10000000000002 53 1 + 53 0x10000000000001p-48 0x10000000000001 +1 53 -0xf0 0x10000000000101 53 0x100 + 53 0x10000000000001p-48 0x10000000000001 +2 53 -0x000fffffffffffp-48 0x10000000000012 53 0x101p-4 + 53 0x10000000000001p-48 0x10000000000001 +3 53 -0xf01p-4 0x10000000000102 53 0x1001p-4 diff --git a/tests/inf_p.dat b/tests/inf_p.dat new file mode 100644 index 0000000..5c7a2f0 --- /dev/null +++ b/tests/inf_p.dat @@ -0,0 +1,41 @@ +# data file for mpfi_inf_p +# +# column fields: +# 1: return value (0: false, +: true) +# 2: precision of argument +# 3: left endpoint value of argument +# 4: right endpoint value of argument +# + +# special values +0 53 nan -inf +0 53 nan -8 +0 53 -8 nan +0 53 nan -0 +0 53 +0 nan +0 53 nan 5 +0 53 5 nan +0 53 nan +inf +0 53 nan nan ++ 53 -inf -inf ++ 53 -inf -8 ++ 53 -inf -0 ++ 53 -inf 5 ++ 53 -inf +inf +0 53 -inf nan +0 53 -8 -0 +0 53 +0 -0 +0 53 +0 5 ++ 53 +0 +inf ++ 53 5 +inf ++ 53 +inf +inf +0 53 +inf nan + +# regular values +0 8 -34 -17 +0 8 -8 -1 +0 8 -34 17 +0 53 -0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 53 +8 +0x7fffffffffffbp+51 +0 53 +0x1fffffffffffffp-53 2 diff --git a/tests/inp_str.dat b/tests/inp_str.dat new file mode 100644 index 0000000..35f48cd --- /dev/null +++ b/tests/inp_str.dat @@ -0,0 +1,5 @@ +101011101011101001110110111110100000000000111100000000011111010001110001111011010000111111011001101111101100111101000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000011101100110101010011110111111111111111111111111111111111 + 12 + 9999901 +1.0001e-54 +1.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 diff --git a/tests/intersect.dat b/tests/intersect.dat new file mode 100644 index 0000000..30aa620 --- /dev/null +++ b/tests/intersect.dat @@ -0,0 +1,49 @@ +# data file for mpfi_intersect +# +# for a description of the fields: see add.dat + +# special values +0 53 nan nan 53 nan nan 53 -inf -7 +0 53 nan nan 53 nan nan 53 -8 +1 +0 53 nan nan 53 nan nan 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 nan +0 53 nan nan 53 nan nan 53 +5 +inf +0 53 nan nan 53 nan nan 53 +inf +inf +0 53 nan nan 53 nan nan 53 nan -0 +0 53 nan nan 53 nan -0 53 -inf -7 +0 53 nan nan 53 nan -0 53 -8 +1 +0 53 nan nan 53 nan +inf 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 +7 +0 53 nan nan 53 nan -inf 53 +5 +inf +0 53 nan nan 53 nan -7 53 +inf +inf +0 53 nan nan 53 nan +1 53 nan -0 +0 53 -inf -inf 53 -inf -inf 53 -inf -inf +3 53 -1 -7 53 -inf -7 53 -1 +8 # empty interval +3 53 +8 -0 53 -inf -0 53 +8 +inf # empty interval +3 53 +inf -0 53 -inf -0 53 +inf +inf # empty interval +0 53 +0 +8 53 -inf +8 53 +0 +8 +0 53 +0 +8 53 -inf +inf 53 +0 +8 +3 53 +0 -7 53 +0 -0 53 -inf -7 # empty interval +0 53 +0 -0 53 +0 +8 53 -7 -0 +0 53 +0 -0 53 +0 -0 53 +0 +8 +0 53 +0 +8 53 +0 +inf 53 +0 +8 +3 53 +8 -0 53 +0 -0 53 +8 +inf # empty interval +0 53 nan nan 53 +0 +8 53 +inf nan +0 53 +0 -0 53 +0 -0 53 -inf +inf +0 53 +0 +8 53 +0 +8 53 -7 +8 +0 53 +0 -0 53 +0 -0 53 +0 -0 +0 53 +0 +8 53 +0 +inf 53 +0 +8 +0 53 nan nan 53 +0 nan 53 +8 +inf +3 53 +inf +8 53 +0 +8 53 +inf +inf # empty interval +3 53 +inf +3 53 +inf +inf 53 -inf +3 # empty interval +0 53 +inf +inf 53 +inf +inf 53 +0 +inf +0 53 nan nan 53 +inf +inf 53 +3 nan +0 53 nan nan 53 +inf nan 53 -inf -7 +0 53 nan nan 53 +inf nan 53 +inf +inf +0 53 nan nan 53 +inf nan 53 -3 +7 + +# regular values +0 53 0x12 0x34 53 0x12 0x90 53 -0x0d 0x34 +1 12 0x8.efp-8 0x34 53 -0x0d 0x34 53 0x8.ef7p-8 0xa0 +2 12 -0x12 0x1.f3p+24 53 -0x2fp+12 0x9p+32 53 -0x12 0x1.f2ffffffp+24 +3 12 0x1.a1p-4 0x4.e78p-4 53 -1 0x8.237 53 0x1.a100001p-4 0x4.e7249961p-4 diff --git a/tests/inv.dat b/tests/inv.dat new file mode 100644 index 0000000..5c7d718 --- /dev/null +++ b/tests/inv.dat @@ -0,0 +1,31 @@ +# data file for mpfi_inv +# +# column fields: see neg.dat + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -64 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 nan +1 +0 53 nan nan 53 +inf nan +0 53 +0 -0 53 -inf -inf +0 53 -4 -0 53 -inf -.25 +0 53 -inf -0 53 -inf -0 +0 53 -inf +inf 53 -inf +4 +0 53 -inf +inf 53 -inf +inf +0 53 -inf +inf 53 +0 -0 +0 53 +.5 +inf 53 +0 +2 +0 53 +0 +inf 53 +0 +inf +0 53 +0 -0 53 +inf +inf + +# regular values +0 53 -.5 -0.125 + 53 -8 -2 +1 53 0x1947bfce1bc417p-52 0x10 + 53 0x1p-4 0x1440c131282cd9p-53 +2 53 0.015625 0x13bc205a76b3fdp-50 + 53 0x19f1a539c91fddp-55 +64 +3 53 -0x1480a9b5772a23p-50 -0x177887d65484c9p-52 + 53 -0xae83b95effd69p-52 -0x63e3cb4ed72a3p-53 diff --git a/tests/is_neg.dat b/tests/is_neg.dat new file mode 100644 index 0000000..5817b7a --- /dev/null +++ b/tests/is_neg.dat @@ -0,0 +1,41 @@ +# data file for mpfi_is_neg +# +# column fields: +# 1: return value (0: false, +: true) +# 2: precision of argument +# 3: left endpoint value of argument +# 4: right endpoint value of argument +# + +# special values +0 53 nan -inf +0 53 nan -8 +0 53 -8 nan +0 53 nan -0 +0 53 +0 nan +0 53 nan 5 +0 53 5 nan +0 53 nan +inf +0 53 nan nan ++ 53 -inf -inf ++ 53 -inf -8 ++ 53 -inf -0 +0 53 -inf 5 +0 53 -inf +inf +0 53 -inf nan ++ 53 -8 -0 +0 53 +0 -0 +0 53 +0 5 +0 53 +0 +inf +0 53 5 +inf +0 53 +inf +inf +0 53 +inf nan + +# regular values ++ 8 -34 -17 ++ 8 -8 -1 +0 8 -34 17 +0 53 -0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 53 +8 +0x7fffffffffffbp+51 +0 53 +0x1fffffffffffffp-53 2 diff --git a/tests/is_nonneg.dat b/tests/is_nonneg.dat new file mode 100644 index 0000000..1db947d --- /dev/null +++ b/tests/is_nonneg.dat @@ -0,0 +1,41 @@ +# data file for mpfi_is_nonneg +# +# column fields: +# 1: return value (0: false, +: true) +# 2: precision of argument +# 3: left endpoint value of argument +# 4: right endpoint value of argument +# + +# special values +0 53 nan -inf +0 53 nan -8 +0 53 -8 nan +0 53 nan -0 +0 53 +0 nan +0 53 nan 5 +0 53 5 nan +0 53 nan +inf +0 53 nan nan +0 53 -inf -inf +0 53 -inf -8 +0 53 -inf -0 +0 53 -inf 5 +0 53 -inf +inf +0 53 -inf nan +0 53 -8 -0 ++ 53 +0 -0 ++ 53 +0 5 ++ 53 +0 +inf ++ 53 5 +inf ++ 53 +inf +inf +0 53 +inf nan + +# regular values +0 8 -34 -17 +0 8 -8 -1 +0 8 -34 17 +0 53 -0x1921fb54442d18p-51 0x1921fb54442d19p-51 ++ 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 ++ 53 +8 +0x7fffffffffffbp+51 ++ 53 +0x1fffffffffffffp-53 2 diff --git a/tests/is_nonpos.dat b/tests/is_nonpos.dat new file mode 100644 index 0000000..96f1835 --- /dev/null +++ b/tests/is_nonpos.dat @@ -0,0 +1,41 @@ +# data file for mpfi_is_nonpos +# +# column fields: +# 1: return value (0: false, +: true) +# 2: precision of argument +# 3: left endpoint value of argument +# 4: right endpoint value of argument +# + +# special values +0 53 nan -inf +0 53 nan -8 +0 53 -8 nan +0 53 nan -0 +0 53 +0 nan +0 53 nan 5 +0 53 5 nan +0 53 nan +inf +0 53 nan nan ++ 53 -inf -inf ++ 53 -inf -8 ++ 53 -inf -0 +0 53 -inf 5 +0 53 -inf +inf +0 53 -inf nan ++ 53 -8 -0 ++ 53 +0 -0 +0 53 +0 5 +0 53 +0 +inf +0 53 5 +inf +0 53 +inf +inf +0 53 +inf nan + +# regular values ++ 8 -34 -17 ++ 8 -8 -1 +0 8 -34 17 +0 53 -0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 53 8 0x7fffffffffffbp+51 +0 53 0x1fffffffffffffp-53 2 diff --git a/tests/is_pos.dat b/tests/is_pos.dat new file mode 100644 index 0000000..cb9732a --- /dev/null +++ b/tests/is_pos.dat @@ -0,0 +1,43 @@ +# data file for mpfi_is_pos +# +# column fields: +# 1: return value (0: false, +: true) +# 2: precision of argument +# 3: left endpoint value of argument +# 4: right endpoint value of argument +# + +# special values +0 53 nan -inf +0 53 nan -8 +0 53 -8 nan +0 53 nan -0 +0 53 +0 nan +0 53 nan 5 +0 53 5 nan +0 53 nan +inf +0 53 nan nan +0 53 -inf -inf +0 53 -inf -8 +0 53 -inf -0 +0 53 -inf 5 +0 53 -inf +inf +0 53 -inf nan +0 53 -8 -0 + +0 53 +0 -0 #should it return true? + ++ 53 +0 5 ++ 53 +0 +inf ++ 53 5 +inf ++ 53 +inf +inf +0 53 +inf nan + +# regular values +0 8 -34 -17 +0 8 -8 -1 +0 8 -34 17 +0 53 -0x1921fb54442d18p-51 0x1921fb54442d19p-51 ++ 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 ++ 53 +8 +0x7fffffffffffbp+51 ++ 53 +0x1fffffffffffffp-53 2 diff --git a/tests/is_strictly_neg.dat b/tests/is_strictly_neg.dat new file mode 100644 index 0000000..494c674 --- /dev/null +++ b/tests/is_strictly_neg.dat @@ -0,0 +1,41 @@ +# data file for mpfi_is_strictly_neg +# +# column fields: +# 1: return value (0: false, +: true) +# 2: precision of argument +# 3: left endpoint value of argument +# 4: right endpoint value of argument +# + +# special values +0 53 nan -inf +0 53 nan -8 +0 53 -8 nan +0 53 nan -0 +0 53 +0 nan +0 53 nan 5 +0 53 5 nan +0 53 nan +inf +0 53 nan nan ++ 53 -inf -inf ++ 53 -inf -8 +0 53 -inf -0 +0 53 -inf 5 +0 53 -inf +inf +0 53 -inf nan +0 53 -8 -0 +0 53 +0 -0 +0 53 +0 5 +0 53 +0 +inf +0 53 5 +inf +0 53 +inf +inf +0 53 +inf nan + +# regular values ++ 8 -34 -17 ++ 8 -8 -1 +0 8 -34 17 +0 53 -0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 53 +8 +0x7fffffffffffbp+51 +0 53 +0x1fffffffffffffp-53 2 diff --git a/tests/is_strictly_pos.dat b/tests/is_strictly_pos.dat new file mode 100644 index 0000000..3349959 --- /dev/null +++ b/tests/is_strictly_pos.dat @@ -0,0 +1,41 @@ +# data file for mpfi_is_strictly_pos +# +# column fields: +# 1: return value (0: false, +: true) +# 2: precision of argument +# 3: left endpoint value of argument +# 4: right endpoint value of argument +# + +# special values +0 53 nan -inf +0 53 nan -8 +0 53 -8 nan +0 53 nan -0 +0 53 +0 nan +0 53 nan 5 +0 53 5 nan +0 53 nan +inf +0 53 nan nan +0 53 -inf -inf +0 53 -inf -8 +0 53 -inf -0 +0 53 -inf 5 +0 53 -inf +inf +0 53 -inf nan +0 53 -8 -0 +0 53 +0 -0 +0 53 +0 5 +0 53 +0 +inf ++ 53 5 +inf ++ 53 +inf +inf +0 53 +inf nan + +# regular values +0 8 -34 -17 +0 8 -8 -1 +0 8 -34 17 +0 53 -0x1921fb54442d18p-51 0x1921fb54442d19p-51 ++ 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 ++ 53 +8 +0x7fffffffffffbp+51 ++ 53 +0x1fffffffffffffp-53 2 diff --git a/tests/log.dat b/tests/log.dat new file mode 100644 index 0000000..c9e0897 --- /dev/null +++ b/tests/log.dat @@ -0,0 +1,42 @@ +# data file for mpfi_log +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan -inf 53 nan -0 +0 53 -inf nan 53 +0 nan +0 53 nan -0 53 nan +1 +0 53 +inf nan 53 +inf nan +0 53 nan nan 53 -inf -inf +0 53 nan nan 53 -inf -7 +0 53 nan -inf 53 -inf -0 +0 53 nan -0 53 -inf +1 +0 53 nan +inf 53 -inf +inf +0 53 nan -inf 53 -1 -0 +0 53 -inf -inf 53 +0 -0 +0 53 -inf -0 53 +0 +1 +0 53 -inf +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +0 53 +0 -0 + 53 +1 +1 +3 53 0xc6dc8a2928579p-47 0x1a9500bc7ffcc5p-48 + 53 0x3a2a08c23afe3p-14 0x1463ceb440d6bdp-14 +1 53 -0x2b9b8b1fb2fb9p-51 -0 + 53 0xb616ab8b683b5p-52 +1 +2 53 +0 0x5380455576989p-46 + 53 +1 0x8ac74d932fae3p-21 +3 53 0xbdee7228cfedfp-47 0x1b3913fc99f555p-48 + 53 0x4c322657ec89bp-16 0x4d68ba5f26bf1p-11 diff --git a/tests/log10.dat b/tests/log10.dat new file mode 100644 index 0000000..2609127 --- /dev/null +++ b/tests/log10.dat @@ -0,0 +1,42 @@ +# data file for mpfi_log10 +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan -inf 53 nan -0 +0 53 -inf nan 53 +0 nan +0 53 nan -0 53 nan 1 +0 53 +inf nan 53 +inf nan +0 53 nan nan 53 -inf -inf +0 53 nan nan 53 -inf -7 +0 53 nan -inf 53 -inf -0 +0 53 nan -0 53 -inf 1 +0 53 nan +inf 53 -inf +inf +0 53 nan -inf 53 -1 -0 +0 53 -inf -inf 53 +0 -0 +0 53 -inf -0 53 +0 1 +0 53 -inf +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +0 53 +0 -0 + 53 1 1 +3 53 0x159753104a9401p-49 0x1716c01a04b570p-49 + 53 0x3a2a08c23afe3p-14 0x1463ceb440d6bdp-14 +1 53 -0x12f043ec00f8d6p-55 -0 + 53 0xb616ab8b683b5p-52 1 +2 53 2 0x1221cc590b9946p-49 + 53 100 0x8ac74d932fae3p-21 +3 53 0x149f1d70168f49p-49 0x17a543a94fb65ep-49 + 53 0x4c322657ec89bp-16 0x4d68ba5f26bf1p-11 diff --git a/tests/log1p.dat b/tests/log1p.dat new file mode 100644 index 0000000..009d790 --- /dev/null +++ b/tests/log1p.dat @@ -0,0 +1,40 @@ +# data file for mpfi_log1p +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 -inf nan 53 -1 nan +0 53 nan -0 53 nan -0 +0 53 +0 nan 53 +0 nan +0 53 nan 0x162e42fefa39f0p-53 53 nan 1 +0 53 +inf nan 53 +inf nan +0 53 nan nan 53 -inf -inf +0 53 nan nan 53 -inf -7 +0 53 nan -inf 53 -inf -1 +0 53 nan -0 53 -inf -0 +0 53 nan 0x162e42fefa39f0p-53 53 -inf 1 +0 53 nan +inf 53 -inf +inf +0 53 -inf -0 53 -1 -0 +0 53 +0 -0 53 +0 -0 +2 53 +0 0x162e42fefa39f0p-53 53 +0 1 +0 53 +0 +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +1 53 -0x13e080325bab7bp-52 -0 + 53 -0xb616ab8b683b5p-52 -0 +2 53 +0 0x14e0115561569cp-48 + 53 +0 0x8ac74d932fae3p-21 +3 53 0x17bdce451a337fp-48 0x1b3913fc99f6fcp-48 + 53 0x4c322657ec89bp-16 0x4d68ba5f26bf1p-11 diff --git a/tests/log2.dat b/tests/log2.dat new file mode 100644 index 0000000..e8fdc8d --- /dev/null +++ b/tests/log2.dat @@ -0,0 +1,40 @@ +# data file for mpfi_log2 +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan -inf 53 nan -0 +0 53 -inf nan 53 +0 nan +0 53 nan -0 53 nan +1 +0 53 +inf nan 53 +inf nan +0 53 nan nan 53 -inf -inf +0 53 nan nan 53 -inf -7 +0 53 nan -inf 53 -inf -0 +0 53 nan -0 53 -inf +1 +0 53 nan +inf 53 -inf +inf +0 53 nan -inf 53 -1 -0 +0 53 -inf -inf 53 +0 -0 +0 53 -inf -0 53 +0 +1 +0 53 -inf +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +0 53 +0 -0 + 53 1 1 +1 53 -0x1f74cb5d105b3ap-54 -0 + 53 0xb616ab8b683b5p-52 1 +2 53 +0 0x1e1ddc27c2c70fp-48 + 53 1 0x8ac74d932fae3p-21 +3 53 0x112035c9390c07p-47 0x13a3208f61f10cp-47 + 53 0x4c322657ec89bp-16 0x4d68ba5f26bf1p-11 diff --git a/tests/mag.dat b/tests/mag.dat new file mode 100644 index 0000000..dac7b38 --- /dev/null +++ b/tests/mag.dat @@ -0,0 +1,40 @@ +# data file for mpfi_mag +# +# column fields: +# 1: error direction (0: result is exact, +: result is overestimated) +# 2: precision of result +# 3: value of result +# +# 5: precision of argument +# 6: left endpoint value of argument +# 7: right endpoint value of argument +# + +# special values +0 53 nan 53 nan -inf +0 53 nan 53 nan -8 +0 53 nan 53 -8 nan +0 53 nan 53 nan -0 +0 53 nan 53 +0 nan +0 53 nan 53 nan 5 +0 53 nan 53 +5 nan +0 53 nan 53 nan +inf +0 53 nan 53 nan nan +0 53 +inf 53 -inf -inf +0 53 +inf 53 -inf -8 +0 53 +inf 53 -inf -0 +0 53 +inf 53 -inf 5 +0 53 +inf 53 -inf +inf +0 53 nan 53 -inf nan +0 53 +inf 53 -inf -0 +0 53 +8 53 -8 -0 +0 53 +0 53 +0 -0 +0 53 +5 53 +0 5 +0 53 +inf 53 +0 +inf +0 53 nan 53 +0 nan +0 53 +inf 53 +inf +inf +0 53 nan 53 +inf nan + +# regular values +0 53 34 53 -34 -17 ++ 4 36 53 -34 -17 diff --git a/tests/mid.dat b/tests/mid.dat new file mode 100644 index 0000000..d34ff97 --- /dev/null +++ b/tests/mid.dat @@ -0,0 +1,57 @@ +# data file for mpfi_mid +# +# column fields: +# 1: error direction (0: result is exact, +: result is overestimated) +# 2: precision of result +# 3: value of result +# +# 5: precision of argument +# 6: left endpoint value of argument +# 7: right endpoint value of argument +# + +# special values +0 53 nan 53 nan -inf +0 53 nan 53 nan -8 +0 53 nan 53 -8 nan +0 53 nan 53 nan -0 +0 53 nan 53 +0 nan +0 53 nan 53 nan 5 +0 53 nan 53 5 nan +0 53 nan 53 nan +inf +0 53 nan 53 nan nan +0 53 -inf 53 -inf -inf +0 53 -inf 53 -inf -8 +0 53 -inf 53 -inf -0 +0 53 -inf 53 -inf 5 +0 53 nan 53 -inf +inf +0 53 nan 53 -inf nan +0 53 -4 53 -8 -0 +0 53 +0 53 +0 -0 +0 53 +2.5 53 +0 5 +0 53 +inf 53 +0 +inf +0 53 nan 53 +0 nan +0 53 +inf 53 5 +inf +0 53 +inf 53 +inf +inf +0 53 nan 53 +inf nan + +# regular values +0 53 -0x33p-1 + 53 -34 -17 + +- 4 -26 53 -34 -17 +0 53 -8.5 53 -34 17 ++ 4 -8 53 -34 17 +0 53 +0x123456789abcdp-3 + 53 +0 +0x123456789abcdp-2 +- 53 0x1921fb54442d18p-51 + 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 ++ 53 -0x1921fb54442d18p-51 + 53 -0x1921fb54442d19p-51 -0x1921fb54442d18p-51 ++ 53 -0x27fffffffffffbp-52 + 53 -4 -0x7fffffffffffdp-51 +- 53 -0x47fffffffffffbp-52 + 53 -8 -0x7fffffffffffbp-51 + +- 53 0.5 + 53 -0x1fffffffffffffp-53 2 diff --git a/tests/mig.dat b/tests/mig.dat new file mode 100644 index 0000000..1451207 --- /dev/null +++ b/tests/mig.dat @@ -0,0 +1,40 @@ +# data file for mpfi_mig +# +# column fields: +# 1: error direction (0: result is exact, -: result is underestimated) +# 2: precision of result +# 3: value of result +# +# 5: precision of argument +# 6: left endpoint value of argument +# 7: right endpoint value of argument +# + +# special values +0 53 nan 53 nan -inf +0 53 nan 53 nan -8 +0 53 nan 53 -8 nan +0 53 nan 53 nan -0 +0 53 nan 53 +0 nan +0 53 nan 53 nan 5 +0 53 nan 53 +5 nan +0 53 nan 53 nan +inf +0 53 nan 53 nan nan +0 53 +inf 53 -inf -inf +0 53 8 53 -inf -8 +0 53 +0 53 -inf -0 +0 53 +0 53 -inf 5 +0 53 +0 53 -inf +inf +0 53 nan 53 -inf nan +0 53 +0 53 -inf -0 +0 53 +0 53 -8 -0 +0 53 +0 53 +0 -0 +0 53 +0 53 +0 5 +0 53 +0 53 +0 +inf +0 53 nan 53 +0 nan +0 53 +inf 53 +inf +inf +0 53 nan 53 +inf nan + +# regular values +0 53 17 53 -34 -17 +- 4 16 53 -34 -17 diff --git a/tests/mpfi-tests.c b/tests/mpfi-tests.c new file mode 100644 index 0000000..b0b9b57 --- /dev/null +++ b/tests/mpfi-tests.c @@ -0,0 +1,69 @@ +/* mpfi_tests.c -- Test constant functions + and test non-constant functions with random values. + +Copyright (C) 2001, 2002, 2009, 2010, + Spaces project, Inria Lorraine + Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library, based on the MPFR Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the MPFR Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +mpfi_restrict_random (mpfi_function_ptr func, I_fun restriction) +{ + func->random_domain = restriction; +} + +void +mpfi_fun_clear (mpfi_function_ptr func) +{ + func->clear (func); +} + +void +check_random (mpfi_function_ptr function, + mpfr_prec_t prec_min, mpfr_prec_t prec_max, int nb_tests) +{ + mpfr_prec_t prec; + int i; + + if (!rands_initialized) + { + printf ("Put test_start at the beginning of your test function.\n"); + printf ("There is a bug in the test suite itself, " + "please report to the MPFI mailing list.\n"); + exit (1); + } + + if (function->random == NULL) { + printf ("Error: no random function for this type.\n"); + printf ("There is a bug in the test suite itself, " + "please report to the MPFI mailing list.\n"); + exit (1); + } + + for (prec = prec_min; prec <= prec_max; ++prec) { + function->set_prec (function, prec); + for (i = 0; i < nb_tests; ++i) { + function->random (function); + } + } +} diff --git a/tests/mpfi-tests.h b/tests/mpfi-tests.h new file mode 100644 index 0000000..ff7002b --- /dev/null +++ b/tests/mpfi-tests.h @@ -0,0 +1,310 @@ +/* mpfi-tests.h -- Include file for mpfi's tests. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#ifndef __MPFI_TESTS_H__ +#define __MPFI_TESTS_H__ + +#include + +#include "mpfi_io.h" +#include "mpfi-impl.h" + +#define STR(a) # a +#define QUOTE(a) STR(a) + + +/** GENERIC TESTS **/ + +/* When adding a new generic test, one must declare a mpfi_function_t + variable and initialize it with the MPFI_FUN_SET macro before calling one + of the check_* functions. */ + +typedef int (*I_fun) (mpfi_t); +typedef int (*II_fun) (mpfi_t, mpfi_srcptr); +typedef int (*IS_fun) (mpfi_t, long); +typedef int (*IU_fun) (mpfi_t, unsigned long); +typedef int (*JS_fun) (mpfi_t, intmax_t); +typedef int (*JU_fun) (mpfi_t, uintmax_t); +typedef int (*ID_fun) (mpfi_t, double); +typedef int (*IF_fun) (mpfi_t, float); +typedef int (*IL_fun) (mpfi_t, long double); +typedef int (*IZ_fun) (mpfi_t, mpz_srcptr); +typedef int (*IQ_fun) (mpfi_t, mpq_srcptr); +typedef int (*IR_fun) (mpfi_t, mpfr_srcptr); +typedef int (*III_fun) (mpfi_t, mpfi_srcptr, mpfi_srcptr); +typedef int (*IIII_fun)(mpfi_t, mpfi_t, mpfi_srcptr, mpfi_srcptr); +typedef int (*IIU_fun) (mpfi_t, mpfi_srcptr, unsigned long); +typedef int (*IIS_fun) (mpfi_t, mpfi_srcptr, long); +typedef int (*IID_fun) (mpfi_t, mpfi_srcptr, double); +typedef int (*IIZ_fun) (mpfi_t, mpfi_srcptr, mpz_srcptr); +typedef int (*IIQ_fun) (mpfi_t, mpfi_srcptr, mpq_srcptr); +typedef int (*IIR_fun) (mpfi_t, mpfi_srcptr, mpfr_srcptr); +typedef int (*IUI_fun) (mpfi_t, unsigned long, mpfi_srcptr); +typedef int (*ISI_fun) (mpfi_t, long, mpfi_srcptr); +typedef int (*IDI_fun) (mpfi_t, double, mpfi_srcptr); +typedef int (*IZI_fun) (mpfi_t, mpz_srcptr, mpfi_srcptr); +typedef int (*IQI_fun) (mpfi_t, mpq_srcptr, mpfi_srcptr); +typedef int (*IRI_fun) (mpfi_t, mpfr_srcptr, mpfi_srcptr); +typedef int (*RI_fun) (mpfr_t, mpfi_srcptr); + +typedef int (*R_fun) (mpfr_t, mpfr_rnd_t); +typedef int (*RR_fun) (mpfr_t, mpfr_srcptr, mpfr_rnd_t); +typedef int (*RRU_fun) (mpfr_t, mpfr_srcptr, unsigned long, mpfr_rnd_t); +typedef int (*RRS_fun) (mpfr_t, mpfr_srcptr, long, mpfr_rnd_t); +typedef int (*RRD_fun) (mpfr_t, mpfr_srcptr, double, mpfr_rnd_t); +typedef int (*RRZ_fun) (mpfr_t, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t); +typedef int (*RRQ_fun) (mpfr_t, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t); +typedef int (*RRR_fun) (mpfr_t, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t); +typedef int (*RUR_fun) (mpfr_t, unsigned long, mpfr_srcptr, mpfr_rnd_t); +typedef int (*RSR_fun) (mpfr_t, long, mpfr_srcptr, mpfr_rnd_t); +typedef int (*RDR_fun) (mpfr_t, double, mpfr_srcptr, mpfr_rnd_t); +typedef int (*RZR_fun) (mpfr_t, mpz_srcptr, mpfr_srcptr, mpfr_rnd_t); +typedef int (*RQR_fun) (mpfr_t, mpq_srcptr, mpfr_srcptr, mpfr_rnd_t); +typedef void *NULL_fun; + +typedef union +{ + I_fun I; /* output: mpfi_t, no input */ + II_fun II; /* output: mpfi_t, input: mpfi_t */ + IS_fun IS; /* output: mpfi_t, input: long */ + IU_fun IU; /* output: mpfi_t, input: unsigned long */ + JS_fun JS; /* output: mpfi_t, input: intmax_t */ + JU_fun JU; /* output: mpfi_t, input: uintmax_t */ + ID_fun ID; /* output: mpfi_t, input: double */ + IF_fun IF; /* output: mpfi_t, input: float */ + IL_fun IL; /* output: mpfi_t, input: long double */ + IZ_fun IZ; /* output: mpfi_t, input: mpz_t */ + IQ_fun IQ; /* output: mpfi_t, input: mpq_t */ + IR_fun IR; /* output: mpfi_t, input: mpfr_t */ + III_fun III; /* output: mpfi_t, inputs: mpfi_t, mpfi_t */ + IIII_fun IIII; /* output: mpfi_t, mpfi_t, inputs: mpfi_t, mpfi_t */ + IIU_fun IIU; /* output: mpfi_t, inputs: mpfi_t, unsigned long */ + IIS_fun IIS; /* output: mpfi_t, inputs: mpfi_t, signed long */ + IID_fun IID; /* output: mpfi_t, inputs: mpfi_t, double */ + IIZ_fun IIZ; /* output: mpfi_t, inputs: mpfi_t, mpz_t */ + IIQ_fun IIQ; /* output: mpfi_t, inputs: mpfi_t, mpq_t */ + IIR_fun IIR; /* output: mpfi_t, inputs: mpfi_t, mpfr_t */ + IUI_fun IUI; /* output: mpfi_t, inputs: unsigned long, mpfi_t */ + ISI_fun ISI; /* output: mpfi_t, inputs: signed long, mpfi_t */ + IDI_fun IDI; /* output: mpfi_t, inputs: double, mpfi_t */ + IZI_fun IZI; /* output: mpfi_t, inputs: mpz_t, mpfi_t */ + IQI_fun IQI; /* output: mpfi_t, inputs: mpq_t, mpfi_t */ + IRI_fun IRI; /* output: mpfi_t, inputs: mpfr_t, mpfi_t */ + RI_fun RI; /* output: mpfr_t, input: mpfi_t */ +} mpfi_fun_ptr; + +typedef union +{ + R_fun I; /* output: mpfr_t, no input */ + RR_fun II; /* output: mpfr_t, input: mpfr_t */ + RRR_fun III; /* output: mpfr_t, inputs: mpfr_t, mpfr_t */ + RRR_fun IIII; /* output: mpfr_t, inputs: mpfr_t, mpfr_t */ + NULL_fun IS; /* dummy, no corresponding mpfr function */ + NULL_fun IU; /* dummy, no corresponding mpfr function */ + NULL_fun JS; /* dummy, no corresponding mpfr function */ + NULL_fun JU; /* dummy, no corresponding mpfr function */ + NULL_fun ID; /* dummy, no corresponding mpfr function */ + NULL_fun IF; /* dummy, no corresponding mpfr function */ + NULL_fun IL; /* dummy, no corresponding mpfr function */ + NULL_fun IZ; /* dummy, no corresponding mpfr function */ + NULL_fun IQ; /* dummy, no corresponding mpfr function */ + NULL_fun IR; /* dummy, no corresponding mpfr function */ + RRU_fun IIU; /* output: mpfr_t, inputs: mpfr_t, unsigned long */ + RRS_fun IIS; /* output: mpfr_t, inputs: mpfr_t, signed long */ + RRD_fun IID; /* output: mpfr_t, inputs: mpfr_t, double */ + RRZ_fun IIZ; /* output: mpfr_t, inputs: mpfr_t, mpz_t */ + RRQ_fun IIQ; /* output: mpfr_t, inputs: mpfr_t, mpq_t */ + RRR_fun IIR; /* output: mpfr_t, inputs: mpfr_t, mpfr_t */ + RUR_fun IUI; /* output: mpfr_t, inputs: unsigned long, mpfr_t */ + RSR_fun ISI; /* output: mpfr_t, inputs: signed long, mpfr_t */ + RDR_fun IDI; /* output: mpfr_t, inputs: double, mpfr_t */ + RZR_fun IZI; /* output: mpfr_t, inputs: mpz_t, mpfr_t */ + RQR_fun IQI; /* output: mpfr_t, inputs: mpq_t, mpfr_t */ + RRR_fun IRI; /* output: mpfr_t, inputs: mpfr_t, mpfr_t */ + NULL_fun RI; /* dummy, no corresponding mpfr function */ +} mpfi_fun_mpfr_ptr; + +typedef enum + { + I, /* no input */ + II, /* one input: interval */ + IS, /* one input: long */ + IU, /* one input: unsigned long */ + JS, /* one input: intmax_t */ + JU, /* one input: uintmax_t */ + ID, /* one input: double */ + IF, /* one input: float */ + IL, /* one input: long double */ + IZ, /* one input: mpz_t */ + IQ, /* one input: mpq_t */ + IR, /* one input: mpfr_t */ + III, /* two inputs: intervals */ + IIII, /* two inputs: intervals */ + IIU, /* two inputs: interval, unsigned long */ + IIS, /* two inputs: interval, signed long */ + IID, /* two inputs: interval, double */ + IIZ, /* two inputs: interval, mpz_t */ + IIQ, /* two inputs: interval, mpq_t */ + IIR, /* two inputs: interval, mpfr_t */ + IUI, /* two inputs: unsigned long, interval */ + ISI, /* two inputs: signed long, interval */ + IDI, /* two inputs: double, interval */ + IZI, /* two inputs: mpz_t, interval */ + IQI, /* two inputs: mpq_t, interval */ + IRI, /* two inputs: mpfr_t, interval */ + RI, /* one input: interval */ + } mpfi_fun_type; + +typedef union { + int i; + unsigned long ui; + signed long si; + uintmax_t uj; + intmax_t sj; + double d; + float f; + long double ld; + mpz_t mpz; + mpq_t mpq; + mpfr_t mpfr; + mpfi_t mpfi; +} mpfi_fun_operand_t; + +struct mpfi_function_t; +typedef struct mpfi_function_t* mpfi_function_ptr; + +struct mpfi_function_t +{ + mpfi_fun_type type; + mpfi_fun_ptr func; + mpfi_fun_mpfr_ptr mpfr_func; /* associated MPFR function */ + mpfi_fun_operand_t* operands; + I_fun random_domain; + + void (*set_prec) (mpfi_function_ptr, mpfr_prec_t); + void (*read_line) (mpfi_function_ptr, FILE *); + void (*check_line) (mpfi_function_ptr); + void (*random) (mpfi_function_ptr); + void (*clear) (mpfi_function_ptr); +}; + + +/* helper macro to abstract (to mask) mpfi_function_t type */ + +#define MPFI_FUN_TYPE(_mpfi_function) (_mpfi_function).type +#define MPFI_FUN_GET(_mpfi_function, _type) (_mpfi_function).func._type +#define MPFI_FUN_MPFR_FUNCTION(_mpfi_function, _type) \ + (_mpfi_function).mpfr_func._type +#define MPFI_FUN_ARGS(_mpfi_function) \ + ((_mpfi_function).operands) +#define MPFI_FUN_ARG(_mpfi_function, _arg_no, _arg_type) \ + ((_mpfi_function).operands[(_arg_no)]._arg_type) + + +/* Helper functions */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* public functions. + when adding a generic test, use the following functions: */ +void test_start (void); +void test_end (void); +void check_data (mpfi_function_ptr, const char *); +void check_random (mpfi_function_ptr, mpfr_prec_t, mpfr_prec_t, int); + +void mpfi_fun_init_I (mpfi_function_ptr, I_fun, R_fun); +void mpfi_fun_init_II (mpfi_function_ptr, II_fun, RR_fun); +void mpfi_fun_init_IU (mpfi_function_ptr, IU_fun, NULL_fun); +void mpfi_fun_init_IS (mpfi_function_ptr, IS_fun, NULL_fun); +void mpfi_fun_init_JU (mpfi_function_ptr, JU_fun, NULL_fun); +void mpfi_fun_init_JS (mpfi_function_ptr, JS_fun, NULL_fun); +void mpfi_fun_init_ID (mpfi_function_ptr, ID_fun, NULL_fun); +void mpfi_fun_init_IF (mpfi_function_ptr, IF_fun, NULL_fun); +void mpfi_fun_init_IL (mpfi_function_ptr, IL_fun, NULL_fun); +void mpfi_fun_init_IZ (mpfi_function_ptr, IZ_fun, NULL_fun); +void mpfi_fun_init_IQ (mpfi_function_ptr, IQ_fun, NULL_fun); +void mpfi_fun_init_IR (mpfi_function_ptr, IR_fun, NULL_fun); +void mpfi_fun_init_III (mpfi_function_ptr, III_fun, RRR_fun); +void mpfi_fun_init_IIII (mpfi_function_ptr, IIII_fun, RRR_fun); +void mpfi_fun_init_IIU (mpfi_function_ptr, IIU_fun, RRU_fun); +void mpfi_fun_init_IIS (mpfi_function_ptr, IIS_fun, RRS_fun); +void mpfi_fun_init_IID (mpfi_function_ptr, IID_fun, RRD_fun); +void mpfi_fun_init_IIZ (mpfi_function_ptr, IIZ_fun, RRZ_fun); +void mpfi_fun_init_IIQ (mpfi_function_ptr, IIQ_fun, RRQ_fun); +void mpfi_fun_init_IIR (mpfi_function_ptr, IIR_fun, RRR_fun); +void mpfi_fun_init_IUI (mpfi_function_ptr, IUI_fun, RUR_fun); +void mpfi_fun_init_ISI (mpfi_function_ptr, ISI_fun, RSR_fun); +void mpfi_fun_init_IDI (mpfi_function_ptr, IDI_fun, RDR_fun); +void mpfi_fun_init_IZI (mpfi_function_ptr, IZI_fun, RZR_fun); +void mpfi_fun_init_IQI (mpfi_function_ptr, IQI_fun, RQR_fun); +void mpfi_fun_init_IRI (mpfi_function_ptr, IRI_fun, RRR_fun); +void mpfi_fun_init_RI (mpfi_function_ptr, RI_fun, NULL_fun); +void mpfi_fun_clear (mpfi_function_ptr); + +void mpfi_restrict_random (mpfi_function_ptr, I_fun); + +/* internal functions */ + +extern gmp_randstate_t rands; +extern char rands_initialized; +void random_interval (mpfi_ptr); +unsigned long random_ui (); +long random_si (); +double random_double (); +void random_mpz (mpz_ptr, unsigned long); +void random_mpq (mpq_ptr); +void random_mpfr (mpfr_ptr); + +int same_mpfr_value (mpfr_srcptr, mpfr_srcptr); +int same_value (mpfi_srcptr, mpfi_srcptr); + +FILE* open_file (const char *); +void init_reading (FILE*); +void close_file (FILE*); +void skip_whitespace_comments (FILE*); +void read_sign (FILE*, int*); +void read_exactness (FILE*, int*); +void read_ui (FILE*, unsigned long*); +void read_si (FILE*, long*); +void read_uj (FILE*, uintmax_t*); +void read_sj (FILE*, intmax_t*); +int read_double (FILE*, double*); +int read_float (FILE*, float*); +int read_long_double (FILE*, long double*); +void read_mpz (FILE*, mpz_ptr); +void read_mpq (FILE*, mpq_ptr); +void read_mpfr (FILE*, mpfr_ptr); +void read_mpfi (FILE*, mpfi_ptr); + +void check_with_different_prec (mpfi_function_ptr, mpfr_prec_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __MPFI_TESTS_H__ */ diff --git a/tests/mul.dat b/tests/mul.dat new file mode 100644 index 0000000..35d22da --- /dev/null +++ b/tests/mul.dat @@ -0,0 +1,123 @@ +# data file for mpfi_mul +# +# fields: see add.dat + +# special values +0 53 nan nan 53 nan nan 53 -inf -7 +0 53 nan nan 53 nan nan 53 -8 +1 +0 53 nan nan 53 nan nan 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 nan +0 53 nan nan 53 nan nan 53 +5 +inf +0 53 nan nan 53 nan nan 53 +inf +inf +0 53 nan nan 53 nan nan 53 nan -0 +0 53 nan nan 53 nan -0 53 -inf -7 +0 53 nan nan 53 nan -0 53 -8 +1 +0 53 nan nan 53 nan +inf 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 +7 +0 53 nan nan 53 nan -inf 53 +5 +inf +0 53 nan nan 53 nan -7 53 +inf +inf +0 53 nan nan 53 nan +1 53 nan -0 +0 53 +inf +inf 53 -inf -inf 53 -inf -inf +0 53 +0 -0 53 -inf -inf 53 +0 -0 +0 53 -inf +inf 53 -inf -7 53 -1 +8 +0 53 -inf -0 53 -inf -0 53 +8 +inf +0 53 -inf nan 53 -inf -0 53 +inf +inf +0 53 -inf +64 53 -inf +8 53 +0 +8 +0 53 +0 -0 53 -inf +inf 53 +0 -0 +0 53 -inf +inf 53 -inf +inf 53 +0 +8 +0 53 +0 -0 53 +0 -0 53 -inf -7 +0 53 -56 -0 53 +0 +8 53 -7 -0 +0 53 +0 -0 53 +0 -0 53 +0 +8 +0 53 +0 +inf 53 +0 +inf 53 +0 +8 +0 53 +0 -0 53 +0 -0 53 +8 +inf +0 53 nan nan 53 +0 +8 53 +inf nan +0 53 +0 -0 53 +0 -0 53 -inf +inf +0 53 -56 +64 53 +0 +8 53 -7 +8 +0 53 +0 -0 53 +0 -0 53 +0 -0 +0 53 +0 +inf 53 +0 +inf 53 +0 +8 +0 53 nan nan 53 +0 nan 53 +8 +inf +0 53 nan +inf 53 +0 +8 53 +inf +inf +0 53 +0 -0 53 +inf +inf 53 +0 -0 +0 53 -inf +inf 53 +inf +inf 53 -inf +3 +0 53 nan +inf 53 +inf +inf 53 +0 +inf +0 53 nan nan 53 +inf +inf 53 +3 nan +0 53 nan nan 53 +inf nan 53 -inf -7 +0 53 nan nan 53 +inf nan 53 +inf +inf +0 53 nan nan 53 +inf nan 53 -3 +7 +0 53 +0 -0 53 -3 +7 53 +0 -0 + +# regular values +0 53 0x12 0x34 + 53 -0x0d -0x09 53 -0x04 -0x02 +1 53 0x8.ef3aa21dba748p-8 0x34 + 53 -0x0d -0xd.f0e7927d247cp-4 53 -0x04 -0xa.41084aff48f8p-8 +2 53 0x12 0x1.f1651669609aap+2044 + 53 -0x2.ff65224ae58c6p+1020 -0x09 53 -0xa.5edd2648b5608p+1020 -0x02 +3 53 0x1.a142a930de328p-4 0x4.e86c3434cd924p-4 + 53 -0xe.26c9e9eb67b48p-4 -0x8.237d2eb8b1178p-4 53 -0x5.8c899a0706d5p-4 -0x3.344e57a37b5e8p-4 +0 53 -0x74e 0x37 + 53 -0x37 -0x07 53 -0x01 0x22 +1 53 -0x1.491df346a9f15p+0 0xe.063f267ed51ap-4 + 53 -0xe.063f267ed51ap-4 -0x0.33 53 -0x01 0x1.777ab178b4a1ep+0 +2 53 -0x1.cb540b71699a8p+4 0x2.804cce4a3f42ep+4 + 53 -0x1.cb540b71699a8p+4 -0x0.33 53 -0x1.64dcaaa101f18p+0 0x01 +3 53 -0x3.71b422ce817f4p+8 0x2.804cce4a3f42ep+4 + 53 -0x1.cb540b71699a8p+4 -0x0.33 53 -0x1.64dcaaa101f18p+0 0x1.eb67a1a6ef725p+4 +0 53 -0x123456789a0 -0x01 + 53 -0x123456789a -0x01 53 0x01 0x10 +1 53 -0x1.7611a672948a5p+0 -0x01 + 53 -0xb.6c67d3a37d54p-4 -0x.8 53 0x02 0x2.0bee4e8bb3dfp+0 +2 53 -0x10 -0x7.99b990532d434p-8 + 53 -0x04 -0xa.497d533c3b2ep-8 53 0xb.d248df3373e68p-4 0x04 +3 53 -0x1.7611a672948a5p+0 -0x7.99b990532d434p-8 + 53 -0xb.6c67d3a37d54p-4 -0xa.497d533c3b2ep-8 53 0xb.d248df3373e68p-4 0x2.0bee4e8bb3dfp+0 + +0 53 -0x77 0x07 + 53 -0x01 0x11 53 -0x07 -0x04 +1 53 -0x2.101b41d3d48b8p+0 0x2.3b46226145234p+0 + 53 -0x01 0xe.ca7ddfdb8572p-4 53 -0x2.3b46226145234p+0 -0x0.1 +2 53 -0x2.3b46226145234p+0 0x2.7c0bd9877f404p+8 + 53 -0x1.1d069e75e8741p+8 0x01 53 -0x2.3b46226145234p+0 -0x0.1 +3 53 -0x2.7c0bd9877f404p+8 0x2.101b41d3d48b8p+0 + 53 -0xe.ca7ddfdb8572p-4 0x1.1d069e75e8741p+8 53 -0x2.3b46226145234p+0 -0x0.1 +0 53 -0x20 0x30 + 53 -0x01 0x10 53 -0x02 0x03 +1 53 -0x6.ea77a3ee43de8p-8 0x2.6bff2625fb71cp-4 + 53 -0x01 0x2.db091cea593fap-4 53 -0x2.6bff2625fb71cp-4 0x1p-8 +2 53 -0x1.8e3fe93a4ea52p+0 0xa.b52fe22d72788p-4 + 53 -0x01 0x6.e211fefc216ap-4 53 -0x1p-4 0x1.8e3fe93a4ea52p+0 +3 53 -0x8.ec5de73125be8p-4 0x2.adfe651d3b19ap+0 + 53 -0x1.15e079e49a0ddp+0 0x1p-8 53 -0x2.77fc84629a602p+0 0x8.3885932f13fp-4 +0 53 -0xfc 0xfc + 53 -0x07 0x07 53 0x13 0x24 +1 53 -0x1.71dc5b5607781p+0 0x2.3381083e7d3b4p+4 + 53 -0xa.8071f870126cp-4 0x10 53 0x02 0x2.3381083e7d3b4p+0 +2 53 -0x1.442e2695ac81ap+0 0x1.fb5fbebd0cbc6p+0 + 53 -0x01 0x1.90aa487ecf153p+0 53 0x01p-53 0x1.442e2695ac81ap+0 +3 53 -0x5.c61fcad908df4p+0 0x5.17b7c49130824p+0 + 53 -0x1.c40db77f2f6fcp+0 0x1.8eb70bbd94478p+0 53 0x02 0x3.45118635235c6p+0 + +0 53 -0x12345 -0xabc + 53 0xc 0x2d 53 -0x679 -0xe5 +1 53 -0x2.83a3712099234p+50 -0xabc + 53 0xc 0x1.1833fdcab4c4ap+10 53 -0x2.4c0afc50522ccp+40 -0xe5 +2 53 -0x12345 -0x7.35b3c8400ade4p+4 + 53 0xb.38f1fb0ef4308p+0 0x2d 53 -0x679 -0xa.4771d7d0c604p+0 +3 53 -0x3.e3ce52d4a139cp+4 -0x2.637164cf2f346p-8 + 53 0xf.08367984ca1cp-4 0xa.bcf6c6cbe341p+0 53 -0x5.cbc445e9952c4p+0 -0x2.8ad05a7b988fep-8 +0 53 -0xabc 0xc + 53 0x01 0xc 53 -0xe5 0x01 +1 53 -0x1.47f2dbe4ef916p+0 0x1.ec24910ac6aecp+32 + 53 0x123p-52 0x1.ec24910ac6aecp+0 53 -0xa.a97267f56a9b8p-4 0x1p+32 +2 53 -0x7.2bea531ef4098p+0 0x4.c765967f9468p+0 + 53 0x03 0x7.2bea531ef4098p+0 53 -0x01 0xa.a97267f56a9b8p-4 +3 53 -0x1.47f2dbe4ef916p+0 0x4.c765967f9468p+0 + 53 0x0.3 0xa.a97267f56a9b8p-4 53 -0x1.ec24910ac6aecp+0 0x7.2bea531ef4098p+0 +0 53 0xf 0x4d + 53 0x3 0x7 53 0x5 0xb +1 53 0x7.dc58fb323ad78p+0 0x4d + 53 0x2.48380232f6c16p+0 0x7 53 0x3.71cb6c53e68eep+0 0xb +2 53 0xfp-25 0x7.dc58fb323ad7cp+0 + 53 0x3 0x3.71cb6c53e68eep+0 53 0x5p-25 0x2.48380232f6c16p+0 +3 53 0x2.587a32d02bc04p-4 0x5.fa216b7c20c6cp+0 + 53 0x3.10e8a605572p-4 0x2.48380232f6c16p+0 53 0xc.3d8e305214ecp-4 0x2.9e7db05203c88p+0 diff --git a/tests/mul_2si.dat b/tests/mul_2si.dat new file mode 100644 index 0000000..bf40318 --- /dev/null +++ b/tests/mul_2si.dat @@ -0,0 +1,71 @@ +# data file for mpfi_mul_2si +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan -inf 53 nan -inf -3 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3 +0 53 nan -1.75 53 nan -7 -2 +0 53 nan -7 53 nan -7 0 +0 53 nan -28 53 nan -7 2 +0 53 nan -0 53 nan -0 -15 +0 53 nan -0 53 nan -0 0 +0 53 nan -0 53 nan -0 15 +0 53 nan .125 53 nan 1 -3 +0 53 nan 1 53 nan 1 0 +0 53 nan 8 53 nan 1 3 +0 53 nan +inf 53 nan +inf -63 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63 +0 53 -inf -inf 53 -inf -inf -2 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2 +0 53 -inf -.125 53 -inf -1 -3 +0 53 -inf -1 53 -inf -1 0 +0 53 -inf -8 53 -inf -1 3 +0 53 -inf -0 53 -inf -0 -8 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8 +0 53 -inf 0.5 53 -inf 8 -4 +0 53 -inf 8 53 -inf 8 0 +0 53 -inf 128 53 -inf 8 4 +0 53 -inf +inf 53 -inf +inf -32 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32 +0 53 -inf nan 53 -inf nan -64 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan 64 +0 53 +0 -0 53 +0 -0 -1 +0 53 +0 -0 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1 +0 53 +0 0.5 53 +0 8 -4 +0 53 +0 8 53 +0 8 0 +0 53 +0 128 53 +0 8 4 +0 53 +0 +inf 53 +0 +inf -7 +0 53 +0 +inf 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7 +0 53 +inf +inf 53 +inf +inf -1 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 +inf nan 53 +inf nan -1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1 + +# regular values +0 53 -0x20p-32 -0x11p-32 + 53 -32 -17 -32 +0 53 0x11p+32 0x20p+32 + 53 17 32 32 diff --git a/tests/mul_2ui.dat b/tests/mul_2ui.dat new file mode 100644 index 0000000..3f67e62 --- /dev/null +++ b/tests/mul_2ui.dat @@ -0,0 +1,66 @@ +# data file for mpfi_mul_2ui +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3 +0 53 nan -7 53 nan -7 0 +0 53 nan -28 53 nan -7 2 +0 53 nan -0 53 nan -0 0 +0 53 nan -0 53 nan -0 15 +0 53 nan 1 53 nan 1 0 +0 53 nan 8 53 nan 1 3 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2 +0 53 -inf -1 53 -inf -1 0 +0 53 -inf -4 53 -inf -1 2 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8 +0 53 -inf 8 53 -inf 8 0 +0 53 -inf 128 53 -inf 8 4 +# semi-infinite result with rounding +2 16 -inf 0x10002000000000p-53 + 53 -inf 0x10000000000001p-53 0 +2 16 -inf 0x10002000000000p-49 + 53 -inf 0x10000000000001p-53 4 + +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan 64 +0 53 +0 -0 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1 +0 53 +0 8 53 +0 8 0 +0 53 +0 128 53 +0 8 4 +# result with endpoints 0 and a rounded number +2 16 +0 0x10002000000000p-53 + 53 +0 0x10000000000001p-53 0 +2 16 +0 0x10002000000000p-49 + 53 +0 0x10000000000001p-53 4 + +0 53 +0 +inf 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1 + +# regular values +0 53 -0x20p+32 -0x11p+32 + 53 -32 -17 32 +0 53 0x123456789abcdfp-28 0x123456789abcdfp+25 + 53 0x123456789abcdfp-53 0x123456789abcdf 25 diff --git a/tests/mul_d.dat b/tests/mul_d.dat new file mode 100644 index 0000000..e637767 --- /dev/null +++ b/tests/mul_d.dat @@ -0,0 +1,123 @@ +# data file for mpfi_add_d +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of second parameter +# 8: second parameter value + +#WARNING: +# double values are read by the test suite with rounding towards minus +# infinity to a machine-dependant precision (whereas the mpfi data are read +# at the given precision with rounding to the nearest). +# So as to ensure portability, use test values that are representable with a +# 53 bit-significand which corresponds to the minimum default precision for +# a double in the test suite. + +# special values +0 53 nan nan 53 nan nan -0x170ef54646d497p-109 +0 53 nan nan 53 nan nan 0.0 +0 53 nan nan 53 nan nan 0x170ef54646d497p-109 +0 53 nan nan 53 nan -inf -0x114b37f4b51f71p-107 +0 53 nan nan 53 nan -inf 0.0 +0 53 nan nan 53 nan -inf 0x114b37f4b51f71p-107 +0 53 nan nan 53 nan -7 -0xfc339ab0a6b53p-99 +0 53 nan nan 53 nan -7 0.0 +0 53 nan nan 53 nan -7 7.0 +0 53 nan nan 53 nan -0 -15.0 +0 53 nan nan 53 nan -0 0.0 +0 53 nan nan 53 nan -0 15.0 +0 53 nan nan 53 nan 1 -0xb2b3ece0a4ef9p-103 +0 53 nan nan 53 nan 1 0.0 +0 53 nan nan 53 nan 1 0xb2b3ece0a4ef9p-103 +0 53 nan nan 53 nan +inf -0x5acae5c4b6e51p-101 +0 53 nan nan 53 nan +inf 0.0 +0 53 nan nan 53 nan +inf 0x5acae5c4b6e51p-101 +0 53 +inf +inf 53 -inf -inf -0x170ef54646d497p-108 +0 53 +0 -0 53 -inf -inf 0.0 +0 53 -inf -inf 53 -inf -inf 0x170ef54646d497p-108 +0 53 +0xa1 +inf 53 -inf -7 -0x17 +0 53 +0 -0 53 -inf -7 0.0 +2 53 -inf -0xa168b4ebefd020p-107 53 -inf -7 0x170ef54646d497p-107 +0 53 +0 +inf 53 -inf -0 -0x170ef54646d497p-106 +0 53 +0 -0 53 -inf -0 0.0 +0 53 -inf -0 53 -inf -0 0x170ef54646d497p-106 +0 53 -0xb1a2bc2ec5000000 +inf 53 -inf 8 -0x16345785d8a00000 +0 53 +0 -0 53 -inf 8 0.0 +0 53 -inf 0xb1a2bc2ec5000000 53 -inf 8 0x16345785d8a00000 +0 53 -inf +inf 53 -inf +inf -0x170ef54646d497p-105 +0 53 +0 -0 53 -inf +inf 0.0e-17 +0 53 -inf +inf 53 -inf +inf +0x170ef54646d497p-105 +0 53 nan nan 53 -inf nan -0x170ef54646d497p-104 +0 53 nan nan 53 -inf nan 0.0e-17 +0 53 nan nan 53 -inf nan +0x170ef54646d497p-104 +0 53 +0 -0 53 +0 -0 -0x170ef54646d497p-109 +0 53 +0 -0 53 +0 -0 0.0 +0 53 +0 -0 53 +0 -0 0x170ef54646d497p-109 +1 53 -0x790e87b0f3dc18p-107 -0 53 +0 7 -0x114b37f4b51f71p-107 +0 53 +0 -0 53 +0 8 0.0 +2 53 +0 0x9ba4f79a5e1b00p-103 53 +0 9 0x114b37f4b51f71p-103 +0 53 -inf -0 53 +0 +inf -0x50b45a75f7e81p-104 +0 53 +0 -0 53 +0 +inf 0.0 +0 53 +0 +inf 53 +0 +inf 0x142d169d7dfa03p-106 +0 53 -inf -inf 53 +inf +inf -0x170ef54646d497p-109 +0 53 +0 -0 53 +inf +inf 0.0 +0 53 +inf +inf 53 +inf +inf 0x170ef54646d497p-109 +0 53 nan nan 53 +inf nan -0x170ef54646d497p-109 +0 53 nan nan 53 +inf nan 0.0 +0 53 nan nan 53 +inf nan 0x170ef54646d497p-109 + +# regular values +0 53 0xfffffffffffffp-123 0x22a2a28 + 53 -0x1717170 -0xaaaaaaaaaaaaap-123 -1.5 +0 53 -0x22a2a28p+401 0xfffffffffffff + 53 -0xaaaaaaaaaaaaa 0x1717170p+401 -1.5 +0 53 -0x1222222222221p+654 -0x22000000000022 + 53 0x10000000000010 0x888888888888p+654 -2.125 +0 53 -0x22a2a28 -0xfffffffffffffp-123 + 53 -0x1717170 -0xaaaaaaaaaaaaap-123 1.5 +0 53 -0xfffffffffffff 0x22a2a28p+401 + 53 -0xaaaaaaaaaaaaa 0x1717170p+401 1.5 +0 53 0x22000000000022 0x1222222222221p+654 + 53 0x10000000000010 0x888888888888p+654 2.125 +1 53 0x18000000000001 0x22a2a28p+36 + 53 -0x1717170p+36 -0x10000000000001 -1.5 +1 53 -0x18000000000002 0xfffffffffffff + 53 -0xaaaaaaaaaaaaa 0x10000000000001 -1.5 +1 53 -0x12222222222223p+1 -0x22000000000022 + 53 0x10000000000010 0x11111111111111 -2.125 +1 53 -0x18000000000002 -0xfffffffffffffp-123 + 53 -0x10000000000001 -0xaaaaaaaaaaaaap-123 1.5 +1 53 -0x10000000000001 0x22a2a28p+401 + 53 -0xaaaaaaaaaaaab 0x1717170p+401 1.5 +1 53 0x22000000000002 0x1222222222221p+654 + 53 0x10000000000001 0x888888888888p+654 2.125 +2 53 0xfffffffffffffp-123 0x1a2a2a2a2a2a2a + 53 -0x11717171717171 -0xaaaaaaaaaaaaap-123 -1.5 +2 53 -0x22a2a28p+401 0x18000000000002 + 53 -0x10000000000001 0x1717170p+401 -1.5 +2 53 -0x1222222222221p+654 -0x22000000000002 + 53 0x10000000000001 0x888888888888p+654 -2.125 +2 53 -0x22a2a28 -0x27fffffffffffep-123 + 53 -0x1717170 -0x1aaaaaaaaaaaaap-123 1.5 +2 53 -0xfffffffffffff 0x1a2a2a2a2a2a2a + 53 -0xaaaaaaaaaaaaa 0x11717171717171 1.5 +2 53 0x22000000000022 0x34222222222224 + 53 0x10000000000010 0x18888888888889 2.125 +3 53 0x18000000000001 0x1a2a2a2a2a2a2a + 53 -0x11717171717171 -0x10000000000001 -1.5 +3 53 -0x18000000000002 0x18000000000002 + 53 -0x10000000000001 0x10000000000001 -1.5 +3 53 -0x12222222222223p+1 -0x22000000000002 + 53 0x10000000000001 0x11111111111111 -2.125 +3 53 -0x18000000000002 -0x27fffffffffffep-123 + 53 -0x10000000000001 -0x1aaaaaaaaaaaaap-123 1.5 +3 53 -0x10000000000001 0x1a2a2a2a2a2a2a + 53 -0xaaaaaaaaaaaab 0x11717171717171 1.5 +3 53 0x22000000000002 0x34222222222224 + 53 0x10000000000001 0x18888888888889 2.125 diff --git a/tests/mul_fr.dat b/tests/mul_fr.dat new file mode 100644 index 0000000..0f02d8e --- /dev/null +++ b/tests/mul_fr.dat @@ -0,0 +1,90 @@ +# data file for mpfi_mul_fr +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan 53 -0x170ef54646d497p-109 +0 53 nan nan 53 nan nan 53 -0 +0 53 nan nan 53 nan nan 53 0x170ef54646d497p-109 +0 53 nan nan 53 nan -inf 53 -0x114b37f4b51f71p-107 +0 53 nan nan 53 nan -inf 53 +0 +0 53 nan nan 53 nan -inf 53 0x114b37f4b51f71p-107 +0 53 nan nan 53 nan -7 53 -0xfc339ab0a6b53p-99 +0 53 nan nan 53 nan -7 53 -0 +0 53 nan nan 53 nan -7 53 7.0 +0 53 nan nan 53 nan -0 53 -15.0 +0 53 nan nan 53 nan -0 53 +0 +0 53 nan nan 53 nan -0 53 15.0 +0 53 nan nan 53 nan +1 53 -0xb2b3ece0a4ef9p-103 +0 53 nan nan 53 nan +1 53 -0 +0 53 nan nan 53 nan +1 53 0xb2b3ece0a4ef9p-103 +0 53 nan nan 53 nan +inf 53 -0x5acae5c4b6e51p-101 +0 53 nan nan 53 nan +inf 53 +0 +0 53 nan nan 53 nan +inf 53 0x5acae5c4b6e51p-101 +0 53 +inf +inf 53 -inf -inf 53 -0x170ef54646d497p-108 +0 53 +0 -0 53 -inf -inf 53 +0 +0 53 -inf -inf 53 -inf -inf 53 0x170ef54646d497p-108 +1 53 0x142d169d7dfa04p-104 +inf 53 -inf -7 53 -0x170ef54646d497p-107 +0 53 +0 -0 53 -inf -7 53 -0 +2 53 -inf -0x142d169d7dfa04p-104 53 -inf -7 53 0x170ef54646d497p-107 +0 53 +0 +inf 53 -inf -0 53 -0x170ef54646d497p-106 +0 53 +0 -0 53 -inf -0 53 +0 +0 53 -inf -0 53 -inf -0 53 0x170ef54646d497p-106 +0 53 -0x16345785d8ap+23 +inf 53 -inf 8 53 -0x16345785d8a00000 +0 53 +0 -0 53 -inf 8 53 -0 +0 53 -inf 0x16345785d8ap+23 53 -inf 8 53 0x16345785d8a00000 +0 53 -inf +inf 53 -inf +inf 53 -0x170ef54646d497p-105 +0 53 +0 -0 53 -inf +inf 53 +0 +0 53 -inf +inf 53 -inf +inf 53 +0x170ef54646d497p-105 +0 53 nan nan 53 -inf nan 53 -0x170ef54646d497p-104 +0 53 nan nan 53 -inf nan 53 -0 +0 53 nan nan 53 -inf nan 53 +0x170ef54646d497p-104 +0 53 +0 0x114b37f4b51f71p-104 53 -8 -0 53 -0x114b37f4b51f71p-107 +0 53 +0 -0 53 -8 -0 53 -0 +0 53 -0x114b37f4b51f71p-104 -0 53 -8 -0 53 0x114b37f4b51f71p-107 +0 53 +0 -0 53 +0 -0 53 -0x170ef54646d497p-109 +0 53 +0 -0 53 +0 -0 53 +0 +0 53 +0 -0 53 +0 -0 53 0x170ef54646d497p-109 +1 53 -0x115c832ca9d491p-99 -0 53 +0 257 53 -0x114b37f4b51f71p-107 +0 53 +0 -0 53 +0 257 53 -0 +2 53 +0 0x115c832ca9d491p-99 53 +0 257 53 0x114b37f4b51f71p-107 +0 53 -inf -0 53 +0 +inf 53 -0x50b45a75f7e81p-104 +0 53 +0 -0 53 +0 +inf 53 +0 +0 53 +0 +inf 53 +0 +inf 53 0x142d169d7dfa03p-106 +2 53 -inf -0x115c832ca9d490p-99 53 257 +inf 53 -0x114b37f4b51f71p-107 +0 53 +0 -0 53 257 +inf 53 +0 +1 53 0x115c832ca9d490p-99 +inf 53 257 +inf 53 0x114b37f4b51f71p-107 +0 53 -inf -inf 53 +inf +inf 53 -0x170ef54646d497p-109 +0 53 +0 -0 53 +inf +inf 53 -0 +0 53 +inf +inf 53 +inf +inf 53 0x170ef54646d497p-109 +0 53 nan nan 53 +inf nan 53 -0x170ef54646d497p-109 +0 53 nan nan 53 +inf nan 53 +0 +0 53 nan nan 53 +inf nan 53 0x170ef54646d497p-109 + +# regular values +0 53 0x1fdb97530eca6cp-51 0x1fdb97530eca6cp-7 + 53 0x123456789abcdp-48 0x123456789abcdp-4 53 3.5 +1 53 0x1fdb97530eca86p-55 0x1fdb97530eca6cp-7 + 53 0x123456789abcdfp-56 0x123456789abcdp-4 53 3.5 +2 53 -0x123d70a3d6fd58p-52 0x123d70a3d70a3ep-44 + 53 -0x123456789abp-48 0x123456789abcdfp-52 53 256.5 +3 53 -0x10018000000000p-39 -0x10018000000001p-538 + 53 -0x1fffffffffffffp-52 -0x10000000000001p-550 53 4097.5 + +0 53 -0x1fdb97530eca6cp-7 -0x1fdb97530eca6cp-51 + 53 0x123456789abcdp-48 0x123456789abcdp-4 53 -3.5 +1 53 -0x123d70a3d70a3ep-44 0x123d70a3d6fd58p-52 + 53 -0x123456789abp-48 0x123456789abcdfp-52 53 -256.5 +2 53 -0x1fdb97530eca6cp-7 -0x1fdb97530eca86p-55 + 53 0x123456789abcdfp-56 0x123456789abcdp-4 53 -3.5 +3 53 0x10018000000001p-538 0x10018000000000p-39 + 53 -0x1fffffffffffffp-52 -0x10000000000001p-550 53 -4097.5 diff --git a/tests/mul_q.dat b/tests/mul_q.dat new file mode 100644 index 0000000..1b00786 --- /dev/null +++ b/tests/mul_q.dat @@ -0,0 +1,99 @@ +# data file for mpfi_mul_q +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1/1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1/1 +0 53 nan nan 53 nan -inf -3/1 +0 53 nan nan 53 nan -inf 0 +0 53 nan nan 53 nan -inf 3/1 +0 53 nan nan 53 nan -7 -7/1 +0 53 nan nan 53 nan -7 0 +0 53 nan nan 53 nan -7 7/1 +0 53 nan nan 53 nan -0 -15/1 +0 53 nan nan 53 nan -0 0 +0 53 nan nan 53 nan -0 15/1 +0 53 nan nan 53 nan 1 -31/1 +0 53 nan nan 53 nan 1 0 +0 53 nan nan 53 nan 1 31/1 +0 53 nan nan 53 nan +inf -63/1 +0 53 nan nan 53 nan +inf 0 +0 53 nan nan 53 nan +inf 63/1 +0 53 +inf +inf 53 -inf -inf -2/1 +0 53 +0 -0 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2/1 + +1 53 0x12492492492492p-53 +inf + 53 -inf -4 -1/7 +0 53 +0 -0 53 -inf -7 0 +2 53 -inf -0x12492492492492p-53 + 53 -inf -4 1/7 + +0 53 +0 +inf 53 -inf -0 -8/1 +0 53 +0 -0 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8/1 +0 53 -0.5 +inf 53 -inf 8 -1/16 +0 53 +0 -0 53 -inf 8 0 +0 53 -inf 0.5 53 -inf 8 1/16 +0 53 -inf +inf 53 -inf +inf -32/1 +0 53 +0 -0 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32/1 +0 53 nan nan 53 -inf nan -64/1 +0 53 nan nan 53 -inf nan 0 +0 53 nan nan 53 -inf nan 64/1 +0 53 +0 -0 53 +0 -0 -1/1 +0 53 +0 -0 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1/1 + +1 53 -0x15555555555556p-51 -0 + 53 +0 8 -1/3 +0 53 +0 -0 53 +0 8 0 +2 53 +0 0x15555555555556p-51 + 53 +0 8 1/3 + +0 53 -inf -0 53 +0 +inf -7/1 +0 53 +0 -0 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7/1 +0 53 -inf -inf 53 +inf +inf -1/1 +0 53 +0 -0 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1/1 +0 53 nan nan 53 +inf nan -1/1 +0 53 nan nan 53 +inf nan 0 +0 53 nan nan 53 +inf nan 1/1 + +# regular values +0 53 0x55p-5 5 + 53 -32 -17 -5/32 +0 53 -5 -0x55p-5 + 53 -32 -17 5/32 +1 53 -0x12d2d2d2d2d2d3p-49 -5 + 53 -32 -17 5/17 + +0 53 0x123456789abcdfp-45 0x123456789abcdfp+8 + 53 0x123456789abcdfp-53 0x123456789abcdf 256/1 +1 53 0x18000000000001p-52 9 + 53 0x10000000000001p-53 3 3/1 +2 53 -27 0x18000000000002p-52 + 53 -9 0x10000000000001p-53 3/1 +3 53 -0x15555555555556p-51 0x15555555555556p-51 + 53 -8 8 1/3 + +0 53 -0x123456789abcdfp+8 -0x123456789abcdfp-45 + 53 0x123456789abcdfp-53 0x123456789abcdf -256/1 +1 53 -0x18000000000002p-52 27 + 53 -9 0x10000000000001p-53 -3/1 +2 53 -9 -0x18000000000001p-52 + 53 0x10000000000001p-53 3 -3/1 +3 53 -0x15555555555556p-51 0x15555555555556p-51 + 53 -8 8 -1/3 diff --git a/tests/mul_si.dat b/tests/mul_si.dat new file mode 100644 index 0000000..c268831 --- /dev/null +++ b/tests/mul_si.dat @@ -0,0 +1,99 @@ +# data file for mpfi_mul_si +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan nan 53 nan -inf -3 +0 53 nan nan 53 nan -inf 0 +0 53 nan nan 53 nan -inf 3 +0 53 nan nan 53 nan -7 -7 +0 53 nan nan 53 nan -7 0 +0 53 nan nan 53 nan -7 7 +0 53 nan nan 53 nan -0 -15 +0 53 nan nan 53 nan -0 0 +0 53 nan nan 53 nan -0 15 +0 53 nan nan 53 nan 1 -31 +0 53 nan nan 53 nan 1 0 +0 53 nan nan 53 nan 1 31 +0 53 nan nan 53 nan +inf -63 +0 53 nan nan 53 nan +inf 0 +0 53 nan nan 53 nan +inf 63 +0 53 +inf +inf 53 -inf -inf -2 +0 53 +0 -0 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf +2 + +1 53 -0x14000000000002p+2 +inf + 53 -inf 0x10000000000001 -5 +0 53 +0 -0 53 -inf -1 0 +2 53 -inf 0xa000000000001p+3 + 53 -inf 0x10000000000001 5 + +0 53 +0 +inf 53 -inf -0 -8 +0 53 +0 -0 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8 +0 53 -128 +inf 53 -inf 8 -16 +0 53 +0 -0 53 -inf 8 0 +0 53 -inf 128 53 -inf 8 16 +0 53 -inf +inf 53 -inf +inf -32 +0 53 +0 -0 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf +32 +0 53 nan nan 53 -inf nan -64 +0 53 nan nan 53 -inf nan 0 +0 53 nan nan 53 -inf nan +64 +0 53 +0 -0 53 +0 -0 -1 +0 53 +0 -0 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1 + +1 53 -0x18000000000002p+1 -0 + 53 +0 0x10000000000001 -3 +0 53 +0 -0 53 +0 8 0 +2 53 +0 0x18000000000002p+1 + 53 +0 0x10000000000001 3 + +0 53 -inf -0 53 +0 +inf -7 +0 53 +0 -0 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7 + +2 53 -inf -0x1c000000000001p+2 + 53 +0x10000000000001 +inf -7 +0 53 +0 -0 53 +0 +inf 0 +1 53 +0x1c000000000001p+2 +inf + 53 +0x10000000000001 +inf 7 + +0 53 -inf -inf 53 +inf +inf -1 +0 53 +0 -0 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 nan nan 53 +inf nan -1 +0 53 nan nan 53 +inf nan 0 +0 53 nan nan 53 +inf nan 1 + +# regular values +0 53 0x123456789abcdfp-45 0x123456789abcdfp+8 + 53 0x123456789abcdfp-53 0x123456789abcdf 256 +1 53 0x18000000000001p-52 9 + 53 0x10000000000001p-53 3 3 +2 53 -27 0x18000000000002p-52 + 53 -9 0x10000000000001p-53 3 +3 53 -0xa000000000001p-50 0xa000000000001p-50 + 53 -0x10000000000001p-53 0x10000000000001p-53 5 + +0 53 -0x123456789abcdfp+8 -0x123456789abcdfp-45 + 53 0x123456789abcdfp-53 0x123456789abcdf -256 +1 53 -0x18000000000002p-52 27 + 53 -9 0x10000000000001p-53 -3 +2 53 -9 -0x18000000000001p-52 + 53 0x10000000000001p-53 3 -3 +3 53 -0x16c16c16c16c17p+2 0x16c16c16c16c17p+2 + 53 -0x123456789abcdf 0x123456789abcdf -5 diff --git a/tests/mul_ui.dat b/tests/mul_ui.dat new file mode 100644 index 0000000..7d86fa4 --- /dev/null +++ b/tests/mul_ui.dat @@ -0,0 +1,63 @@ +# data file for mpfi_mul_ui +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan nan 53 nan -inf 0 +0 53 nan nan 53 nan -inf 3 +0 53 nan nan 53 nan -7 0 +0 53 nan nan 53 nan -7 7 +0 53 nan nan 53 nan -0 0 +0 53 nan nan 53 nan -0 15 +0 53 nan nan 53 nan 1 0 +0 53 nan nan 53 nan 1 31 +0 53 nan nan 53 nan +inf 0 +0 53 nan nan 53 nan +inf 63 +0 53 +0 -0 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2 +0 53 +0 -0 53 -inf -1 0 +2 53 -inf 0xa000000000001p+3 + 53 -inf 0x10000000000001 5 +0 53 +0 -0 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8 +0 53 +0 -0 53 -inf 8 0 +0 53 -inf 128 53 -inf 8 16 +0 53 +0 -0 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf +32 +0 53 nan nan 53 -inf nan 0 +0 53 nan nan 53 -inf nan +64 +0 53 +0 -0 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1 +0 53 +0 -0 53 +0 8 0 +2 53 +0 0x18000000000002p+1 + 53 +0 0x10000000000001 3 +0 53 +0 -0 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7 +0 53 +0 -0 53 +0 +inf 0 +1 53 +0x1c000000000001p+2 +inf + 53 +0x10000000000001 +inf 7 +0 53 +0 -0 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 nan nan 53 +inf nan 0 +0 53 nan nan 53 +inf nan 1 + +# regular values +0 53 0x123456789abcdfp-45 0x123456789abcdfp+8 + 53 0x123456789abcdfp-53 0x123456789abcdf 256 +1 53 0x18000000000001p-52 9 + 53 0x10000000000001p-53 3 3 +2 53 -27 0x18000000000002p-52 + 53 -9 0x10000000000001p-53 3 +3 53 -0xa000000000001p-50 0xa000000000001p-50 + 53 -0x10000000000001p-53 0x10000000000001p-53 5 diff --git a/tests/mul_z.dat b/tests/mul_z.dat new file mode 100644 index 0000000..1477067 --- /dev/null +++ b/tests/mul_z.dat @@ -0,0 +1,99 @@ +# data file for mpfi_mul_z +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan nan 53 nan -inf -3 +0 53 nan nan 53 nan -inf 0 +0 53 nan nan 53 nan -inf 3 +0 53 nan nan 53 nan -7 -7 +0 53 nan nan 53 nan -7 0 +0 53 nan nan 53 nan -7 7 +0 53 nan nan 53 nan -0 -15 +0 53 nan nan 53 nan -0 0 +0 53 nan nan 53 nan -0 15 +0 53 nan nan 53 nan 1 -31 +0 53 nan nan 53 nan 1 0 +0 53 nan nan 53 nan 1 31 +0 53 nan nan 53 nan +inf -63 +0 53 nan nan 53 nan +inf 0 +0 53 nan nan 53 nan +inf 63 +0 53 +inf +inf 53 -inf -inf -2 +0 53 +0 -0 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2 + +1 53 -0x14000000000002p+2 +inf + 53 -inf 0x10000000000001 -5 +0 53 +0 -0 53 -inf -1 0 +2 53 -inf 0xa000000000001p+3 + 53 -inf 0x10000000000001 5 + +0 53 +0 +inf 53 -inf -0 -8 +0 53 +0 -0 53 -inf -0 0 +0 53 -inf -0 53 -inf -0 8 +0 53 -128 +inf 53 -inf +8 -16 +0 53 +0 -0 53 -inf +8 0 +0 53 -inf 128 53 -inf +8 16 +0 53 -inf +inf 53 -inf +inf -32 +0 53 +0 -0 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32 +0 53 nan nan 53 -inf nan -64 +0 53 nan nan 53 -inf nan 0 +0 53 nan nan 53 -inf nan 64 +0 53 +0 -0 53 +0 -0 -1 +0 53 +0 -0 53 +0 -0 0 +0 53 +0 -0 53 +0 -0 1 + +1 53 -0x18000000000002p+1 -0 + 53 +0 0x10000000000001 -3 +0 53 +0 -0 53 +0 8 0 +2 53 +0 0x18000000000002p+1 + 53 +0 0x10000000000001 3 + +0 53 -inf -0 53 +0 +inf -7 +0 53 +0 -0 53 +0 +inf 0 +0 53 +0 +inf 53 +0 +inf 7 + +2 53 -inf -0x1c000000000001p+2 + 53 +0x10000000000001 +inf -7 +0 53 +0 -0 53 +0 +inf 0 +1 53 +0x1c000000000001p+2 +inf + 53 +0x10000000000001 +inf 7 + +0 53 -inf -inf 53 +inf +inf -1 +0 53 +0 -0 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 nan nan 53 +inf nan -1 +0 53 nan nan 53 +inf nan 0 +0 53 nan nan 53 +inf nan 1 + +# regular values +0 53 0x123456789abcdfp-45 0x123456789abcdfp+8 + 53 0x123456789abcdfp-53 0x123456789abcdf 256 +1 53 0x18000000000001p-52 9 + 53 0x10000000000001p-53 3 3 +2 53 -27 0x18000000000002p-52 + 53 -9 0x10000000000001p-53 3 +3 53 -0xa000000000001p-50 0xa000000000001p-50 + 53 -0x10000000000001p-53 0x10000000000001p-53 5 + +0 53 -0x123456789abcdfp+8 -0x123456789abcdfp-45 + 53 0x123456789abcdfp-53 0x123456789abcdf -256 +1 53 -0x18000000000002p-52 27 + 53 -9 0x10000000000001p-53 -3 +2 53 -9 -0x18000000000001p-52 + 53 0x10000000000001p-53 3 -3 +3 53 -0x16c16c16c16c17p+2 0x16c16c16c16c17p+2 + 53 -0x123456789abcdf 0x123456789abcdf -5 diff --git a/tests/nan_p.dat b/tests/nan_p.dat new file mode 100644 index 0000000..aa12a8c --- /dev/null +++ b/tests/nan_p.dat @@ -0,0 +1,41 @@ +# data file for mpfi_nan_p +# +# column fields: +# 1: return value (0: false, +: true) +# 2: precision of argument +# 3: left endpoint value of argument +# 4: right endpoint value of argument +# + +# special values ++ 53 nan -inf ++ 53 nan -8 ++ 53 -8 nan ++ 53 nan -0 ++ 53 +0 nan ++ 53 nan 5 ++ 53 5 nan ++ 53 nan +inf ++ 53 nan nan +0 53 -inf -inf +0 53 -inf -8 +0 53 -inf -0 +0 53 -inf 5 +0 53 -inf +inf ++ 53 -inf nan +0 53 -8 -0 +0 53 +0 -0 +0 53 +0 5 +0 53 +0 +inf +0 53 5 +inf +0 53 +inf +inf ++ 53 +inf nan + +# regular values +0 8 -34 -17 +0 8 -8 -1 +0 8 -34 17 +0 53 -0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 53 0x1921fb54442d18p-51 0x1921fb54442d19p-51 +0 53 +8 +0x7fffffffffffbp+51 +0 53 +0x1fffffffffffffp-53 2 diff --git a/tests/neg.dat b/tests/neg.dat new file mode 100644 index 0000000..15dcc33 --- /dev/null +++ b/tests/neg.dat @@ -0,0 +1,36 @@ +# data file for mpfi_neg +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 +inf nan 53 nan -inf +0 53 nan +7 53 -7 nan +0 53 +0 nan 53 nan -0 +0 53 nan -0 53 +0 nan +0 53 -1 nan 53 nan +1 +0 53 nan -inf 53 +inf nan +0 53 +inf +inf 53 -inf -inf +0 53 +7 +inf 53 -inf -7 +0 53 +0 +inf 53 -inf -0 +0 53 -8 +inf 53 -inf +8 +0 53 -inf +inf 53 -inf +inf +0 53 +0 -0 53 +0 -0 +0 53 +0 -0 53 +0 -0 +0 53 -8 -0 53 +0 +8 +0 53 -inf -0 53 +0 +inf +0 53 -inf -inf 53 +inf +inf + +# regular values +0 53 -0x123456799p-16 -0x123456789p-16 53 0x123456789p-16 0x123456799p-16 +1 12 -0x889p+21 0xaaap-26 53 -0xaaap-26 0x111111111 +2 12 0xaaa 0xaabp+4 53 -0xaaa1 -0xaaa +3 12 0xaaap+4 0xb6d0 53 -0xb6c1 -0xaaa1 diff --git a/tests/put_d.dat b/tests/put_d.dat new file mode 100644 index 0000000..91d5e8b --- /dev/null +++ b/tests/put_d.dat @@ -0,0 +1,67 @@ +# data file for mpfi_put_d +# +# fields: see put_z.dat + +# special values +53 nan nan 0 53 nan nan -inf +53 nan nan 0 53 nan nan -8 +53 nan nan 0 53 nan nan -0 +53 nan nan 0 53 nan nan +0 +53 nan nan 0 53 nan nan +5 +53 nan nan 0 53 nan nan +inf +53 nan nan 0 53 nan nan nan +53 -inf -inf 0 53 -inf -inf -inf +53 -inf -inf 0 53 -inf -8 -8 +53 -inf -inf 0 53 -inf -0 -0 +53 -inf -inf 0 53 -inf -0 +0 +53 -inf -inf 0 53 -inf +5 +5 +53 -inf -inf 0 53 -inf +inf +inf +53 -inf -inf 0 53 nan -inf nan +53 +0 -0 0 53 -inf -0 -inf +53 +0 -0 0 53 -8 -0 -8 +53 +0 -0 0 53 +0 -0 -0 +53 +0 -0 0 53 +0 -0 +0 +53 +0 -0 0 53 +0 +5 +5 +53 +0 -0 0 53 +0 +inf +inf +53 +0 -0 0 53 nan -0 nan +53 +inf +inf 0 53 -inf +inf -inf +53 +inf +inf 0 53 -8 +inf -8 +53 +inf +inf 0 53 +0 +inf -0 +53 +inf +inf 0 53 +0 +inf +0 +53 +inf +inf 0 53 +5 +inf +5 +53 +inf +inf 0 53 +inf +inf +inf +53 +inf +inf 0 53 nan +inf nan + +# regular values + 49 +0x123456789abcdp-17 +0x1fedcba987654p-16 +0 49 +0x1111111111111p-17 +0x1fedcba987654p-16 +0x11111111111110p-21 + 49 +0x123456789abcdp-17 +0x1fedcba987654p-16 +1 49 +0x1111111111111p-17 +0x1fedcba987654p-16 +0x11111111111111p-21 + 49 +0x123456789abcdp-17 +0x1fedcba987654p-16 +0 49 +0x123456789abcdp-17 +0x1fedcba987654p-16 +0x1aaaaaaaaaaaaap-20 + 49 +0x123456789abcdp-17 +0x1fedcba987654p-16 +0 49 +0x123456789abcdp-17 +0x1ffffffffffffp-16 +0x1ffffffffffff0p-20 + 49 +0x123456789abcdp-17 +0x1fedcba987654p-16 +2 49 +0x123456789abcdp-17 +0x1ffffffffffffp-16 +0x1fffffffffffe2p-20 + + 49 -0x1fedcba987654 -0x123456789bcde +0 49 -0x1ffffffffffff -0x123456789bcde -0x1ffffffffffff + 49 -0x1fedcba987654 -0x123546789bcde +1 49 -0x20000000000000 -0x123546789bcde -0x1fffffffffffff + 49 -0x1fedcba987654 -1 +0 49 -0x1fedcba987654 -1 -0x1aaaaaaaaaaaa + 49 -0x123456789abcd -0x1111111111111 +0 49 -0x123456789abcd -1 -1 + 49 -0x123456789abcd -0x1fedcba987654p-19 +2 49 -0x123456789abcd -0x1ffffffffffffp-49 -0x1ffffffffffff2p-53 + + 49 -0x1 +0x1 +0 49 -0x2 +0x1 -0x2 + 49 -0x1 +0x1 +1 49 -0x2 +0x1 -0x1ffffffffffffep-52 + 49 -0x1 +0x1 +0 49 -0x1 +0x1 -0x1ffffffffffffep-53 + 49 -0x1 +0x1 +0 49 -0x1 +0x2 +0x2 + 49 -0x1 +0x1 +2 49 -0x1 +0x2 +0x1ffffffffffffep-52 diff --git a/tests/put_fr.dat b/tests/put_fr.dat new file mode 100644 index 0000000..de761be --- /dev/null +++ b/tests/put_fr.dat @@ -0,0 +1,77 @@ +# data file for mpfi_put_fr +# +# fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: precision of argument +# 9: value of argument + +# special values +53 nan nan 0 53 nan nan 53 -inf +53 nan nan 0 53 nan nan 53 -8 +53 nan nan 0 53 nan nan 53 -0 +53 nan nan 0 53 nan nan 53 +0 +53 nan nan 0 53 nan nan 53 +5 +53 nan nan 0 53 nan nan 53 +inf +53 nan nan 0 53 nan nan 53 nan +53 -inf -inf 0 53 -inf -inf 53 -inf +53 -inf -inf 0 53 -inf -8 53 -8 +53 -inf -inf 0 53 -inf -0 53 -0 +53 -inf -inf 0 53 -inf -0 53 +0 +53 -inf -inf 0 53 -inf +5 53 +5 +53 -inf -inf 0 53 -inf +inf 53 +inf +53 -inf -inf 0 53 nan nan 53 nan +53 +0 -0 0 53 -inf -0 53 -inf +53 +0 -0 0 53 -8 -0 53 -8 +53 +0 -0 0 53 +0 -0 53 -0 +53 +0 -0 0 53 +0 -0 53 +0 +53 +0 -0 0 53 +0 +5 53 +5 +53 +0 -0 0 53 +0 +inf 53 +inf +53 +0 -0 0 53 nan nan 53 nan +53 +inf +inf 0 53 -inf +inf 53 -inf +53 +inf +inf 0 53 -8 +inf 53 -8 +53 +inf +inf 0 53 +0 +inf 53 -0 +53 +inf +inf 0 53 +0 +inf 53 +0 +53 +inf +inf 0 53 +5 +inf 53 +5 +53 +inf +inf 0 53 +inf +inf 53 +inf +53 +inf +inf 0 53 nan nan 53 nan + +# regular values + 53 +0x123456789abcdep+17 +0x1fedcba9876543p+19 +0 53 +0x11111111111111p+17 +0x1fedcba9876543p+19 53 +0x11111111111111p+17 + 53 +0x123456789abcdep+17 +0x1fedcba9876543p+19 +1 53 +0x11111111111111p+17 +0x1fedcba9876543p+19 64 +0x11111111111111002p+5 + 53 +0x123456789abcdep+17 +0x1fedcba9876543p+19 +0 53 +0x123456789abcdep+17 +0x1fedcba9876543p+19 53 +0x1aaaaaaaaaaaaap+17 + 53 +0x123456789abcdep+17 +0x1fedcba9876543p+19 +0 53 +0x123456789abcdep+17 +0x1fffffffffffffp+19 53 +0x1fffffffffffffp+19 + 53 +0x123456789abcdep+17 +0x1fedcba9876543p+19 +2 53 +0x123456789abcdep+17 +0x1fffffffffffffp+19 64 +0x1ffffffffffffe002p+7 + 53 -0x1fedcba9876543 -0x123456789abcde +0 53 -0x1fffffffffffff -0x123456789abcde 53 -0x1fffffffffffff + 53 -0x1fedcba9876543 -0x123546789abcde +1 53 -0x1p+65 -0x123546789abcde 64 -0x1fffffffffffff002 + 53 -0x1fedcba9876543 -1 +0 53 -0x1fedcba9876543 -1 53 -0xaaaaaaaaaaaaa + 53 -0x123456789abcde -0x11111111111111 +0 53 -0x123456789abcde -1 53 -1 + 53 -0x123456789abcde -0x1fedcba9876543p-19 +2 53 -0x123456789abcde -0x1fffffffffffffp-53 64 -0xffffffffffffffffp-64 + + 53 -0x1 +0x1 +0 53 -0x2 +0x1 53 -0x2 + 53 -0x1 +0x1 +1 53 -0x2 +0x1 64 -0x1fffffffffffffffep-64 + 53 -0x1 +0x1 +0 53 -0x1 +0x1 64 -0x1fffffffffffffffep-65 + 53 -0x1 +0x1 +0 53 -0x1 +0x2 53 +0x2 + 53 -0x1 +0x1 +2 53 -0x1 +0x2 64 +0x1fffffffffffffffep-64 diff --git a/tests/put_q.dat b/tests/put_q.dat new file mode 100644 index 0000000..3cf792a --- /dev/null +++ b/tests/put_q.dat @@ -0,0 +1,66 @@ +# data file for mpfi_put_q +# +# fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: precision of argument +# 9: value of argument + +# special values +53 nan nan 0 53 nan nan -8/2 +53 nan nan 0 53 nan nan -0/2 +53 nan nan 0 53 nan nan 0/2 +53 nan nan 0 53 nan nan 5/2 +53 -inf -inf 0 53 -inf -8 -8/1 +53 -inf -inf 0 53 -inf -0 -0/1 +53 -inf -inf 0 53 -inf -0 0/1 +53 -inf -inf 0 53 -inf +5 5/1 +53 +0 -0 0 53 -8 -0 -8/1 +53 +0 -0 0 53 +0 -0 -0/1 +53 +0 -0 0 53 +0 -0 0/1 +53 +0 -0 0 53 +0 +5 5/1 +53 +inf +inf 0 53 -8 +inf -8/1 +53 +inf +inf 0 53 +0 +inf -0/1 +53 +inf +inf 0 53 +0 +inf 0/1 +53 +inf +inf 0 53 +5 +inf 5/1 + +# regular values + 53 +1 +2 +0 53 +0.5 +2 1/2 + 53 +1 +2 +1 53 +0x15555555555555p-54 +2 1/3 + 53 +1 +2 +0 53 +1 +2 3/2 + 53 +1 +2 +0 53 +1 +2.5 5/2 + 53 +1 +2 +2 53 +1 +0x12aaaaaaaaaaabp-51 7/3 + + 53 -2 -1 +0 53 -4 -1 -8/2 + 53 -2 -1 +1 53 -0x15555555555556p-51 -1 -8/3 + 53 -4 -1 +0 53 -4 -1 -6/2 + 53 -4 -3 +0 53 -4 -2 -2/1 + 53 -4 -2 +2 53 -4 -0x15555555555555p-54 -1/3 + + 53 -0x1 +0x1 +0 53 -0x2 +0x1 -2/1 + 53 -0x1 +0x1 +1 53 -0x15555555555556p-52 +0x1 -4/3 + 53 -0x1 +0x1 +0 53 -0x1 +0x1 -1/2 + 53 -0x1 +0x1 +0 53 -0x1 +2.5 5/2 + 53 -0x1 +0x1 +2 53 -0x1 +0x1aaaaaaaaaaaabp-52 5/3 diff --git a/tests/put_si.dat b/tests/put_si.dat new file mode 100644 index 0000000..359556a --- /dev/null +++ b/tests/put_si.dat @@ -0,0 +1,51 @@ +# data file for mpfi_put_ui +# +# fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: precision of argument +# 9: value of argument + +# special values +53 nan nan 0 53 nan nan -8 +53 nan nan 0 53 nan nan -0 +53 nan nan 0 53 nan nan 0 +53 nan nan 0 53 nan nan 5 +53 -inf -inf 0 53 -inf -8 -8 +53 -inf -inf 0 53 -inf -0 -0 +53 -inf -inf 0 53 -inf -0 0 +53 -inf -inf 0 53 -inf +5 5 +53 +0 -0 0 53 -8 -0 -8 +53 +0 -0 0 53 +0 -0 -0 +53 +0 -0 0 53 +0 -0 0 +53 +0 -0 0 53 +0 +5 5 +53 +inf +inf 0 53 -8 +inf -8 +53 +inf +inf 0 53 +0 +inf -0 +53 +inf +inf 0 53 +0 +inf 0 +53 +inf +inf 0 53 +5 +inf 5 + +# regular values +53 +10 +20 0 53 +5 +20 5 +16 +0x123400 0xdada00 1 16 +0x111100 0xdada00 0x111101 +53 +10 +20 0 53 +10 +20 15 +16 +0x123400 0xdada00 0 16 +0x123400 0xdddd00 0xdddd00 +16 +0x123400 0xdada00 2 16 +0x123400 0xdadb00 0xdadada + +53 -0x888888 -0x888887 0 53 -0xbaffe0 -0x888887 -0xbaffe0 +16 -0x888800 -0x888700 1 16 -0x888900 -0x888700 -0x888801 +53 -0x888800 -0x888700 0 53 -0x888800 -0x888700 -0x888701 +16 -0x888800 -0x888700 0 16 -0x888800 -0x100000 -0x100000 +16 -0x888800 -0x888700 2 16 -0x888800 -0x100000 -0x100001 + +16 -0x888800 +0x1 0 16 -0xfedc00 +0x1 -0xfedc00 +16 -0x888800 +0x1 1 16 -0xfedc00 +0x1 -0xfedb01 +16 -0x888800 +0x1 0 16 -0x888800 +0x1 -1 +16 -0x888800 +0x1 0 16 -0x888800 +0x888800 0x888800 +16 -0x888800 +0x1 2 16 -0x888800 +0x888900 0x888801 diff --git a/tests/put_ui.dat b/tests/put_ui.dat new file mode 100644 index 0000000..5f7a27f --- /dev/null +++ b/tests/put_ui.dat @@ -0,0 +1,44 @@ +# data file for mpfi_put_ui +# +# fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: precision of argument +# 9: value of argument + +# special values +53 nan nan 0 53 nan nan +0 +53 nan nan 0 53 nan nan +5 +53 nan +inf 0 53 nan +inf +0 +53 nan -inf 0 53 nan -inf +5 +53 -inf -inf 0 53 -inf -0 +0 +53 -inf -0 0 53 -inf +5 +5 +53 -inf -1 0 53 -inf -0 +0 +53 -inf +inf 0 53 -inf +inf +5 +53 +0 -0 0 53 +0 -0 +0 +53 +0 -0 0 53 +0 +5 +5 +53 +0 +inf 0 53 +0 +inf +5 +53 +5 +inf 0 53 +0 +inf +0 +53 +inf +inf 0 53 +0 +inf +0 +53 +inf +inf 0 53 +5 +inf +5 + +# regular values +53 +10 +20 0 53 +5 +20 5 +16 +0x123400 0xdada00 1 16 +0x111100 +0xdada00 0x111101 +53 +10 +20 0 53 +10 +20 15 +16 +0x123400 0xdada00 0 16 +0x123400 +0xdddd00 0xdddd00 +16 +0x123400 0xdada00 2 16 +0x123400 +0xdadb00 0xdadada + +53 -0x888888 -0x888887 0 53 -0x888888 +0xbaffe0 0xbaffe0 +16 -0x888800 -0x888700 2 16 -0x888800 +0x888900 0x888801 + +16 -0x888800 +0x1 0 16 -0x888800 +0xfedc00 0xfedc00 +16 -0x888800 +0x10 0 16 -0x888800 +0x10 0x8 +16 -0x888800 +0x1 2 16 -0x888800 +0x888900 0x888801 diff --git a/tests/put_z.dat b/tests/put_z.dat new file mode 100644 index 0000000..68e2481 --- /dev/null +++ b/tests/put_z.dat @@ -0,0 +1,51 @@ +# data file for mpfi_put_z +# +# fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: precision of argument +# 9: value of argument + +# special values +53 nan nan 0 53 nan nan -8 +53 nan nan 0 53 nan nan -0 +53 nan nan 0 53 nan nan 0 +53 nan nan 0 53 nan nan 5 +53 -inf -inf 0 53 -inf -8 -8 +53 -inf -inf 0 53 -inf -0 -0 +53 -inf -inf 0 53 -inf -0 0 +53 -inf -inf 0 53 -inf +5 5 +53 +0 -0 0 53 -8 -0 -8 +53 +0 -0 0 53 +0 -0 -0 +53 +0 -0 0 53 +0 -0 0 +53 +0 -0 0 53 +0 +5 5 +53 +inf +inf 0 53 -8 +inf -8 +53 +inf +inf 0 53 +0 +inf -0 +53 +inf +inf 0 53 +0 +inf 0 +53 +inf +inf 0 53 +5 +inf 5 + +# regular values +53 +10 +20 0 53 +5 +20 5 +16 +0x123400 0xdada00 1 16 +0x111100 0xdada00 0x111101 +53 +10 +20 0 53 +10 +20 15 +16 +0x123400 0xdada00 0 16 +0x123400 0xdddd00 0xdddd00 +16 +0x123400 0xdada00 2 16 +0x123400 0xdadb00 0xdadada + +53 -0x888888 -0x888887 0 53 -0xbaffe0 -0x888887 -0xbaffe0 +16 -0x888800 -0x888700 1 16 -0x888900 -0x888700 -0x888801 +53 -0x888800 -0x888700 0 53 -0x888800 -0x888700 -0x888701 +16 -0x888800 -0x888700 0 16 -0x888800 -0x100000 -0x100000 +16 -0x888800 -0x888700 2 16 -0x888800 -0x100000 -0x100001 + +16 -0x888800 +0x1 0 16 -0xfedc00 +0x1 -0xfedc00 +16 -0x888800 +0x1 1 16 -0xfedc00 +0x1 -0xfedb01 +16 -0x888800 +0x1 0 16 -0x888800 +0x1 -1 +16 -0x888800 +0x1 0 16 -0x888800 +0x888800 0x888800 +16 -0x888800 +0x1 2 16 -0x888800 +0x888900 0x888801 diff --git a/tests/q_div.dat b/tests/q_div.dat new file mode 100644 index 0000000..51ca998 --- /dev/null +++ b/tests/q_div.dat @@ -0,0 +1,130 @@ +#file for mpfi_q_div.dat +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: first parameter value +# 6: precision of second parameter +# 7: left endpoint value of second parameter +# 8: right endpoint value of second parameter + +# special values +0 53 nan nan -1/1 53 nan nan +0 53 nan nan 0 53 nan nan +0 53 nan nan 1/1 53 nan nan +0 53 nan nan -3/1 53 nan -inf +0 53 nan nan 0 53 nan -inf +0 53 nan nan 3/1 53 nan -inf +0 53 nan nan -7/1 53 nan -7 +0 53 nan nan 0 53 nan -7 +0 53 nan nan 7/1 53 nan -7 +0 53 nan nan -15/1 53 nan -0 +0 53 nan nan 0 53 nan -0 +0 53 nan nan 15/1 53 nan -0 +0 53 nan nan -31/1 53 nan 1 +0 53 nan nan 0 53 nan 1 +0 53 nan nan 31/1 53 nan 1 +0 53 nan nan -63/1 53 nan +inf +0 53 nan nan 0 53 nan +inf +0 53 nan nan 63/1 53 nan +inf +0 53 +0 -0 -2/1 53 -inf -inf +0 53 +0 -0 0 53 -inf -inf +0 53 +0 -0 2/1 53 -inf -inf +0 53 +0 0.5 -4/1 53 -inf -8 +0 53 +0 -0 0 53 -inf -7 +0 53 -0.5 -0 4/1 53 -inf -8 + +2 53 +0 0x12492492492493p-58 + -1/7 + 53 -inf -8 +1 53 -0x12492492492493p-58 -0 + 1/7 + 53 -inf -8 +2 53 +0 0x12492492492493p-58 + -1/8 + 53 -inf -7 +1 53 -0x12492492492493p-58 -0 + 1/8 + 53 -inf -7 + +0 53 +0 +inf -8/1 53 -inf -0 +0 53 +0 -0 0 53 -inf -0 +0 53 -inf -0 8/1 53 -inf -0 +0 53 -inf +inf -16/1 53 -inf 8 +0 53 -inf +inf 0 53 -inf 8 +0 53 -inf +inf 16/1 53 -inf 8 +0 53 -inf +inf -32/1 53 -inf +inf +0 53 -inf +inf 0 53 -inf +inf +0 53 -inf +inf 32/1 53 -inf +inf +0 53 nan nan -64/1 53 -inf nan +0 53 nan nan 0 53 -inf nan +0 53 nan nan 64/1 53 -inf nan +0 53 -inf +inf -1/1 53 +0 -0 +0 53 +0 -0 0 53 +0 -0 +0 53 -inf +inf 1/1 53 +0 -0 +0 53 -inf -3 -9/1 53 +0 3 +0 53 +0 -0 0 53 +0 3 +0 53 3 +inf 9/1 53 +0 3 +2 53 -inf -0x1c71c71c71c71cp-58 + -1/9 + 53 +0 4 +1 53 0x1c71c71c71c71cp-58 +inf + 1/9 + 53 +0 4 +2 53 -inf -0x1c71c71c71c71cp-58 + -1/4 + 53 0 9 +1 53 0x1c71c71c71c71cp-58 +inf + 1/4 + 53 +0 9 + +0 53 -inf -0 -7/1 53 +0 +inf +0 53 +0 -0 0 53 +0 +inf +0 53 +0 +inf 7/1 53 +0 +inf +0 53 +0 -0 -1/1 53 +inf +inf +0 53 +0 -0 0 53 +inf +inf +0 53 +0 -0 1/1 53 +inf +inf +0 53 nan nan -1/1 53 +inf nan +0 53 nan nan 0 53 +inf nan +0 53 nan nan 1/1 53 +inf nan + +# regular values +0 53 0x1p-48 1 + -3/32 + 53 -0x3p+43 -0x3p-5 +1 53 0x13333333333333p-54 3 + -3/32 + 53 -0x5p-4 -0x1p-5 +2 53 0x1p-48 0x6db6db6db6db7p-14 + -3/32 + 53 -0x3p+43 -0x7p-43 +3 53 0x1b6db6db6db6dbp-59 0x4cccccccccccdp-56 + -3/32 + 53 -7 -5 + +0 53 -inf +inf + -3/32 + 53 -7 +5 + +0 53 0.5 1 + 5/8796093022208 + 53 0x5p-43 0x5p-42 +1 53 0xb6db6db6db6dbp-52 1 + 5/8796093022208 + 53 0x5p-43 0x7p-43 +2 53 1 0x1aaaaaaaaaaaabp-52 + 5/8796093022208 + 53 0x3p-43 0x5p-43 +3 53 0xb6db6db6db6dbp-52 0x1aaaaaaaaaaaabp-52 + 5/8796093022208 + 53 0x3p-43 0x7p-43 + +3 53 0xfffffffffffffp-52 0x10000000000001p-52 + 1/3 + 53 0x15555555555555p-54 0xaaaaaaaaaaaabp-53 +3 4 0xfp-4 0x9p-3 + 1165/16384 + 53 0x1234p-16 0x1234p-16 diff --git a/tests/q_sub.dat b/tests/q_sub.dat new file mode 100644 index 0000000..46b3230 --- /dev/null +++ b/tests/q_sub.dat @@ -0,0 +1,129 @@ +# data file for mpfi_q_sub +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: first parameter value +# 6: precision of second parameter +# 7: left endpoint value of second parameter +# 8: right endpoint value of second parameter + +# special values +0 53 nan nan -1/1 53 nan nan +0 53 nan nan 0 53 nan nan +0 53 nan nan 1/1 53 nan nan +0 53 +inf nan -3/1 53 nan -inf +0 53 +inf nan 0 53 nan -inf +0 53 +inf nan 3/1 53 nan -inf +0 53 +0 nan -7/1 53 nan -7 +0 53 7 nan 0 53 nan -7 +0 53 14 nan 7/1 53 nan -7 +0 53 -15 nan -15/1 53 nan -0 +0 53 +0 nan 0 53 nan -0 +0 53 15 nan 15/1 53 nan -0 +0 53 -32 nan -31/1 53 nan 1 +0 53 -1 nan 0 53 nan 1 +0 53 30 nan 31/1 53 nan 1 +0 53 -inf nan -63/1 53 nan +inf +0 53 -inf nan 0 53 nan +inf +0 53 -inf nan 63/1 53 nan +inf +0 53 +inf +inf -2/1 53 -inf -inf +0 53 +inf +inf 0 53 -inf -inf +0 53 +inf +inf 2/1 53 -inf -inf +0 53 3 +inf -4/1 53 -inf -7 +0 53 7 +inf 0 53 -inf -7 +0 53 11 +inf 4/1 53 -inf -7 + +1 53 0x1b6db6db6db6dbp-50 +inf + -1/7 + 53 -inf -7 +1 53 0x1c924924924924p-50 +inf + 1/7 + 53 -inf -7 +1 53 0x1fffffffffffffp+17 +inf + -7/1 + 53 -inf -0x1p+70 +1 53 0x1p+70 +inf + 7/1 + 53 -inf -0x1p+70 + +0 53 -8 +inf -8/1 53 -inf -0 +0 53 +0 +inf 0 53 -inf -0 +0 53 8 +inf 8/1 53 -inf -0 +0 53 -24 +inf -16/1 53 -inf 8 +0 53 -8 +inf 0 53 -inf 8 +0 53 8 +inf 16/1 53 -inf 8 +0 53 -inf +inf -32/1 53 -inf +inf +0 53 -inf +inf 0 53 -inf +inf +0 53 -inf +inf 32/1 53 -inf +inf +0 53 nan +inf -64/1 53 -inf nan +0 53 nan +inf 0 53 -inf nan +0 53 nan +inf 64/1 53 -inf nan +0 53 -1 -1 -1/1 53 +0 -0 +0 53 +0 -0 0 53 +0 -0 +0 53 1 1 1/1 53 +0 -0 +0 53 -11 -3 -3/1 53 +0 8 +0 53 -8 -0 0 53 +0 8 +0 53 -5 3 3/1 53 +0 8 +0 53 -inf -7 -7/1 53 +0 +inf +0 53 -inf -0 0 53 +0 +inf +0 53 -inf +7 7/1 53 +0 +inf + +2 53 -inf -0x12492492492492p-55 + -1/7 + 53 +0 +inf +2 53 -inf 0x12492492492493p-55 + 1/7 + 53 +0 +inf +2 53 -inf -0x1p+70 + -7/1 + 53 0x1p+70 +inf +2 53 -inf -0x1fffffffffffffp+17 + 7/1 + 53 0x1p+70 +inf + +0 53 -inf -inf -1/1 53 +inf +inf +0 53 -inf -inf 0 53 +inf +inf +0 53 -inf -inf 1/1 53 +inf +inf +0 53 nan -inf -1/1 53 +inf nan +0 53 nan -inf 0 53 +inf nan +0 53 nan -inf 1/1 53 +inf nan + +# regular values +0 53 -15 -0 -32/1 53 -32 -17 +0 53 49 64 32/1 53 -32 -17 +0 53 34 49 17/1 53 -32 -17 + +0 53 -0x123456789abce2 -0x153456789abcdfp-48 + -3/1 + 53 0x123456789abcdfp-48 0x123456789abcdf +1 53 -0x10123456789abdp-44 -1 + -256/1 + 53 -0xff 0x123456789abcdfp-52 +2 53 -0x123456789abce2 -0x3123456789abcdp-52 + -3/1 + 53 0x123456789abcdfp-56 0x123456789abcdf +3 53 -0x1001 -0xfff + -0x1001/1 + 53 -0x1fffffffffffffp-52 -0x1p-550 + +0 53 -0x123456789abcdc -0xf3456789abcdfp-48 + 3/1 + 53 0x123456789abcdfp-48 0x123456789abcdf +1 53 0xfedcba9876543p-44 0x1ff + 256/1 + 53 -0xff 0x123456789abcdfp-52 +2 53 -0x123456789abcdc 0x2edcba98765433p-52 + 3/1 + 53 0x123456789abcdfp-56 0x123456789abcdf +3 53 0x1001 0x1003 + 0x1001/1 + 53 -0x1fffffffffffffp-52 -0x1p-550 + +# check if a double rounding occurs +3 4 -16 -0.3125 -97/3 53 -32 -17 +3 4 -0.34375 15 -52/3 53 -32 -17 +0 4 1 15 -17/1 53 -32 -18 diff --git a/tests/random.c b/tests/random.c new file mode 100644 index 0000000..2cfe52f --- /dev/null +++ b/tests/random.c @@ -0,0 +1,217 @@ +/* random.c -- Handle random seed in tests. + +Copyright (C) 2009, 2010, + Spaces project, Inria Lorraine + Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library, based on the MPFR Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the MPFR Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +/* Put test_start at the beginning of your test function and + test_end at the end. + These are an adaptation of those of MPFR. */ + +#include "mpfi-tests.h" + +#include "mpfi_config.h" + +#ifdef TIME_WITH_SYS_TIME +# include +# include +#else +# ifdef HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + +#ifdef HAVE_LIMITS_H +#include +#endif +#ifndef ULONG_MAX +# define ULONG_MAX 4294967295 +#endif + +#ifdef HAVE_FLOAT_H +#include +#endif +#ifndef DBL_MANT_DIG +# define DBL_MANT_DIG 53 +#endif +#ifndef DBL_MAX_EXP +# define DBL_MAX_EXP +1024 +#endif + +gmp_randstate_t rands; +char rands_initialized; + +void +test_start (void) +{ + char *environment_seed; + unsigned long seed; + + if (rands_initialized) { + printf ("Put test_start ONCE at the beginning of your test function.\n"); + exit (1); + } + + gmp_randinit_default (rands); + rands_initialized = 1; + + environment_seed = getenv ("MPFI_CHECK_RANDOMIZE"); + if (environment_seed == NULL) + gmp_randseed_ui (rands, 0xfac11e); + else { + seed = atoi (environment_seed); + if (seed == 0 || seed == 1) { +#if HAVE_GETTIMEOFDAY + struct timeval tv; + gettimeofday (&tv, NULL); + seed = tv.tv_sec + tv.tv_usec; +#else + time_t tv; + time (&tv); + seed = tv; +#endif + gmp_randseed_ui (rands, seed); + printf ("Seed MPFI_CHECK_RANDOMIZE=%lu " + "(include this in bug reports)\n", seed); + } + else { + printf ("Re-seeding with MPFI_CHECK_RANDOMIZE=%lu\n", seed); + gmp_randseed_ui (rands, seed); + } + } +} + +void +test_end (void) +{ + if (rands_initialized) { + rands_initialized = 0; + gmp_randclear (rands); + } + else { + printf ("Put test_start at the beginning of your test function.\n"); + exit (1); + } + + mpfr_free_cache (); +} + +unsigned long +random_ui () +{ + return gmp_urandomm_ui (rands, ULONG_MAX); +} + +long +random_si () +{ + return (long)gmp_urandomm_ui (rands, ULONG_MAX); +} + +double +random_double () +{ + double d; + mpfr_t x; + + mpfr_init2 (x, DBL_MANT_DIG + 1); + mpfr_urandomb (x, rands); + mpfr_sub_d (x, x, 0.5, MPFI_RNDD); + mpfr_mul_2ui (x, x, DBL_MAX_EXP + 1, MPFI_RNDD); + d = mpfr_get_d (x, MPFI_RNDD); + mpfr_clear (x); + + return d; +} + +void +random_mpz (mpz_ptr z, unsigned long n) +{ + return mpz_urandomb (z, rands, n); +} + +void +random_mpq (mpq_ptr q) +{ + mpq_set_si (q, random_si (), random_ui ()); +} + +/* random endpoint with non-uniform distribution: + Prob(x == -oo) = 1/8 + Prob(-oo < x < -1) = 1/4 + Prob(-1 < x < 0) = 1/8 + Prob(0 < x < +1) = 1/8 + Prob(+1 < x < +oo) = 1/4 + Prob(x == +oo) = 1/8 + */ +void +random_mpfr (mpfr_ptr x) +{ + unsigned long r; + + r = gmp_urandomb_ui (rands, 3); + if (r < 1) { + mpfr_set_inf (x, +1); + return; + } + if (r < 2) { + mpfr_set_inf (x, -1); + return; + } + mpfr_urandomb (x, rands); + if (r < 3) + return; + if (r < 4) { + mpfr_neg (x, x, MPFI_RNDD); + return; + } + mpfr_ui_div (x, 1, x, MPFI_RNDD); + if (r < 6) + return; + mpfr_neg (x, x, MPFI_RNDD); +} + +/* random interval with non-uniform distribution: + Prob(inf == -oo) = Prob(sup == +oo) = 1/8 + 7/64 + Prob(-oo < inf < -1) = Prob(+1 < sup < +oo) = 3/8 + Prob(-1 < inf < 0) = Prob(0 < sup < +1) = 1/16 + 5/64 + Prob(0 < inf < +1) = Prob(-1 < sup < 0) = 1/16 + 3/64 + Prob(+1 < inf < +oo) = Prob(-oo < sup < -1) = 1/8 + Prob(inf == +oo) = Prob(sup == -oo) = 1/64 + where inf = left endpoint, sup = right endpoint + */ +void +random_interval (mpfi_ptr i) +{ + mpfr_t x; + + mpfr_init2 (x, mpfi_get_prec (i)); + + random_mpfr (x); + mpfi_set_fr (i, x); + random_mpfr (x); + mpfi_put_fr (i, x); + + mpfr_clear (x); +} diff --git a/tests/read_data.c b/tests/read_data.c new file mode 100644 index 0000000..2161d8c --- /dev/null +++ b/tests/read_data.c @@ -0,0 +1,565 @@ +/* read_data.c -- Helper functions to read data files. + +Copyright 2009, 2010, 2011, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include +#include "mpfi-tests.h" +#include "mpfi_config.h" + +char *pathname; +unsigned long line_number; /* file name with complete path and currently read + line; kept globally to simplify parameter + passing */ +int nextchar; /* character appearing next in the file, may be EOF */ + +FILE* +open_file (const char* file_name) +{ + FILE *fp; + char *src_dir; + char default_srcdir[] = "."; + + src_dir = getenv ("srcdir"); + if (src_dir == NULL) + src_dir = default_srcdir; + + pathname = (char *) malloc ((strlen (src_dir)) + strlen (file_name) + 2); + if (pathname == NULL) { + printf ("Cannot allocate memory\n"); + exit (1); + } + sprintf (pathname, "%s/%s", src_dir, file_name); + fp = fopen (pathname, "r"); + if (fp == NULL) { + fprintf (stderr, "Unable to open %s\n", pathname); + exit (1); + } + + return fp; +} + +void +close_file (FILE *f) +{ + free (pathname); + fclose (f); +} + +void +init_reading (FILE* f) +{ + line_number = 1; + nextchar = getc (f); + skip_whitespace_comments (f); +} + +/* comparisons: return true when arguments have the same value (even if both + are NaN) */ +int +same_mpfr_value (mpfr_srcptr got, mpfr_srcptr ref) +{ + if (mpfr_nan_p (got) || mpfr_nan_p (ref)) + return mpfr_nan_p (ref) && mpfr_nan_p (got); + if (mpfr_inf_p (got)) + return mpfr_inf_p (ref) && mpfr_signbit (got) == mpfr_signbit (ref); + if (mpfr_zero_p (got)) + return mpfr_zero_p (ref) && mpfr_signbit (got) == mpfr_signbit (ref); + return mpfr_cmp (got, ref) == 0; +} + +int +same_value (mpfi_srcptr a, mpfi_srcptr b) +{ + return same_mpfr_value (&(a->left), &(b->left)) + && same_mpfr_value (&(a->right), &(b->right)); +} + + +/* read primitives */ + +/* skips characters until reaching '\n' or EOF; + '\n' is skipped as well */ +static void +skip_line (FILE *f) +{ + while (nextchar != EOF && nextchar != '\n') + nextchar = getc (f); + if (nextchar != EOF) { + line_number++; + nextchar = getc (f); + } +} + +/* skips over whitespace if any until reaching EOF or non-whitespace */ +static void +skip_whitespace (FILE *f) +{ + while (isspace (nextchar)) { + if (nextchar == '\n') + line_number++; + nextchar = getc (f); + } +} + +/* skips over all whitespace and comments, if any */ +void +skip_whitespace_comments (FILE *f) +{ + skip_whitespace (f); + while (nextchar == '#') { + skip_line (f); + if (nextchar != EOF) + skip_whitespace (f); + } +} + + +/* Read operand in file, and sometimes check its validity */ + +void +read_sign (FILE *f, int *sign) +{ + switch (nextchar) { + case '-': + *sign = -1; + break; + case '0': + *sign = 0; + break; + case '+': + *sign = +1; + break; + default: + printf ("Error: unexpected signedness '%c' in file '%s' line %lu\n", + nextchar, pathname, line_number); + exit (1); + } + + nextchar = getc (f); + if (!isspace(nextchar)) { + printf ("Error: unexpected character '%c' after exactness flag" + " in file '%s' line %lu\n", nextchar, pathname, line_number); + exit (1); + } + + skip_whitespace_comments (f); +} + +void +read_exactness (FILE *f, int *exactness) +{ + if (!isdigit (nextchar) || nextchar < '0' || nextchar > '4') { + printf ("Error: unexpected exactness flag '%c' in file '%s' line %lu\n", + nextchar, pathname, line_number); + exit (1); + } + + *exactness = nextchar - '0'; + nextchar = getc (f); + if (!isspace(nextchar)) { + printf ("Error: unexpected character '%c' after exactness flag" + " in file '%s' line %lu\n", nextchar, pathname, line_number); + exit (1); + } + + skip_whitespace_comments (f); +} + +void +read_ui (FILE *f, unsigned long *i) +{ + mpfr_t x; + + mpfr_init2 (x, 32); + + if (nextchar == EOF) { + printf ("Error: Unexpected EOF when reading integer " + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + ungetc (nextchar, f); + if (mpfr_inp_str (x, f, 0, MPFI_RNDD) == 0) { + printf ("Error: Impossible to read integer in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + + + if (mpfr_fits_ulong_p (x, MPFI_RNDD)) + *i = mpfr_get_ui (x, MPFI_RNDD); + else { + printf ("Error: the number "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf (" read in file '%s' line %lu does not fit " + "in an unsigned long int\n", + pathname, line_number); + exit (1); + } + + nextchar = getc (f); + skip_whitespace_comments (f); + + mpfr_clear (x); +} + +void +read_uj (FILE *f, uintmax_t *i) +{ + mpfr_t x; + + /* unknown constant... + mpfr_init2 (x, INTMAX_WIDTH); + */ + mpfr_init2 (x, sizeof(uintmax_t)); + + if (nextchar == EOF) { + printf ("Error: Unexpected EOF when reading integer " + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + ungetc (nextchar, f); + if (mpfr_inp_str (x, f, 0, MPFI_RNDD) == 0) { + printf ("Error: Impossible to read integer in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + + + if (mpfr_fits_uintmax_p (x, MPFI_RNDD)) + *i = mpfr_get_uj (x, MPFI_RNDD); + else { + printf ("Error: the number "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf (" read in file '%s' line %lu does not fit " + "in an unsigned long int\n", + pathname, line_number); + exit (1); + } + + nextchar = getc (f); + skip_whitespace_comments (f); + + mpfr_clear (x); +} + +void +read_si (FILE *f, long *i) +{ + mpfr_t x; + + mpfr_init2 (x, 32); + + if (nextchar == EOF) { + printf ("Error: Unexpected EOF when reading integer " + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + ungetc (nextchar, f); + if (mpfr_inp_str (x, f, 0, MPFI_RNDD) == 0) { + printf ("Error: Impossible to read integer in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + + if (mpfr_fits_slong_p (x, MPFI_RNDD)) + *i = mpfr_get_si (x, MPFI_RNDD); + else { + printf ("Error: the number "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf (" read in file '%s' line %lu does not fit in a long int\n", + pathname, line_number); + exit (1); + } + + nextchar = getc (f); + skip_whitespace_comments (f); + + mpfr_clear (x); +} + +void +read_sj (FILE *f, intmax_t *i) +{ + mpfr_t x; + + /* unknown constant... + mpfr_init2 (x, INTMAX_WIDTH); + */ + mpfr_init2 (x, sizeof(intmax_t)); + + if (nextchar == EOF) { + printf ("Error: Unexpected EOF when reading integer " + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + ungetc (nextchar, f); + if (mpfr_inp_str (x, f, 0, MPFI_RNDD) == 0) { + printf ("Error: Impossible to read integer in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + + if (mpfr_fits_intmax_p (x, MPFI_RNDD)) + *i = mpfr_get_sj (x, MPFI_RNDD); + else { + printf ("Error: the number "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf (" read in file '%s' line %lu does not fit in a huge int\n", + pathname, line_number); + exit (1); + } + + nextchar = getc (f); + skip_whitespace_comments (f); + + mpfr_clear (x); +} + +/* WARNING: when reading a double value, all roundings are towards + minus infinity and the precision depends on the host system. */ +int +read_double (FILE *f, double *d) +{ + int ret; + mpfr_t x; + +#if defined(DBL_MANT_DIG) && DBL_MANT_DIG > 53 + mpfr_init2 (x, DBL_MANT_DIG); +#else + mpfr_init2 (x, 53); +#endif + + if (nextchar == EOF) { + printf ("Error: Unexpected EOF when reading double" + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + ungetc (nextchar, f); + if (mpfr_inp_str (x, f, 0, MPFI_RNDD) == 0) { + printf ("Error: Impossible to read double in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + + *d = mpfr_get_d (x, MPFI_RNDD); + ret = mpfr_cmp_d (x, *d); /* verify conversion */ + + nextchar = getc (f); + skip_whitespace_comments (f); + + mpfr_clear (x); + + return ret; +} + +int +read_float (FILE *f, float *d) +{ + int ret; + mpfr_t x; + +#if defined(FLT_MANT_DIG) && FLT_MANT_DIG > 24 + mpfr_init2 (x, FLT_MANT_DIG); +#else + mpfr_init2 (x, 24); +#endif + + if (nextchar == EOF) { + printf ("Error: Unexpected EOF when reading float" + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + ungetc (nextchar, f); + if (mpfr_inp_str (x, f, 0, MPFI_RNDD) == 0) { + printf ("Error: Impossible to read float in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + + *d = mpfr_get_flt (x, MPFI_RNDD); + ret = mpfr_cmp_d (x, *d); /* verify conversion */ + + nextchar = getc (f); + skip_whitespace_comments (f); + + mpfr_clear (x); + + return ret; +} + +int +read_long_double (FILE *f, long double *d) +{ + int ret; + mpfr_t x; + +#if defined(LDBL_MANT_DIG) && LDBL_MANT_DIG > 64 + mpfr_init2 (x, LDBL_MANT_DIG); +#else + mpfr_init2 (x, 64); +#endif + + if (nextchar == EOF) { + printf ("Error: Unexpected EOF when reading long double" + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + ungetc (nextchar, f); + if (mpfr_inp_str (x, f, 0, MPFI_RNDD) == 0) { + printf ("Error: Impossible to read long double in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + + *d = mpfr_get_ld (x, MPFI_RNDD); + ret = mpfr_cmp_ld (x, *d); /* verify conversion */ + + nextchar = getc (f); + skip_whitespace_comments (f); + + mpfr_clear (x); + + return ret; +} + +void +read_mpz (FILE *f, mpz_ptr x) +{ + if (nextchar == EOF) { + printf ("Error: Unexpected EOF when reading mpz number" + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + ungetc (nextchar, f); + if (mpz_inp_str (x, f, 0) == 0) { + printf ("Error: Impossible to read mpz number " + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + + nextchar = getc (f); + skip_whitespace_comments (f); +} + +void +read_mpq (FILE *f, mpq_ptr x) +{ + if (nextchar == EOF) { + printf ("Error: Unexpected EOF when reading mpq number" + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + ungetc (nextchar, f); + if (mpq_inp_str (x, f, 0) == 0) { + printf ("Error: Impossible to read mpq number " + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + + nextchar = getc (f); + skip_whitespace_comments (f); +} + +static mpfr_prec_t +read_prec (FILE *f) +{ + unsigned long prec; + int n; + + if (nextchar == EOF) { + printf ("Error: Unexpected EOF when reading mpfr precision " + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + ungetc (nextchar, f); + n = fscanf (f, "%lu", &prec); + if (ferror (f)) /* then also n == EOF */ + perror ("Error when reading precision"); + if (n == 0 || n == EOF || prec < MPFR_PREC_MIN || prec > MPFR_PREC_MAX) { + printf ("Error: Impossible precision in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + nextchar = getc (f); + skip_whitespace_comments (f); + return (mpfr_prec_t) prec; +} + +static void +read_mpfr_number (FILE *f, mpfr_ptr x) +{ + if (nextchar == EOF) { + printf ("Error: Unexpected EOF when reading mpfr number" + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + ungetc (nextchar, f); + if (mpfr_inp_str (x, f, 0, MPFR_RNDN) == 0) { + printf ("Error: Impossible to read mpfr number " + "in file '%s' line %lu\n", + pathname, line_number); + exit (1); + } + + nextchar = getc (f); + skip_whitespace_comments (f); +} + +void +read_mpfr (FILE *f, mpfr_ptr x) +{ + mpfr_set_prec (x, read_prec (f)); + read_mpfr_number (f, x); +} + +void +read_mpfi (FILE *f, mpfi_ptr a) +{ + mpfi_set_prec (a, read_prec (f)); + read_mpfr_number (f, &(a->left)); + read_mpfr_number (f, &(a->right)); + +#ifdef WARN_IF_REVERTED_ENDPOINTS + if (mpfr_cmp (&(a->left), &(a->right)) > 0) + printf ("Warning: reverted endpoints line %lu\n", line_number); + if (mpfr_zero_p (&(a->left)) && mpfr_signbit (&(a->left))) + printf ("Warning: -0 as lower bound line %lu\n", line_number); + if (mpfr_zero_p (&(a->right)) && !mpfr_signbit (&(a->right))) + printf ("Warning: +0 in upper bound line %lu\n", line_number); +#endif +} diff --git a/tests/sec.dat b/tests/sec.dat new file mode 100644 index 0000000..84bd13d --- /dev/null +++ b/tests/sec.dat @@ -0,0 +1,144 @@ +# data file for mpfi_sec +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 -inf nan +0 53 nan nan 53 -inf -inf +0 53 -inf +inf 53 -inf -7 +0 53 -inf +inf 53 -inf -0 +0 53 -inf +inf 53 -inf 8 +0 53 -inf +inf 53 -inf +inf +0 53 -inf +inf 53 -8 -0 +0 53 -inf +inf 53 -3 -0 +2 53 1 0x1d9cf0f125cc2ap-52 53 -1 -0 +0 53 1 1 53 +0 -0 +2 53 1 0x1d9cf0f125cc2ap-52 53 +0 +1 +0 53 -inf +inf 53 +0 3 +0 53 -inf +inf 53 +0 8 +0 53 -inf +inf 53 +0 +inf +0 53 nan nan 53 +inf +inf + +# regular values +0 53 -inf +inf 53 -6 7 +0 53 -inf +inf 53 -6 6 +0 53 -inf +inf 53 -6 5 +0 53 -inf +inf 53 -6 4 +0 53 -inf +inf 53 -6 3 +0 53 -inf +inf 53 -6 2 +0 53 -inf +inf 53 -6 1 +0 53 -inf +inf 53 -6 -0 +0 53 -inf +inf 53 -6 -1 +0 53 -inf +inf 53 -6 -2 +0 53 -inf +inf 53 -6 -3 +0 53 -inf +inf 53 -6 -4 +3 53 0x10a9e8f3e19df1p-52 0x1c33db0464189bp-51 53 -6 -5 +3 53 0x10a9e8f3e19df1p-52 0x10a9e8f3e19df2p-52 53 -6 -6 + +0 53 -inf +inf 53 -5 7 +0 53 -inf +inf 53 -5 6 +0 53 -inf +inf 53 -5 5 +0 53 -inf +inf 53 -5 4 +0 53 -inf +inf 53 -5 3 +0 53 -inf +inf 53 -5 2 +0 53 -inf +inf 53 -5 1 +0 53 -inf +inf 53 -5 -0 +0 53 -inf +inf 53 -5 -1 +0 53 -inf +inf 53 -5 -2 +0 53 -inf +inf 53 -5 -3 +0 53 -inf +inf 53 -5 -4 +3 53 0x1c33db0464189ap-51 0x1c33db0464189bp-51 53 -5 -5 + +0 53 -inf +inf 53 -4 7 +0 53 -inf +inf 53 -4 6 +0 53 -inf +inf 53 -4 5 +0 53 -inf +inf 53 -4 4 +0 53 -inf +inf 53 -4 3 +0 53 -inf +inf 53 -4 2 +0 53 -inf +inf 53 -4 1 +0 53 -inf +inf 53 -4 -0 +0 53 -inf +inf 53 -4 -1 +1 53 -0x133956fecf9e49p-51 -1 53 -4 -2 +1 53 -0x187a6961d2485fp-52 -1 53 -4 -3 +3 53 -0x187a6961d2485fp-52 -0x187a6961d2485ep-52 53 -4 -4 + +0 53 -inf +inf 53 -3 7 +0 53 -inf +inf 53 -3 6 +0 53 -inf +inf 53 -3 5 +0 53 -inf +inf 53 -3 4 +0 53 -inf +inf 53 -3 3 +0 53 -inf +inf 53 -3 2 +0 53 -inf +inf 53 -3 1 +0 53 -inf +inf 53 -3 -0 +0 53 -inf +inf 53 -3 -1 +3 53 -0x133956fecf9e49p-51 -0x102967b457b245p-52 53 -3 -2 +3 53 -0x102967b457b246p-52 -0x102967b457b245p-52 53 -3 -3 + +0 53 -inf +inf 53 -2 7 +0 53 -inf +inf 53 -2 6 +0 53 -inf +inf 53 -2 5 +0 53 -inf +inf 53 -2 4 +0 53 -inf +inf 53 -2 3 +0 53 -inf +inf 53 -2 2 +0 53 -inf +inf 53 -2 1 +0 53 -inf +inf 53 -2 -0 +0 53 -inf +inf 53 -2 -1 +3 53 -0x133956fecf9e49p-51 -0x133956fecf9e48p-51 53 -2 -2 + +0 53 -inf +inf 53 -1 7 +0 53 -inf +inf 53 -1 6 +0 53 -inf +inf 53 -1 5 +0 53 -inf +inf 53 -1 4 +0 53 -inf +inf 53 -1 3 +0 53 -inf +inf 53 -1 2 +2 53 1 0x1d9cf0f125cc2ap-52 53 -1 1 +2 53 1 0x1d9cf0f125cc2ap-52 53 -1 -0 +3 53 0x1d9cf0f125cc29p-52 0x1d9cf0f125cc2ap-52 53 -1 -1 + +0 53 -inf +inf 53 1 7 +0 53 -inf +inf 53 1 6 +0 53 -inf +inf 53 1 5 +0 53 -inf +inf 53 1 4 +0 53 -inf +inf 53 1 3 +0 53 -inf +inf 53 1 2 +3 53 0x1d9cf0f125cc29p-52 0x1d9cf0f125cc2ap-52 53 1 1 + +0 53 -inf +inf 53 2 7 +0 53 -inf +inf 53 2 6 +0 53 -inf +inf 53 2 5 +1 53 -0x133956fecf9e49p-51 -1 53 2 4 +3 53 -0x133956fecf9e49p-51 -0x102967b457b245p-52 53 2 3 +3 53 -0x133956fecf9e49p-51 -0x133956fecf9e48p-51 53 2 2 + +0 53 -inf +inf 53 3 7 +0 53 -inf +inf 53 3 6 +0 53 -inf +inf 53 3 5 +1 53 -0x187a6961d2485fp-52 -1 53 3 4 +3 53 -0x102967b457b246p-52 -0x102967b457b245p-52 53 3 3 + +0 53 -inf +inf 53 4 7 +0 53 -inf +inf 53 4 6 +0 53 -inf +inf 53 4 5 +3 53 -0x187a6961d2485fp-52 -0x187a6961d2485ep-52 53 4 4 + +2 53 1 0x1c33db0464189bp-51 53 5 7 +3 53 0x10a9e8f3e19df1p-52 0x1c33db0464189bp-51 53 5 6 +3 53 0x1c33db0464189ap-51 0x1c33db0464189bp-51 53 5 5 + +2 53 1 0x153910a80e7db5p-52 53 6 7 +3 53 0x10a9e8f3e19df1p-52 0x10a9e8f3e19df2p-52 53 6 6 + +3 53 0x153910a80e7db4p-52 0x153910a80e7db5p-52 53 7 7 diff --git a/tests/sech.dat b/tests/sech.dat new file mode 100644 index 0000000..b5f71f7 --- /dev/null +++ b/tests/sech.dat @@ -0,0 +1,43 @@ +# data file for mpfi_sech +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 -inf nan +0 53 +0 -0 53 -inf -inf +2 53 +0 0x1de169fb49b339p-62 53 -inf -7 +0 53 +0 1 53 -inf -0 +0 53 +0 1 53 -inf +8 +0 53 +0 1 53 -inf +inf +1 53 0x14bcdc50ed6be7p-53 1 53 -1 -0 +0 53 1 1 53 +0 -0 +1 53 0x14bcdc50ed6be7p-53 1 53 +0 +1 +1 53 0x15fc20da8e18dbp-63 1 53 +0 +8 +0 53 +0 1 53 +0 +inf +0 53 +0 -0 53 +inf +inf + +# regular values +1 53 0x1fc069fe3f72bep-53 1 + 53 -0.125 -0 +1 53 0x1c60d1ff040dcfp-53 1 + 53 0 0x10000000000001p-53 +3 53 0x16bf984a9a2355p-58 0x1aa0b464a5e24ap-53 + 53 -4.5 -0.625 +3 53 0x196d8e17d88eb1p-56 0x14bcdc50ed6be8p-53 + 53 1 3 + +3 53 0x10000000000173p-1074 0x1639e3175a6893p-76 + 53 17 0xb145bb71d3dbp-38 diff --git a/tests/set_d.dat b/tests/set_d.dat new file mode 100644 index 0000000..96c8523 --- /dev/null +++ b/tests/set_d.dat @@ -0,0 +1,39 @@ +# data file for mpfi_set_d +# +# fields: see put_ui.dat + +# special values +53 nan nan 0 53 -inf -inf -inf +53 nan nan 0 53 -8 -8 -8 +53 nan nan 0 53 +0 -0 -0 +53 nan nan 0 53 +0 -0 +0 +53 nan nan 0 53 +5 +5 +5 +53 +7 -7 0 53 +inf +inf +inf +53 +7 -7 0 53 nan nan nan +53 +7 -7 0 53 -inf -inf -inf +53 +7 -7 0 53 -8 -8 -8 +53 +7 -7 0 53 +0 -0 -0 +53 nan nan 0 53 +0 -0 +0 +53 nan nan 0 53 +5 +5 +5 +53 nan nan 0 53 +inf +inf +inf +53 +0 -0 0 53 nan nan nan +53 +0 -0 0 53 -inf -inf -inf +53 nan nan 0 53 -8 -8 -8 +53 nan nan 0 53 +0 -0 -0 +53 nan nan 0 53 +0 -0 +0 +53 nan nan 0 53 +5 +5 +5 +53 nan nan 0 53 +inf +inf +inf +53 -1 +1 0 53 nan nan nan +53 -1 +1 0 53 -inf -inf -inf +53 -1 +1 0 53 -8 -8 -8 +53 -1 +1 0 53 +0 -0 -0 +53 nan nan 0 53 +0 -0 +0 +53 nan nan 0 53 +5 +5 +5 +53 nan nan 0 53 +inf +inf +inf +53 +0 +1 0 53 nan nan nan + +# regular values + 53 +0x123456789abcdep-16 +0x1fedcba9876543p-16 +0 53 +0x11111111111111 +0x11111111111111 +0x11111111111111 + 49 +0x123456789abcdp-57 +0x1fedcba987654p+33 +3 49 +0x1111111111111 +0x1111111111112 +0x11111111111111p-4 diff --git a/tests/set_flt.dat b/tests/set_flt.dat new file mode 100644 index 0000000..9306afa --- /dev/null +++ b/tests/set_flt.dat @@ -0,0 +1,37 @@ +# data file for mpfi_set_flt +# +# fields: see put_ui.dat + +# special values +24 nan nan 0 24 -inf -inf -inf +24 nan nan 0 24 -8 -8 -8 +24 nan nan 0 24 +0 -0 -0 +24 nan nan 0 24 +0 -0 +0 +24 nan nan 0 24 +5 +5 +5 +24 +7 -7 0 24 +inf +inf +inf +24 +7 -7 0 24 nan nan nan +24 +7 -7 0 24 -inf -inf -inf +24 +7 -7 0 24 -8 -8 -8 +24 +7 -7 0 24 +0 -0 -0 +24 nan nan 0 24 +0 -0 +0 +24 nan nan 0 24 +5 +5 +5 +24 nan nan 0 24 +inf +inf +inf +24 +0 -0 0 24 nan nan nan +24 +0 -0 0 24 -inf -inf -inf +24 nan nan 0 24 -8 -8 -8 +24 nan nan 0 24 +0 -0 -0 +24 nan nan 0 24 +0 -0 +0 +24 nan nan 0 24 +5 +5 +5 +24 nan nan 0 24 +inf +inf +inf +24 -1 +1 0 24 nan nan nan +24 -1 +1 0 24 -inf -inf -inf +24 -1 +1 0 24 -8 -8 -8 +24 -1 +1 0 24 +0 -0 -0 +24 nan nan 0 24 +0 -0 +0 +24 nan nan 0 24 +5 +5 +5 +24 nan nan 0 24 +inf +inf +inf +24 +0 +1 0 24 nan nan nan + +# regular values + 24 +0x123456p-16 +0xfedcbap-16 0 24 +0x111111 +0x111111 +0x111111 + 20 +0x123456p-57 +0xfedcbap+33 3 20 +0x1.111110 +0x1.111112 +0x1.111111 diff --git a/tests/set_fr.dat b/tests/set_fr.dat new file mode 100644 index 0000000..9a04b7b --- /dev/null +++ b/tests/set_fr.dat @@ -0,0 +1,48 @@ +# data file for mpfi_set_fr +# +# column fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: precision of argument +# 9: value of argument + +# special values +53 nan nan 0 53 -inf -inf 53 -inf +53 -inf -inf 0 53 -8 -8 53 -8 +53 nan nan 0 53 +0 -0 53 -0 +53 nan nan 0 53 +0 -0 53 +0 +53 nan nan 0 53 +5 +5 53 +5 +53 nan nan 0 53 +inf +inf 53 +inf +53 -inf -0 0 53 nan nan 53 nan +53 nan nan 0 53 -inf -inf 53 -inf +53 -inf -inf 0 53 -8 -8 53 -8 +53 -inf -inf 0 53 +0 -0 53 -0 +53 -inf -inf 0 53 +0 -0 53 +0 +53 -inf -inf 0 53 +5 +5 53 +5 +53 -inf -inf 0 53 +inf +inf 53 +inf +53 -inf -inf 0 53 nan nan 53 nan +53 +0 -0 0 53 -inf -inf 53 -inf +53 +0 -0 0 53 -8 -8 53 -8 +53 +0 -0 0 53 +0 -0 53 -0 +53 +0 -0 0 53 +0 -0 53 +0 +53 +0 -0 0 53 +5 +5 53 +5 +53 +0 -0 0 53 +inf +inf 53 +inf +53 +0 -0 0 53 nan nan 53 nan +53 +inf +inf 0 53 -inf -inf 53 -inf +53 +inf +inf 0 53 -8 -8 53 -8 +53 +inf +inf 0 53 +0 -0 53 -0 +53 +inf +inf 0 53 +0 -0 53 +0 +53 +inf +inf 0 53 +5 +5 53 +5 +53 -inf +inf 0 53 +inf +inf 53 +inf +53 +inf +inf 0 53 nan nan 53 nan + +# regular values +53 nan nan 0 53 0x1999999999999a@-14 0x1999999999999a@-14 53 0.1 + 2 nan nan 3 2 0x18@-2 0x2@-1 53 0.1 diff --git a/tests/set_ld.dat b/tests/set_ld.dat new file mode 100644 index 0000000..55fc83c --- /dev/null +++ b/tests/set_ld.dat @@ -0,0 +1,40 @@ +# data file for mpfi_set_d +# +# fields: see put_ui.dat +# long doubles seem to be at least 64 bits of precision, can be up to 106... check only with 64 + +# special values +64 nan nan 0 64 -inf -inf -inf +64 nan nan 0 64 -8 -8 -8 +64 nan nan 0 64 +0 -0 -0 +64 nan nan 0 64 +0 -0 +0 +64 nan nan 0 64 +5 +5 +5 +64 +7 -7 0 64 +inf +inf +inf +64 +7 -7 0 64 nan nan nan +64 +7 -7 0 64 -inf -inf -inf +64 +7 -7 0 64 -8 -8 -8 +64 +7 -7 0 64 +0 -0 -0 +64 nan nan 0 64 +0 -0 +0 +64 nan nan 0 64 +5 +5 +5 +64 nan nan 0 64 +inf +inf +inf +64 +0 -0 0 64 nan nan nan +64 +0 -0 0 64 -inf -inf -inf +64 nan nan 0 64 -8 -8 -8 +64 nan nan 0 64 +0 -0 -0 +64 nan nan 0 64 +0 -0 +0 +64 nan nan 0 64 +5 +5 +5 +64 nan nan 0 64 +inf +inf +inf +64 -1 +1 0 64 nan nan nan +64 -1 +1 0 64 -inf -inf -inf +64 -1 +1 0 64 -8 -8 -8 +64 -1 +1 0 64 +0 -0 -0 +64 nan nan 0 64 +0 -0 +0 +64 nan nan 0 64 +5 +5 +5 +64 nan nan 0 64 +inf +inf +inf +64 +0 +1 0 64 nan nan nan + +# regular values + 64 +0x123456789abcdep-16 +0x1fedcba9876543p-16 +0 64 +0x11111111111111 +0x11111111111111 +0x11111111111111 + 60 +0x123456789abcdeep-57 +0x1fedcba98765432p+33 +3 60 +0x1.111111111111110 +0x1.111111111111112 +0x1.1111111111111111 diff --git a/tests/set_q.dat b/tests/set_q.dat new file mode 100644 index 0000000..c9903f6 --- /dev/null +++ b/tests/set_q.dat @@ -0,0 +1,35 @@ +# data file for mpfi_set_q +# +# column fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: value of argument + +# special values in initial interval +53 nan nan 0 53 -8 -8 -8/1 +53 nan nan 0 53 +0 -0 -0/1 +53 nan nan 0 53 +0 -0 0/1 +53 nan nan 0 53 +5 +5 5/1 +53 -inf -inf 0 53 -8 -8 -8/1 +53 -inf -inf 0 53 +0 -0 -0/1 +53 -inf -inf 0 53 +0 -0 0/1 +53 -inf -inf 0 53 +5 +5 5/1 +53 +0 -0 0 53 -8 -8 -8/1 +53 +0 -0 0 53 +0 -0 -0/1 +53 +0 -0 0 53 +0 -0 0/1 +53 +0 -0 0 53 +5 +5 5/1 +53 +inf +inf 0 53 -8 -8 -8/1 +53 +inf +inf 0 53 +0 -0 -0/1 +53 +inf +inf 0 53 +0 -0 0/1 +53 +inf +inf 0 53 +5 +5 5/1 + +# regular values +53 nan nan 3 53 0x19999999999999@-14 0x1999999999999a@-14 1/10 + 2 nan nan 3 2 0x18@-2 0x2@-1 1/10 diff --git a/tests/set_si.dat b/tests/set_si.dat new file mode 100644 index 0000000..ea9ebbb --- /dev/null +++ b/tests/set_si.dat @@ -0,0 +1,40 @@ +# data file for mpfi_set_si +# +# fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: precision of argument +# 9: value of argument + +# special values +53 nan nan 0 53 -8 -8 -8 +53 nan nan 0 53 +0 -0 -0 +53 nan nan 0 53 +0 -0 +0 +53 nan nan 0 53 +5 +5 +5 +53 -inf -inf 0 53 -8 -8 -8 +53 -inf -inf 0 53 +0 -0 -0 +53 -inf -inf 0 53 +0 -0 +0 +53 -inf -inf 0 53 +5 +5 +5 +53 +0 -0 0 53 -8 -8 -8 +53 +0 -0 0 53 +0 -0 -0 +53 +0 -0 0 53 +0 -0 +0 +53 +0 -0 0 53 +5 +5 +5 +53 +inf +inf 0 53 -8 -8 -8 +53 +inf +inf 0 53 +0 -0 -0 +53 +inf +inf 0 53 +0 -0 +0 +53 +inf +inf 0 53 +5 +5 +5 + +# regular values +53 +10 +20 0 53 +5 +5 +5 +16 +0x123400 0xdada00 3 16 +0x111100 +0x111120 +0x111101 +53 -0x888888 -0x888887 0 53 -0xbaffe0 -0xbaffe0 -0xbaffe0 +16 -0x888800 -0x888700 3 16 -0x888900 -0x888800 -0x888801 +16 -0x888800 +0x1 0 16 -0xfedc00 -0xfedc00 -0xfedc00 +16 -0x888800 +0x1 3 16 +0xfedb00 +0xfedc00 +0xfedb01 diff --git a/tests/set_sj.dat b/tests/set_sj.dat new file mode 100644 index 0000000..6d47b4f --- /dev/null +++ b/tests/set_sj.dat @@ -0,0 +1,41 @@ +# data file for mpfi_set_sj +# same data file as for mpfi_set_si, XXX to be completed +# +# fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: precision of argument +# 9: value of argument + +# special values +53 nan nan 0 53 -8 -8 -8 +53 nan nan 0 53 +0 -0 -0 +53 nan nan 0 53 +0 -0 +0 +53 nan nan 0 53 +5 +5 +5 +53 -inf -inf 0 53 -8 -8 -8 +53 -inf -inf 0 53 +0 -0 -0 +53 -inf -inf 0 53 +0 -0 +0 +53 -inf -inf 0 53 +5 +5 +5 +53 +0 -0 0 53 -8 -8 -8 +53 +0 -0 0 53 +0 -0 -0 +53 +0 -0 0 53 +0 -0 +0 +53 +0 -0 0 53 +5 +5 +5 +53 +inf +inf 0 53 -8 -8 -8 +53 +inf +inf 0 53 +0 -0 -0 +53 +inf +inf 0 53 +0 -0 +0 +53 +inf +inf 0 53 +5 +5 +5 + +# regular values +53 +10 +20 0 53 +5 +5 +5 +16 +0x123400 0xdada00 3 16 +0x111100 +0x111120 +0x111101 +53 -0x888888 -0x888887 0 53 -0xbaffe0 -0xbaffe0 -0xbaffe0 +16 -0x888800 -0x888700 3 16 -0x888900 -0x888800 -0x888801 +16 -0x888800 +0x1 0 16 -0xfedc00 -0xfedc00 -0xfedc00 +16 -0x888800 +0x1 3 16 +0xfedb00 +0xfedc00 +0xfedb01 diff --git a/tests/set_ui.dat b/tests/set_ui.dat new file mode 100644 index 0000000..abb8c87 --- /dev/null +++ b/tests/set_ui.dat @@ -0,0 +1,38 @@ +# data file for mpfi_set_ui +# +# fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: precision of argument +# 9: value of argument + +# special values +53 nan nan 0 53 +0 -0 +0 +53 nan nan 0 53 +5 +5 +5 +53 -inf -inf 0 53 +0 -0 +0 +53 -inf -inf 0 53 +5 +5 +5 +53 +0 -0 0 53 +0 -0 +0 +53 +0 -0 0 53 +5 +5 +5 +53 +inf +inf 0 53 +0 -0 +0 +53 +inf +inf 0 53 +5 +5 +5 + +# regular values +53 +10 +20 0 53 +5 +5 5 +16 +0x123400 0xdada00 3 16 +0x111100 +0x111120 0x111101 +53 +10 +20 0 53 +15 +15 15 +16 +0x123400 0xdada00 0 16 +0xdddd00 +0xdddd00 0xdddd00 +16 +0x123400 0xdada00 3 16 +0xdada00 +0xdadb00 0xdadada + +53 -0x888888 -0x888887 0 53 +0xbaffe0 0xbaffe0 0xbaffe0 +16 -0x888800 -0x888700 3 16 +0x888800 0x888900 0x888801 + +16 -0x888800 +0x1 0 16 +0xfedc00 +0xfedc00 0xfedc00 +16 -0x888800 +0x10 0 16 +0x8 +0x8 0x8 +16 -0x888800 +0x1 3 16 +0x888800 +0x888900 0x888801 diff --git a/tests/set_uj.dat b/tests/set_uj.dat new file mode 100644 index 0000000..1175eb6 --- /dev/null +++ b/tests/set_uj.dat @@ -0,0 +1,39 @@ +# data file for mpfi_set_uj +# same data file as for mpfi_set_ui, XXX to be completed +# +# fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: precision of argument +# 9: value of argument + +# special values +53 nan nan 0 53 +0 -0 +0 +53 nan nan 0 53 +5 +5 +5 +53 -inf -inf 0 53 +0 -0 +0 +53 -inf -inf 0 53 +5 +5 +5 +53 +0 -0 0 53 +0 -0 +0 +53 +0 -0 0 53 +5 +5 +5 +53 +inf +inf 0 53 +0 -0 +0 +53 +inf +inf 0 53 +5 +5 +5 + +# regular values +53 +10 +20 0 53 +5 +5 5 +16 +0x123400 0xdada00 3 16 +0x111100 +0x111120 0x111101 +53 +10 +20 0 53 +15 +15 15 +16 +0x123400 0xdada00 0 16 +0xdddd00 +0xdddd00 0xdddd00 +16 +0x123400 0xdada00 3 16 +0xdada00 +0xdadb00 0xdadada + +53 -0x888888 -0x888887 0 53 +0xbaffe0 0xbaffe0 0xbaffe0 +16 -0x888800 -0x888700 3 16 +0x888800 0x888900 0x888801 + +16 -0x888800 +0x1 0 16 +0xfedc00 +0xfedc00 0xfedc00 +16 -0x888800 +0x10 0 16 +0x8 +0x8 0x8 +16 -0x888800 +0x1 3 16 +0x888800 +0x888900 0x888801 diff --git a/tests/set_z.dat b/tests/set_z.dat new file mode 100644 index 0000000..3ff088c --- /dev/null +++ b/tests/set_z.dat @@ -0,0 +1,35 @@ +# data file for mpfi_set_z +# +# column fields: +# 1: initial precision of interval +# 2: initial left point value of interval +# 3: initial right endpoint value of interval +# +# 4: inexact flag (returned value) +# 5: precision of result (must be the same as in field 1) +# 6: left endpoint value of result +# 7: right endpoint value of result +# +# 8: value of argument + +# special values in initial interval +53 nan nan 0 53 -8 -8 -8 +53 nan nan 0 53 +0 -0 -0 +53 nan nan 0 53 +0 -0 0 +53 nan nan 0 53 +5 +5 5 +53 -inf -inf 0 53 -8 -8 -8 +53 -inf -inf 0 53 +0 -0 -0 +53 -inf -inf 0 53 +0 -0 0 +53 -inf -inf 0 53 +5 +5 5 +53 +0 -0 0 53 -8 -8 -8 +53 +0 -0 0 53 +0 -0 -0 +53 +0 -0 0 53 +0 -0 0 +53 +0 -0 0 53 +5 +5 5 +53 +inf +inf 0 53 -8 -8 -8 +53 +inf +inf 0 53 +0 -0 -0 +53 +inf +inf 0 53 +0 -0 0 +53 +inf +inf 0 53 +5 +5 5 + +# regular values +53 nan nan 3 53 0x15555555555555p+3 0x15555555555556p+3 0xaaaaaaaaaaaaaa + 2 nan nan 3 2 0x18 0x20 0x19 diff --git a/tests/si_div.dat b/tests/si_div.dat new file mode 100644 index 0000000..6370798 --- /dev/null +++ b/tests/si_div.dat @@ -0,0 +1,112 @@ +# data file for mpfi_si_div +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: first parameter value +# 6: precision of second parameter +# 7: left endpoint value of second parameter +# 8: right endpoint value of second parameter + +# special values +0 53 nan nan -1 53 nan nan +0 53 nan nan 0 53 nan nan +0 53 nan nan 1 53 nan nan +0 53 nan nan -3 53 nan -inf +0 53 nan nan 0 53 nan -inf +0 53 nan nan 3 53 nan -inf +0 53 nan nan -7 53 nan -7 +0 53 nan nan 0 53 nan -7 +0 53 nan nan 7 53 nan -7 +0 53 nan nan -1 53 nan -0 +0 53 nan nan 0 53 nan -0 +0 53 nan nan 1 53 nan -0 +0 53 nan nan -3 53 nan 1 +0 53 nan nan 0 53 nan 1 +0 53 nan nan 3 53 nan 1 +0 53 nan nan -6 53 nan +inf +0 53 nan nan 0 53 nan +inf +0 53 nan nan 6 53 nan +inf +0 53 +0 -0 -2 53 -inf -inf +0 53 +0 -0 0 53 -inf -inf +0 53 +0 -0 2 53 -inf -inf +0 53 +0 4 -4 53 -inf -1 +0 53 +0 -0 0 53 -inf -1 +0 53 -4 -0 4 53 -inf -1 + +2 53 +0 0x12492492492493p-53 + -4 + 53 -inf -7 +1 53 -0x12492492492493p-53 -0 + 4 + 53 -inf -7 + +0 53 +0 +inf -8 53 -inf -0 +0 53 +0 -0 0 53 -inf -0 +0 53 -inf -0 8 53 -inf -0 +0 53 -inf +inf -1 53 -inf +8 +0 53 -inf +inf 0 53 -inf +8 +0 53 -inf +inf 1 53 -inf +8 +0 53 -inf +inf -3 53 -inf +inf +0 53 -inf +inf 0 53 -inf +inf +0 53 -inf +inf 3 53 -inf +inf +0 53 nan nan -6 53 -inf nan +0 53 nan nan 0 53 -inf nan +0 53 nan nan 6 53 -inf nan +0 53 -inf +inf -1 53 +0 -0 +0 53 +0 -0 0 53 +0 -0 +0 53 -inf +inf 1 53 +0 -0 +0 53 -inf -0.5 -4 53 +0 +8 +0 53 +0 -0 0 53 +0 +8 +0 53 0.5 +inf 4 53 +0 +8 + +2 53 -inf -0x12492492492492p-53 + -4 + 53 +0 7 +1 53 0x12492492492492p-53 +inf + 4 + 53 +0 7 + +0 53 -inf -0 -7 53 +0 +inf +0 53 +0 -0 0 53 +0 +inf +0 53 +0 +inf 7 53 +0 +inf +0 53 +0 -0 -1 53 +inf +inf +0 53 +0 -0 0 53 +inf +inf +0 53 +0 -0 1 53 +inf +inf +0 53 nan nan -1 53 +inf nan +0 53 nan nan 0 53 +inf nan +0 53 nan nan 1 53 +inf nan + +# regular values +0 53 -inf +inf + -32 + 53 -32 17 + +0 53 2 5 + 30 + 53 6 15 +1 53 0x11249249249249p-51 5 + 30 + 53 6 14 +2 53 2 0x1124924924924ap-50 + 30 + 53 7 15 +3 53 0x10888888888888p-51 0x14aaaaaaaaaaabp-50 + 31 + 53 6 15 + +0 53 -5 -2 + -30 + 53 6 15 +1 53 -0x1124924924924ap-50 -2 + 30 + 53 -15 -7 +2 53 -5 -0x11249249249249p-51 + -30 + 53 6 14 +3 53 -0x14aaaaaaaaaaabp-50 -0x10888888888888p-51 + 31 + 53 -15 -6 diff --git a/tests/si_sub.dat b/tests/si_sub.dat new file mode 100644 index 0000000..cba94fb --- /dev/null +++ b/tests/si_sub.dat @@ -0,0 +1,101 @@ +# data file for mpfi_si_sub +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: first parameter value +# 6: precision of second parameter +# 7: left endpoint value of second parameter +# 8: right endpoint value of second parameter + +# special values +0 53 nan nan -1 53 nan nan +0 53 nan nan 0 53 nan nan +0 53 nan nan 1 53 nan nan +0 53 +inf nan -3 53 nan -inf +0 53 +inf nan 0 53 nan -inf +0 53 +inf nan 3 53 nan -inf +0 53 +0 nan -7 53 nan -7 +0 53 7 nan 0 53 nan -7 +0 53 14 nan 7 53 nan -7 +0 53 -15 nan -15 53 nan -0 +0 53 +0 nan 0 53 nan -0 +0 53 15 nan 15 53 nan -0 +0 53 -32 nan -31 53 nan 1 +0 53 -1 nan 0 53 nan 1 +0 53 30 nan 31 53 nan 1 +0 53 -inf nan -63 53 nan +inf +0 53 -inf nan 0 53 nan +inf +0 53 -inf nan 63 53 nan +inf +0 53 +inf +inf -2 53 -inf -inf +0 53 +inf +inf 0 53 -inf -inf +0 53 +inf +inf +2 53 -inf -inf +0 53 3 +inf -4 53 -inf -7 +0 53 7 +inf 0 53 -inf -7 +0 53 11 +inf 4 53 -inf -7 + +1 53 0x1p+70 +inf + 1 + 53 -inf -0x1p+70 + +0 53 -8 +inf -8 53 -inf -0 +0 53 +0 +inf 0 53 -inf -0 +0 53 8 +inf 8 53 -inf -0 +0 53 -24 +inf -16 53 -inf 8 +0 53 -8 +inf 0 53 -inf 8 +0 53 8 +inf 16 53 -inf 8 +0 53 -inf +inf -32 53 -inf +inf +0 53 -inf +inf 0 53 -inf +inf +0 53 -inf +inf +32 53 -inf +inf +0 53 nan +inf -64 53 -inf nan +0 53 nan +inf 0 53 -inf nan +0 53 nan +inf +64 53 -inf nan +0 53 -1 -1 -1 53 +0 -0 +0 53 +0 -0 0 53 +0 -0 +0 53 1 1 1 53 +0 -0 +0 53 -11 -3 -3 53 +0 8 +0 53 -8 -0 0 53 +0 8 +0 53 -5 3 3 53 +0 8 +0 53 -inf -7 -7 53 +0 +inf +0 53 -inf -0 0 53 +0 +inf +0 53 -inf 7 7 53 +0 +inf +0 53 -inf -inf -1 53 +inf +inf +0 53 -inf -inf 0 53 +inf +inf +0 53 -inf -inf 1 53 +inf +inf +0 53 nan -inf -1 53 +inf nan +0 53 nan -inf 0 53 +inf nan +0 53 nan -inf 1 53 +inf nan + +# regular values +0 53 -64 -49 -32 53 17 32 +0 53 +0 +15 32 53 17 32 +0 53 -15 -0 17 53 17 32 + +0 53 0x153456789abcdfp-48 0x123456789abce2 + 3 + 53 -0x123456789abcdf -0x123456789abcdfp-48 +1 53 0x3123456789abcdp-52 0x123456789abce2 + 3 + 53 -0x123456789abcdf -0x123456789abcdfp-56 +2 53 1 0x10123456789abdp-44 + 256 + 53 -0x123456789abcdfp-52 0xff +3 53 0xfff 0x1001 + 0x1001 + 53 0x1p-550 0x1fffffffffffffp-52 + +0 53 0xf3456789abcdfp-48 0x123456789abcdc + -3 + 53 -0x123456789abcdf -0x123456789abcdfp-48 +1 53 -0x2edcba98765433p-52 0x123456789abcdc + -3 + 53 -0x123456789abcdf -0x123456789abcdfp-56 +2 53 -0x1ff -0xfedcba9876543p-44 + -256 + 53 -0x123456789abcdfp-52 0xff +3 53 -0x1003 -0x1001 + -0x1001 + 53 0x1p-550 0x1fffffffffffffp-52 diff --git a/tests/sin.dat b/tests/sin.dat new file mode 100644 index 0000000..171a9c1 --- /dev/null +++ b/tests/sin.dat @@ -0,0 +1,168 @@ +# data file for mpfi_sin +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 -inf nan +0 53 nan nan 53 -inf -inf +0 53 -1 1 53 -inf -7 +0 53 -1 1 53 -inf -0 +0 53 -1 1 53 -inf +8 +0 53 -1 1 53 -inf +inf +1 53 -0x1aed548f090cefp-53 -0 53 -1 -0 +0 53 +0 -0 53 +0 -0 +2 53 +0 0x1aed548f090cefp-53 53 +0 +1 +0 53 -1 1 53 +0 +8 +0 53 -1 1 53 +0 +inf +0 53 nan nan 53 +inf +inf + +# regular values +0 53 -1 1 53 0.125 17 +1 53 0x1fffffffffffffp-53 1 + 53 0x1921fb54442d18p-52 0x1921fb54442d19p-52 +2 53 -1 -0x1eaee8744b05efp-54 53 -2 -0.5 +2 53 -1 0x1f47ed3dc74081p-53 53 -4.5 0.625 +3 53 -0x1aed548f090cefp-53 -0x1faaeed4f31576p-55 53 -1 -0.25 +3 53 -0x1eaee8744b05f0p-54 0x1eaee8744b05f0p-54 53 -0.5 0.5 +3 53 0x1bde6c11cbfc46p-55 0x1bde6c11cbfc47p-55 + 53 0x71p+76 0x71p+76 + +0 53 -1 1 53 -7 7 +0 53 -1 1 53 -7 6 +0 53 -1 1 53 -7 5 +0 53 -1 1 53 -7 4 +0 53 -1 1 53 -7 3 +0 53 -1 1 53 -7 2 +0 53 -1 1 53 -7 1 +0 53 -1 1 53 -7 -0 +0 53 -1 1 53 -7 -1 +1 53 -0x1d18f6ead1b446p-53 1 53 -7 -2 +1 53 -0x150608c26d0a09p-53 1 53 -7 -3 +1 53 -0x150608c26d0a09p-53 1 53 -7 -4 +3 53 -0x150608c26d0a09p-53 0x1eaf81f5e09934p-53 53 -7 -5 +3 53 -0x150608c26d0a09p-53 0x11e1f18ab0a2c1p-54 53 -7 -6 +3 53 -0x150608c26d0a09p-53 -0x150608c26d0a08p-53 53 -7 -7 + +0 53 -1 1 53 -6 7 +0 53 -1 1 53 -6 6 +0 53 -1 1 53 -6 5 +0 53 -1 1 53 -6 4 +0 53 -1 1 53 -6 3 +0 53 -1 1 53 -6 2 +0 53 -1 1 53 -6 1 +0 53 -1 1 53 -6 -0 +0 53 -1 1 53 -6 -1 +1 53 -0x1d18f6ead1b446p-53 1 53 -6 -2 +1 53 -0x1210386db6d55cp-55 1 53 -6 -3 +1 53 0x11e1f18ab0a2c0p-54 1 53 -6 -4 +3 53 0x11e1f18ab0a2c0p-54 0x1eaf81f5e09934p-53 53 -6 -5 +3 53 0x11e1f18ab0a2c0p-54 0x11e1f18ab0a2c1p-54 53 -6 -6 + +0 53 -1 1 53 -5 7 +0 53 -1 1 53 -5 6 +0 53 -1 1 53 -5 5 +0 53 -1 1 53 -5 4 +0 53 -1 1 53 -5 3 +0 53 -1 1 53 -5 2 +0 53 -1 1 53 -5 1 +0 53 -1 1 53 -5 -0 +0 53 -1 1 53 -5 -1 +1 53 -0x1d18f6ead1b446p-53 1 53 -5 -2 +1 53 -0x1210386db6d55cp-55 1 53 -5 -3 +1 53 0x1837b9dddc1eaep-53 1 53 -5 -4 +3 53 0x1eaf81f5e09933p-53 0x1eaf81f5e09934p-53 53 -5 -5 + +0 53 -1 1 53 -4 7 +0 53 -1 1 53 -4 6 +0 53 -1 1 53 -4 5 +0 53 -1 1 53 -4 4 +0 53 -1 1 53 -4 3 +0 53 -1 1 53 -4 2 +2 53 -1 0x1aed548f090cefp-53 53 -4 1 +2 53 -1 0x1837b9dddc1eafp-53 53 -4 -0 +2 53 -1 0x1837b9dddc1eafp-53 53 -4 -1 +3 53 -0x1d18f6ead1b446p-53 0x1837b9dddc1eafp-53 53 -4 -2 +3 53 -0x1210386db6d55cp-55 0x1837b9dddc1eafp-53 53 -4 -3 +3 53 0x1837b9dddc1eaep-53 0x1837b9dddc1eafp-53 53 -4 -4 + +0 53 -1 1 53 -3 7 +0 53 -1 1 53 -3 6 +0 53 -1 1 53 -3 5 +0 53 -1 1 53 -3 4 +0 53 -1 1 53 -3 3 +0 53 -1 1 53 -3 2 +2 53 -1 0x1aed548f090cefp-53 53 -3 1 +0 53 -1 -0 53 -3 -0 +2 53 -1 -0x1210386db6d55bp-55 53 -3 -1 +3 53 -0x1d18f6ead1b446p-53 -0x1210386db6d55bp-55 53 -3 -2 +3 53 -0x1210386db6d55cp-55 -0x1210386db6d55bp-55 53 -3 -3 + +0 53 -1 1 53 -2 7 +0 53 -1 1 53 -2 6 +0 53 -1 1 53 -2 5 +0 53 -1 1 53 -2 4 +0 53 -1 1 53 -2 3 +0 53 -1 1 53 -2 2 +2 53 -1 0x1aed548f090cefp-53 53 -2 1 +0 53 -1 -0 53 -2 -0 +2 53 -1 -0x1aed548f090ceep-53 53 -2 -1 +3 53 -0x1d18f6ead1b446p-53 -0x1d18f6ead1b445p-53 53 -2 -2 + +0 53 -1 1 53 -1 7 +0 53 -1 1 53 -1 6 +0 53 -1 1 53 -1 5 +1 53 -0x1aed548f090cefp-53 1 53 -1 4 +1 53 -0x1aed548f090cefp-53 1 53 -1 3 +1 53 -0x1aed548f090cefp-53 1 53 -1 2 +3 53 -0x1aed548f090cefp-53 0x1aed548f090cefp-53 53 -1 1 +1 53 -0x1aed548f090cefp-53 -0 53 -1 -0 +3 53 -0x1aed548f090cefp-53 -0x1aed548f090ceep-53 53 -1 -1 + +0 53 -1 1 53 1 7 +0 53 -1 1 53 1 6 +0 53 -1 1 53 1 5 +1 53 -0x1837b9dddc1eafp-53 1 53 1 4 +1 53 0x1210386db6d55bp-55 1 53 1 3 +1 53 0x1aed548f090ceep-53 1 53 1 2 +3 53 0x1aed548f090ceep-53 0x1aed548f090cefp-53 53 1 1 + +2 53 -1 0x1d18f6ead1b446p-53 53 2 7 +2 53 -1 0x1d18f6ead1b446p-53 53 2 6 +2 53 -1 0x1d18f6ead1b446p-53 53 2 5 +3 53 -0x1837b9dddc1eafp-53 0x1d18f6ead1b446p-53 53 2 4 +3 53 0x1210386db6d55bp-55 0x1d18f6ead1b446p-53 53 2 3 +3 53 0x1d18f6ead1b445p-53 0x1d18f6ead1b446p-53 53 2 2 + +2 53 -1 0x150608c26d0a09p-53 53 3 7 +2 53 -1 0x1210386db6d55cp-55 53 3 6 +2 53 -1 0x1210386db6d55cp-55 53 3 5 +3 53 -0x1837b9dddc1eafp-53 0x1210386db6d55cp-55 53 3 4 +3 53 0x1210386db6d55bp-55 0x1210386db6d55cp-55 53 3 3 + +2 53 -1 0x150608c26d0a09p-53 53 4 7 +2 53 -1 -0x11e1f18ab0a2c0p-54 53 4 6 +2 53 -1 -0x1837b9dddc1eaep-53 53 4 5 +3 53 -0x1837b9dddc1eafp-53 -0x1837b9dddc1eaep-53 53 4 4 + +3 53 -0x1eaf81f5e09934p-53 0x150608c26d0a09p-53 53 5 7 +3 53 -0x1eaf81f5e09934p-53 -0x11e1f18ab0a2c0p-54 53 5 6 +3 53 -0x1eaf81f5e09934p-53 -0x1eaf81f5e09933p-53 53 5 5 + +3 53 -0x11e1f18ab0a2c1p-54 0x150608c26d0a09p-53 53 6 7 +3 53 -0x11e1f18ab0a2c1p-54 -0x11e1f18ab0a2c0p-54 53 6 6 + +3 53 0x150608c26d0a08p-53 0x150608c26d0a09p-53 53 7 7 + diff --git a/tests/sinh.dat b/tests/sinh.dat new file mode 100644 index 0000000..c5aaae3 --- /dev/null +++ b/tests/sinh.dat @@ -0,0 +1,36 @@ +# data file for mpfi_sinh +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan -inf 53 nan -inf +0 53 -0x1122876ba380cap-43 nan 53 -7 nan +0 53 nan -0 53 nan -0 +0 53 +0 nan 53 +0 nan +0 53 -inf nan 53 -inf nan +0 53 -inf -inf 53 -inf -inf +2 53 -inf -0x1122876ba380c9p-43 53 -inf -7 +0 53 -inf -0 53 -inf -0 +2 53 -inf 0x1749ea514eca66p-42 53 -inf +8 +0 53 -inf +inf 53 -inf +inf +1 53 -0x12cd9fc44eb983p-52 -0 53 -1 -0 +0 53 +0 -0 53 +0 -0 +2 53 +0 0x12cd9fc44eb983p-52 53 +0 +1 +2 53 +0 0x1749ea514eca66p-42 53 +0 +8 +0 53 +0 +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +1 53 -0x100aaccd00d2f1p-55 -0 53 -0.125 -0 +2 53 +0 0x10acd00fe63b98p-53 53 0 0x10000000000001p-53 +3 53 -0x168062ab5fa9fdp-47 -0x1553e795dc19ccp-53 53 -4.5 -0.625 +3 53 0x12cd9fc44eb982p-52 0x140926e70949aep-49 53 1 3 diff --git a/tests/sqr.dat b/tests/sqr.dat new file mode 100644 index 0000000..89eb6ca --- /dev/null +++ b/tests/sqr.dat @@ -0,0 +1,31 @@ +# data file for mpfi_sqr +# +# column fields: see neg.dat + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 nan +1 +0 53 nan nan 53 +inf nan +0 53 +inf +inf 53 -inf -inf +0 53 +49 +inf 53 -inf -7 +0 53 +0 +inf 53 -inf -0 +0 53 +0 +inf 53 -inf +8 +0 53 +0 +inf 53 -inf +inf +0 53 +0 -0 53 +0 -0 +0 53 +0 +64 53 +0 +8 +0 53 +0 +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +0 53 0x4.65df11464764p-4 0xf.8f918d688891p+16 + 53 0x8.6374d8p-4 0x3.f1d929p+8 +1 53 0x2.8b45c3cc03ea6p+12 0x14b66cb0ce4 + 53 0x6.61485c33c0b14p+4 0x123456 +2 53 +0 0x1.f04dba0302d4dp+0 + 53 -0x1.64722ad2480c9p+0 0x1 +3 53 0x2.02ce7912cddf6p+0 0x7.3a5dee779527p+0 + 53 0x1.6b079248747a2p+0 0x2.b041176d263f6p+0 diff --git a/tests/sqrt.dat b/tests/sqrt.dat new file mode 100644 index 0000000..a6f7246 --- /dev/null +++ b/tests/sqrt.dat @@ -0,0 +1,32 @@ +# data file for mpfi_sqrt +# +# column fields: see neg.dat + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan -0 53 nan -0 +0 53 +0 nan 53 +0 nan +0 53 nan +1 53 nan +1 +0 53 +inf nan 53 +inf nan +0 53 nan nan 53 -inf -inf +0 53 nan nan 53 -inf -7 +0 53 nan -0 53 -inf -0 +0 53 nan -0 53 -inf -0 +0 53 nan +3 53 -inf +9 +0 53 nan +inf 53 -inf +inf +0 53 +0 -0 53 +0 -0 +0 53 +0 +3 53 +0 +9 +0 53 +0 +inf 53 +0 +inf +0 53 +inf +inf 53 +inf +inf + +# regular values +0 53 0xd1 0x123456 + 53 0xaaa1 0x14b66cb0ce4 +1 53 0xf.1ea42821b27a8p-4 0xd1 + 53 0xe.49ae7969e41bp-4 0xaaa1 +2 53 0xd.1p-4 0x1.06081714eef1dp+0 + 53 0xa.aa1p-4 0x1.0c348f804c7a9p+0 +3 53 0xf.1ea42821b27a8p-4 0x1.06081714eef1dp+0 + 53 0xe.49ae7969e41bp-4 0x1.0c348f804c7a9p+0 diff --git a/tests/sub.dat b/tests/sub.dat new file mode 100644 index 0000000..1d5a646 --- /dev/null +++ b/tests/sub.dat @@ -0,0 +1,62 @@ +# data file for mpfi_sub +# +# column fields: see add.dat + +# special values +0 53 nan nan 53 nan nan 53 -inf -7 +0 53 nan nan 53 nan nan 53 -8 +1 +0 53 nan nan 53 nan nan 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 nan +0 53 nan nan 53 nan nan 53 +5 +inf +0 53 nan nan 53 nan nan 53 +inf +inf +0 53 nan nan 53 nan nan 53 nan -0 +0 53 nan +inf 53 nan -0 53 -inf -7 +0 53 nan +8 53 nan -0 53 -8 +1 +0 53 nan +inf 53 nan +inf 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 +7 +0 53 nan -inf 53 nan -inf 53 +5 +inf +0 53 nan -inf 53 nan -7 53 +inf +inf +0 53 nan nan 53 nan +1 53 nan -0 +0 53 nan nan 53 -inf -inf 53 -inf -inf +0 53 -inf -6 53 -inf -7 53 -1 +8 +0 53 -inf -8 53 -inf -0 53 +8 +inf +0 53 -inf -inf 53 -inf -0 53 +inf +inf +0 53 -inf +8 53 -inf +8 53 +0 +8 +0 53 -inf +inf 53 -inf +inf 53 +0 +8 +0 53 +7 +inf 53 +0 -0 53 -inf -7 +0 53 +0 +15 53 +0 +8 53 -7 -0 +0 53 -8 -0 53 +0 -0 53 +0 +8 +0 53 -8 +inf 53 +0 +inf 53 +0 +8 +0 53 -inf -8 53 +0 -0 53 +8 +inf +0 53 nan -inf 53 +0 +8 53 +inf nan +0 53 -inf +inf 53 +0 -0 53 -inf +inf +0 53 -8 +15 53 +0 +8 53 -7 +8 +0 53 +0 -0 53 +0 -0 53 +0 -0 +0 53 -8 +inf 53 +0 +inf 53 +0 +8 +0 53 -inf nan 53 +0 nan 53 +8 +inf +0 53 -inf -inf 53 +0 +8 53 +inf +inf +0 53 +inf +inf 53 +inf +inf 53 -inf +3 +0 53 nan +inf 53 +inf +inf 53 +0 +inf +0 53 nan +inf 53 +inf +inf 53 +3 nan +0 53 +inf nan 53 +inf nan 53 -inf -7 +0 53 nan nan 53 +inf nan 53 +inf +inf +0 53 +inf nan 53 +inf nan 53 -3 +7 + +# regular values +0 53 -86 42 53 -5 59 53 17 81 +1 53 -0x10000000000001p-93 0x123456789abcd + 53 -0x1p-300 0x123456p+28 + 53 -0x789abcd 0x10000000000000p-93 +2 53 -0x123456791abcdp-17 0x8f596b3002c1bp+947 + 53 -4 7 + 53 -3e300 0x123456789abcdp-17 +3 53 -0x10101010101011p+4 0x8f596b3002c1bp+947 + 53 -0x1000100010001p+8 0x1p+60 + 53 -3e300 0x1000100010001 + +1 53 -0x10000000000001p+18 -0 + 53 -5 1 + 53 1 0x1p+70 +2 53 +0 0x1p+70 + 53 5 0x1p+70 + 53 3 5 diff --git a/tests/sub_d.dat b/tests/sub_d.dat new file mode 100644 index 0000000..d7d7150 --- /dev/null +++ b/tests/sub_d.dat @@ -0,0 +1,108 @@ +# data file for mpfi_sub_d +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +#WARNING: +# double values are read by the test suite with rounding towards minus +# infinity to a machine-dependant precision (whereas the mpfi data are read +# at the given precision with rounding to the nearest). +# So as to ensure portability, use test values that are representable with a +# 53 bit-significand which corresponds to the minimum default precision for +# a double in the test suite. + +# special values +0 53 nan nan 53 nan nan -0x170ef54646d497p-109 +0 53 nan nan 53 nan nan 0.0 +0 53 nan nan 53 nan nan 0x170ef54646d497p-109 +0 53 nan -inf 53 nan -inf -0x114b37f4b51f71p-107 +0 53 nan -inf 53 nan -inf 0.0 +0 53 nan -inf 53 nan -inf 0x114b37f4b51f71p-107 +0 53 nan -0x1bfffffffffff8p-50 53 nan -7 -0xfc339ab0a6b53p-99 +0 53 nan -7 53 nan -7 0.0 +0 53 nan -0x1c000000000007p-50 53 nan -7 0xfc339ab0a6b53p-99 +0 53 nan 15 53 nan -0 -15.0 +0 53 nan -0 53 nan -0 0.0 +0 53 nan -15 53 nan -0 15.0 +0 53 nan 0x8000000000001p-51 53 nan +1 -0xb2b3ece0a4ef9p-103 +0 53 nan 1 53 nan +1 0.0 +0 53 nan 0xfffffffffffffp-52 53 nan +1 0xb2b3ece0a4ef9p-103 +0 53 nan +inf 53 nan +inf -0x5acae5c4b6e51p-101 +0 53 nan +inf 53 nan +inf 0.0 +0 53 nan +inf 53 nan +inf 0x5acae5c4b6e51p-101 +0 53 -inf -inf 53 -inf -inf -0x170ef54646d497p-108 +0 53 -inf -inf 53 -inf -inf 0.0 +0 53 -inf -inf 53 -inf -inf 0x170ef54646d497p-108 +2 53 -inf -0x1bffffffffffffp-50 53 -inf -7 -0x170ef54646d497p-107 +0 53 -inf -7 53 -inf -7 0.0 +2 53 -inf -7 53 -inf -7 0x170ef54646d497p-107 +0 53 -inf 0x170ef54646d497p-106 53 -inf -0 -0x170ef54646d497p-106 +0 53 -inf -0 53 -inf -0 0.0 +0 53 -inf -8.0e-17 53 -inf -0 0x170ef54646d497p-106 +2 53 -inf 0x16345785d8a00100 53 -inf 8 -0x16345785d8a00000 +0 53 -inf 8 53 -inf 8 0.0 +2 53 -inf -0x16345785d89fff00 53 -inf 8 0x16345785d8a00000 +0 53 -inf +inf 53 -inf +inf -0x170ef54646d497p-105 +0 53 -inf +inf 53 -inf +inf 0.0e-17 +0 53 -inf +inf 53 -inf +inf +0x170ef54646d497p-105 +0 53 -inf nan 53 -inf nan -0x170ef54646d497p-104 +0 53 -inf nan 53 -inf nan 0.0e-17 +0 53 -inf nan 53 -inf nan +0x170ef54646d497p-104 +0 53 +0x170ef54646d497p-109 +0x170ef54646d497p-109 + 53 +0 -0 -0x170ef54646d497p-109 +0 53 +0 -0 + 53 +0 -0 0.0 +0 53 -0x170ef54646d497p-109 -0x170ef54646d497p-109 + 53 +0 -0 0x170ef54646d497p-109 +2 53 0x114b37f4b51f71p-107 0x10000000000001p-49 + 53 +0 8 -0x114b37f4b51f71p-107 +0 53 +0 8 + 53 +0 8 0.0 +2 53 -0x114b37f4b51f71p-107 8 + 53 +0 8 0x114b37f4b51f71p-107 +0 53 0x50b45a75f7e81p-104 +inf + 53 +0 +inf -0x50b45a75f7e81p-104 +0 53 +0 +inf + 53 +0 +inf 0.0 +0 53 -0x142d169d7dfa03p-106 +inf + 53 +0 +inf 0x142d169d7dfa03p-106 +0 53 +inf +inf 53 +inf +inf -0x170ef54646d497p-109 +0 53 +inf +inf 53 +inf +inf 0.0 +0 53 +inf +inf 53 +inf +inf 0x170ef54646d497p-109 +0 53 +inf nan 53 +inf nan -0x170ef54646d497p-109 +0 53 +inf nan 53 +inf nan 0.0 +0 53 +inf nan 53 +inf nan 0x170ef54646d497p-109 + +# regular values +0 53 -0x1fb53d14aa9c2fp-47 -0x18353d14aa9c2fp-47 + 53 -32 -17 0xfb53d14aa9c2fp-47 +0 53 +0 0x7353d14aa9c2fp-47 + 53 -0xfb53d14aa9c2fp-47 -17 -0xfb53d14aa9c2fp-47 +0 53 -0x104ac2eb5563d1p-48 -0 + 53 -32 -0xfb53d14aa9c2fp-48 -0xfb53d14aa9c2fp-48 + +0 53 0x15b456789abcdfp-48 0x123456789abd17p-4 + 53 0x123456789abcdfp-48 0x123456789abcdfp-4 -3.5 +1 53 0x3923456789abcdp-52 0x123456789abd17p-4 + 53 0x123456789abcdfp-56 0x123456789abcdfp-4 -3.5 +2 53 0x18p-4 0x101a3456789abdp-44 + 53 -0xff 0x123456789abcdfp-52 -256.5 +3 53 0xfff8p-4 0x10018p-4 + 53 -0x1fffffffffffffp-52 -0x1p-550 -4097.5 + +0 53 0xeb456789abcdfp-48 0x123456789abca7p-4 + 53 0x123456789abcdfp-48 0x123456789abcdfp-4 3.5 +1 53 -0x36dcba98765434p-52 0x123456789abca7p-4 + 53 0x123456789abcdfp-56 0x123456789abcdfp-4 3.5 +2 53 -0x1ff8p-4 -0xff5cba9876543p-44 + 53 -0xff 0x123456789abcdfp-52 256.5 +3 53 -0x10038p-4 -0x10018p-4 + 53 -0x1fffffffffffffp-52 -0x1p-550 4097.5 diff --git a/tests/sub_fr.dat b/tests/sub_fr.dat new file mode 100644 index 0000000..7d7647a --- /dev/null +++ b/tests/sub_fr.dat @@ -0,0 +1,125 @@ +# data file for mpfi_sub_fr +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan 53 -0x170ef54646d497p-109 +0 53 nan nan 53 nan nan 53 +0 +0 53 nan nan 53 nan nan 53 0x170ef54646d497p-109 +0 53 nan -inf 53 nan -inf 53 -0x114b37f4b51f71p-107 +0 53 nan -inf 53 nan -inf 53 -0 +0 53 nan -inf 53 nan -inf 53 0x114b37f4b51f71p-107 +0 53 nan -0x1bfffffffffff8p-50 53 nan -7 53 -0xfc339ab0a6b53p-99 +0 53 nan -7 53 nan -7 53 +0 +0 53 nan -0x1c000000000007p-50 53 nan -7 53 0xfc339ab0a6b53p-99 +0 53 nan 15 53 nan -0 53 -15 +0 53 nan -0 53 nan -0 53 -0 +0 53 nan -15 53 nan -0 53 15 +0 53 nan 0x8000000000001p-51 53 nan +1 53 -0xb2b3ece0a4ef9p-103 +0 53 nan 1 53 nan +1 53 +0 +0 53 nan 0xfffffffffffffp-52 53 nan +1 53 0xb2b3ece0a4ef9p-103 +0 53 nan +inf 53 nan +inf 53 -0x5acae5c4b6e51p-101 +0 53 nan +inf 53 nan +inf 53 -0 +0 53 nan +inf 53 nan +inf 53 0x5acae5c4b6e51p-101 +0 53 -inf -inf 53 -inf -inf 53 -0x170ef54646d497p-108 +0 53 -inf -inf 53 -inf -inf 53 +0 +0 53 -inf -inf 53 -inf -inf 53 0x170ef54646d497p-108 +2 53 -inf -0x1bffffffffffffp-50 53 -inf -7 53 -0x170ef54646d497p-107 +0 53 -inf -7 53 -inf -7 53 -0 +2 53 -inf -7 53 -inf -7 53 0x170ef54646d497p-107 +0 53 -inf 0x170ef54646d497p-106 53 -inf -0 53 -0x170ef54646d497p-106 +0 53 -inf -0 53 -inf -0 53 +0 +0 53 -inf -8e-17 53 -inf -0 53 0x170ef54646d497p-106 +2 53 -inf 0x16345785d8a00100 53 -inf 8 53 -0x16345785d8a00000 +0 53 -inf 8 53 -inf 8 53 -0 +2 53 -inf -0x16345785d89fff00 53 -inf 8 53 0x16345785d8a00000 +0 53 -inf +inf 53 -inf +inf 53 -0x170ef54646d497p-105 +0 53 -inf +inf 53 -inf +inf 53 +0e-17 +0 53 -inf +inf 53 -inf +inf 53 0x170ef54646d497p-105 +0 53 -inf nan 53 -inf nan 53 -0x170ef54646d497p-104 +0 53 -inf nan 53 -inf nan 53 -0e-17 +0 53 -inf nan 53 -inf nan 53 0x170ef54646d497p-104 +0 53 +0x170ef54646d497p-109 +0x170ef54646d497p-109 + 53 +0 -0 + 53 -0x170ef54646d497p-109 +0 53 +0 -0 + 53 +0 -0 + 53 +0 +0 53 -0x170ef54646d497p-109 -0x170ef54646d497p-109 + 53 +0 -0 + 53 0x170ef54646d497p-109 +2 53 0x114b37f4b51f71p-107 0x10000000000001p-49 + 53 +0 8 + 53 -0x114b37f4b51f71p-107 +0 53 +0 8 + 53 +0 8 + 53 -0 +2 53 -0x114b37f4b51f71p-107 8 + 53 +0 8 + 53 0x114b37f4b51f71p-107 +0 53 0x50b45a75f7e81p-104 +inf + 53 +0 +inf + 53 -0x50b45a75f7e81p-104 +0 53 +0 +inf + 53 +0 +inf + 53 -0 +0 53 -0x142d169d7dfa03p-106 +inf + 53 +0 +inf + 53 0x142d169d7dfa03p-106 +0 53 +inf +inf 53 +inf +inf 53 -0x170ef54646d497p-109 +0 53 +inf +inf 53 +inf +inf 53 0 +0 53 +inf +inf 53 +inf +inf 53 0x170ef54646d497p-109 +0 53 +inf nan 53 +inf nan 53 -0x170ef54646d497p-109 +0 53 +inf nan 53 +inf nan 53 0 +0 53 +inf nan 53 +inf nan 53 0x170ef54646d497p-109 + +# bug20111222 +3 53 -0x170ef54646d498p-109 -0x170ef54646d497p-109 + 53 +0 -0 + 54 0x170ef54646d4978p-113 + +# regular values +0 53 -0x1fb53d14aa9c2fp-47 -0x18353d14aa9c2fp-47 + 53 -32 -17 + 53 0xfb53d14aa9c2fp-47 +0 53 +0 0x7353d14aa9c2fp-47 + 53 -0xfb53d14aa9c2fp-47 -17 + 53 -0xfb53d14aa9c2fp-47 +0 53 -0x104ac2eb5563d1p-48 -0 + 53 -32 -0xfb53d14aa9c2fp-48 + 53 -0xfb53d14aa9c2fp-48 + +0 53 0x15b456789abcdfp-48 0x123456789abd17p-4 + 53 0x123456789abcdfp-48 0x123456789abcdfp-4 + 53 -3.5 +1 53 0x3923456789abcdp-52 0x123456789abd17p-4 + 53 0x123456789abcdfp-56 0x123456789abcdfp-4 + 53 -3.5 +2 53 0x18p-4 0x101a3456789abdp-44 + 53 -0xff 0x123456789abcdfp-52 + 53 -256.5 +3 53 0xfff8p-4 0x10018p-4 + 53 -0x1fffffffffffffp-52 -0x1p-550 + 53 -4097.5 + +0 53 0xeb456789abcdfp-48 0x123456789abca7p-4 + 53 0x123456789abcdfp-48 0x123456789abcdfp-4 + 53 3.5 +1 53 -0x36dcba98765434p-52 0x123456789abca7p-4 + 53 0x123456789abcdfp-56 0x123456789abcdfp-4 + 53 3.5 +2 53 -0x1ff8p-4 -0xff5cba9876543p-44 + 53 -0xff 0x123456789abcdfp-52 + 53 256.5 +3 53 -0x10038p-4 -0x10018p-4 + 53 -0x1fffffffffffffp-52 -0x1p-550 + 53 4097.5 diff --git a/tests/sub_q.dat b/tests/sub_q.dat new file mode 100644 index 0000000..8a6d1d0 --- /dev/null +++ b/tests/sub_q.dat @@ -0,0 +1,117 @@ +# data file for mpfi_sub_q +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1/1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1/1 +0 53 nan -inf 53 nan -inf -3/1 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3/1 +0 53 nan -0 53 nan -7 -7/1 +0 53 nan -7 53 nan -7 0 +0 53 nan -14 53 nan -7 7/1 +0 53 nan +15 53 nan -0 -15/1 +0 53 nan -0 53 nan -0 0 +0 53 nan -15 53 nan -0 15/1 +0 53 nan 32 53 nan 1 -31/1 +0 53 nan 1 53 nan 1 0 +0 53 nan -30 53 nan 1 31/1 +0 53 nan +inf 53 nan +inf -63/1 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63/1 +0 53 -inf -inf 53 -inf -inf -2/1 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2/1 +0 53 -inf -3 53 -inf -7 -4/1 +0 53 -inf -7 53 -inf -7 0 +0 53 -inf -11 53 -inf -7 4/1 + +2 53 -inf -0x1b6db6db6db6dbp-50 + 53 -inf -7 -1/7 +2 53 -inf -0x1c924924924924p-50 + 53 -inf -7 1/7 +2 53 -inf -0x1fffffffffffffp+17 + 53 -inf -0x1p+70 -7/1 +2 53 -inf -0x1p+70 + 53 -inf -0x1p+70 7/1 + +0 53 -inf 8 53 -inf -0 -8/1 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf -8 53 -inf -0 8/1 +0 53 -inf 24 53 -inf 8 -16/1 +0 53 -inf 8 53 -inf 8 0 +0 53 -inf -8 53 -inf 8 16/1 +0 53 -inf +inf 53 -inf +inf -32/1 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32/1 +0 53 -inf nan 53 -inf nan -64/1 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan 64/1 +0 53 1 1 53 +0 -0 -1/1 +0 53 +0 -0 53 +0 -0 0 +0 53 -1 -1 53 +0 -0 1/1 +0 53 3 11 53 +0 8 -3/1 +0 53 +0 8 53 +0 8 0 +0 53 -3 5 53 +0 8 3/1 +0 53 7 +inf 53 +0 +inf -7/1 +0 53 +0 +inf 53 +0 +inf 0 +0 53 -7 +inf 53 +0 +inf 7/1 + +1 53 0x12492492492492p-55 +inf + 53 +0 +inf -1/7 +1 53 -0x12492492492493p-55 +inf + 53 +0 +inf 1/7 +1 53 0x1p+70 +inf + 53 0x1p+70 +inf -7/1 +1 53 0x1fffffffffffffp+17 +inf + 53 0x1p+70 +inf 7/1 + +0 53 +inf +inf 53 +inf +inf -1/1 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1/1 +0 53 +inf nan 53 +inf nan -1/1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1/1 + +# regular values +0 53 -64 -49 53 -32 -17 32/1 +0 53 +0 +15 53 -32 -17 -32/1 +0 53 -15 -0 53 -32 -17 -17/1 + +0 53 0x153456789abcdfp-48 0x123456789abce2 + 53 0x123456789abcdfp-48 0x123456789abcdf -3/1 +1 53 0x3123456789abcdp-52 0x123456789abce2 + 53 0x123456789abcdfp-56 0x123456789abcdf -3/1 +2 53 1 0x10123456789abdp-44 + 53 -0xff 0x123456789abcdfp-52 -256/1 +3 53 0xfff 0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 -0x1001/1 + +0 53 0xf3456789abcdfp-48 0x123456789abcdc + 53 0x123456789abcdfp-48 0x123456789abcdf 3/1 +1 53 -0x2edcba98765433p-52 0x123456789abcdc + 53 0x123456789abcdfp-56 0x123456789abcdf 3/1 +2 53 -0x1ff -0xfedcba9876543p-44 + 53 -0xff 0x123456789abcdfp-52 256/1 +3 53 -0x1003 -0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 0x1001/1 + +# the precision of the result is too small for the mpq value +3 4 +0.3125 +10 53 -20 -11 -61/3 +3 4 +0.3125 16 53 -32 -17 -97/3 +0 4 -15 -1 53 -32 -18 -17/1 +1 3 -16 -1 53 -32 -18 -17/1 + + + diff --git a/tests/sub_si.dat b/tests/sub_si.dat new file mode 100644 index 0000000..8eece85 --- /dev/null +++ b/tests/sub_si.dat @@ -0,0 +1,92 @@ +# data file for mpfi_sub_si +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan -inf 53 nan -inf -3 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3 +0 53 nan -0 53 nan -7 -7 +0 53 nan -7 53 nan -7 0 +0 53 nan -14 53 nan -7 7 +0 53 nan +15 53 nan -0 -15 +0 53 nan -0 53 nan -0 0 +0 53 nan -15 53 nan -0 15 +0 53 nan 32 53 nan 1 -31 +0 53 nan 1 53 nan 1 0 +0 53 nan -30 53 nan 1 31 +0 53 nan +inf 53 nan +inf -63 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63 +0 53 -inf -inf 53 -inf -inf -2 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf +2 +0 53 -inf -3 53 -inf -7 -4 +0 53 -inf -7 53 -inf -7 0 +0 53 -inf -11 53 -inf -7 4 + +2 53 -inf -0x1p+70 + 53 -inf -0x1p+70 1 + +0 53 -inf 8 53 -inf -0 -8 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf -8 53 -inf -0 8 +0 53 -inf 24 53 -inf 8 -16 +0 53 -inf 8 53 -inf 8 0 +0 53 -inf -8 53 -inf 8 16 +0 53 -inf +inf 53 -inf +inf -32 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf +32 +0 53 -inf nan 53 -inf nan -64 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan +64 +0 53 1 1 53 +0 -0 -1 +0 53 +0 -0 53 +0 -0 0 +0 53 -1 -1 53 +0 -0 1 +0 53 3 11 53 +0 +8 -3 +0 53 +0 8 53 +0 +8 0 +0 53 -3 5 53 +0 +8 3 +0 53 7 +inf 53 +0 +inf -7 +0 53 +0 +inf 53 +0 +inf 0 +0 53 -7 +inf 53 +0 +inf 7 +0 53 +inf +inf 53 +inf +inf -1 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 +inf nan 53 +inf nan -1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1 + +# regular values +0 53 -64 -49 53 -32 -17 32 +0 53 +0 +15 53 -32 -17 -32 +0 53 -15 -0 53 -32 -17 -17 + +0 53 0x153456789abcdfp-48 0x123456789abce2 + 53 0x123456789abcdfp-48 0x123456789abcdf -3 +1 53 0x3123456789abcdp-52 0x123456789abce2 + 53 0x123456789abcdfp-56 0x123456789abcdf -3 +2 53 1 0x10123456789abdp-44 + 53 -0xff 0x123456789abcdfp-52 -256 +3 53 0xfff 0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 -0x1001 + +0 53 0xf3456789abcdfp-48 0x123456789abcdc + 53 0x123456789abcdfp-48 0x123456789abcdf 3 +1 53 -0x2edcba98765433p-52 0x123456789abcdc + 53 0x123456789abcdfp-56 0x123456789abcdf 3 +2 53 -0x1ff -0xfedcba9876543p-44 + 53 -0xff 0x123456789abcdfp-52 256 +3 53 -0x1003 -0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 0x1001 diff --git a/tests/sub_ui.dat b/tests/sub_ui.dat new file mode 100644 index 0000000..b2386f4 --- /dev/null +++ b/tests/sub_ui.dat @@ -0,0 +1,63 @@ +# data file for mpfi_sub_ui +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3 +0 53 nan -7 53 nan -7 0 +0 53 nan -14 53 nan -7 7 +0 53 nan -0 53 nan -0 0 +0 53 nan -15 53 nan -0 15 +0 53 nan 1 53 nan 1 0 +0 53 nan -30 53 nan 1 31 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 1 +0 53 -inf -7 53 -inf -7 0 +0 53 -inf -8 53 -inf -7 1 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf -2 53 -inf -0 2 +0 53 -inf 8 53 -inf 8 0 +0 53 -inf 4 53 -inf 8 4 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 4 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan 8 +0 53 +0 -0 53 +0 -0 0 +0 53 -1 -1 53 +0 -0 1 +0 53 +0 8 53 +0 8 0 +0 53 -3 5 53 +0 8 3 +0 53 +0 +inf 53 +0 +inf 0 +0 53 -7 +inf 53 +0 +inf 7 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1 + +# regular values +0 53 -64 -49 53 -32 -17 32 +0 53 -49 -34 53 -32 -17 17 +0 53 -15 -0 53 17 32 32 +0 53 +0 15 53 17 32 17 + +0 53 0x0f3456789abcdfp-48 0x123456789abcdc + 53 0x123456789abcdfp-48 0x123456789abcdf 3 +1 53 -0x176e5d4c3b2a1ap-51 0x123456789abcdc + 53 0x123456789abcdfp-56 0x123456789abcdf 3 +2 53 -0x1ff -0x1fdb97530eca86p-45 + 53 -0xff 0x123456789abcdfp-52 256 +3 53 -0x1003 -0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 0x1001 diff --git a/tests/sub_z.dat b/tests/sub_z.dat new file mode 100644 index 0000000..5507080 --- /dev/null +++ b/tests/sub_z.dat @@ -0,0 +1,106 @@ +# data file for mpfi_sub_z +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of first parameter +# 6: left endpoint value of first parameter +# 7: right endpoint value of first parameter +# 8: second parameter value + +# special values +0 53 nan nan 53 nan nan -1 +0 53 nan nan 53 nan nan 0 +0 53 nan nan 53 nan nan 1 +0 53 nan -inf 53 nan -inf -3 +0 53 nan -inf 53 nan -inf 0 +0 53 nan -inf 53 nan -inf 3 +0 53 nan -0 53 nan -7 -7 +0 53 nan -7 53 nan -7 0 +0 53 nan -14 53 nan -7 7 +0 53 nan +15 53 nan -0 -15 +0 53 nan -0 53 nan -0 0 +0 53 nan -15 53 nan -0 15 +0 53 nan 32 53 nan 1 -31 +0 53 nan 1 53 nan 1 0 +0 53 nan -30 53 nan 1 31 +0 53 nan +inf 53 nan +inf -63 +0 53 nan +inf 53 nan +inf 0 +0 53 nan +inf 53 nan +inf 63 +0 53 -inf -inf 53 -inf -inf -2 +0 53 -inf -inf 53 -inf -inf 0 +0 53 -inf -inf 53 -inf -inf 2 +0 53 -inf -3 53 -inf -7 -4 +0 53 -inf -7 53 -inf -7 0 +0 53 -inf -11 53 -inf -7 4 + +2 53 -inf -0x1fffffffffffffp+17 + 53 -inf -0x1p+70 -7 +2 53 -inf -0x1p+70 + 53 -inf -0x1p+70 7 + +0 53 -inf 8 53 -inf -0 -8 +0 53 -inf -0 53 -inf -0 0 +0 53 -inf -8 53 -inf -0 8 +0 53 -inf 24 53 -inf 8 -16 +0 53 -inf 8 53 -inf 8 0 +0 53 -inf -8 53 -inf 8 16 +0 53 -inf +inf 53 -inf +inf -32 +0 53 -inf +inf 53 -inf +inf 0 +0 53 -inf +inf 53 -inf +inf 32 +0 53 -inf nan 53 -inf nan -64 +0 53 -inf nan 53 -inf nan 0 +0 53 -inf nan 53 -inf nan 64 +0 53 1 1 53 +0 -0 -1 +0 53 +0 -0 53 +0 -0 0 +0 53 -1 -1 53 +0 -0 1 +0 53 3 11 53 +0 8 -3 +0 53 +0 8 53 +0 8 0 +0 53 -3 5 53 +0 8 3 +0 53 7 +inf 53 +0 +inf -7 +0 53 +0 +inf 53 +0 +inf 0 +0 53 -7 +inf 53 +0 +inf 7 + +1 53 0x1p+70 +inf + 53 0x1p+70 +inf -7 +1 53 0x1fffffffffffffp+17 +inf + 53 0x1p+70 +inf 7 + +0 53 +inf +inf 53 +inf +inf -1 +0 53 +inf +inf 53 +inf +inf 0 +0 53 +inf +inf 53 +inf +inf 1 +0 53 +inf nan 53 +inf nan -1 +0 53 +inf nan 53 +inf nan 0 +0 53 +inf nan 53 +inf nan 1 + +# regular values +0 53 -64 -49 53 -32 -17 32 +0 53 +0 +15 53 -32 -17 -32 +0 53 -15 -0 53 -32 -17 -17 + +0 53 0x153456789abcdfp-48 0x123456789abce2 + 53 0x123456789abcdfp-48 0x123456789abcdf -3 +1 53 0x3123456789abcdp-52 0x123456789abce2 + 53 0x123456789abcdfp-56 0x123456789abcdf -3 +2 53 1 0x10123456789abdp-44 + 53 -0xff 0x123456789abcdfp-52 -256 +3 53 0xfff 0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 -0x1001 + +0 53 0xf3456789abcdfp-48 0x123456789abcdc + 53 0x123456789abcdfp-48 0x123456789abcdf 3 +1 53 -0x2edcba98765433p-52 0x123456789abcdc + 53 0x123456789abcdfp-56 0x123456789abcdf 3 +2 53 -0x1ff -0xfedcba9876543p-44 + 53 -0xff 0x123456789abcdfp-52 256 +3 53 -0x1003 -0x1001 + 53 -0x1fffffffffffffp-52 -0x1p-550 0x1001 + +# the precision of the result is too small for the mpz value +2 4 1 30 53 -32 -4 -33 +2 3 1 32 53 -32 -4 -33 +0 4 -15 -1 53 -32 -18 -17 +1 3 -16 -1 53 -32 -18 -17 diff --git a/tests/tabs.c b/tests/tabs.c new file mode 100644 index 0000000..11905f4 --- /dev/null +++ b/tests/tabs.c @@ -0,0 +1,44 @@ +/* tabs.c -- Test mpfi_abs. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_abs; + + mpfi_fun_init_II (&i_abs, mpfi_abs, mpfr_abs); + test_start (); + + check_data (&i_abs, "abs.dat"); + check_random (&i_abs, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_abs); + + return 0; +} diff --git a/tests/tacos.c b/tests/tacos.c new file mode 100644 index 0000000..57845d4 --- /dev/null +++ b/tests/tacos.c @@ -0,0 +1,44 @@ +/* tacos.c -- Test mpfi_acos. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_acos; + + mpfi_fun_init_II (&i_acos, mpfi_acos, mpfr_acos); + test_start (); + + check_data (&i_acos, "acos.dat"); + check_random (&i_acos, 2, 512, 10); + + test_end (); + mpfi_fun_clear (&i_acos); + + return 0; +} diff --git a/tests/tacosh.c b/tests/tacosh.c new file mode 100644 index 0000000..c368006 --- /dev/null +++ b/tests/tacosh.c @@ -0,0 +1,44 @@ +/* tacosh.c -- Test mpfi_acosh. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_acosh; + + mpfi_fun_init_II (&i_acosh, mpfi_acosh, mpfr_acosh); + test_start (); + + check_data (&i_acosh, "acosh.dat"); + check_random (&i_acosh, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_acosh); + + return 0; +} diff --git a/tests/tadd.c b/tests/tadd.c new file mode 100644 index 0000000..578b3d9 --- /dev/null +++ b/tests/tadd.c @@ -0,0 +1,45 @@ +/* tadd.c -- Test mpfi_add. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_add; + + mpfi_fun_init_III (&i_add, mpfi_add, mpfr_add); + + test_start (); + + check_data (&i_add, "add.dat"); + check_random (&i_add, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_add); + + return 0; +} diff --git a/tests/tadd_d.c b/tests/tadd_d.c new file mode 100644 index 0000000..4f5b5cd --- /dev/null +++ b/tests/tadd_d.c @@ -0,0 +1,96 @@ +/* tadd_d.c -- Test mpfi_add_d. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +static void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_add_d (a, a, +1.1); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_add_d does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_add_d does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_add_d (a, a, -1.1); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_add_d does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_add_d does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_add_d; + + mpfi_fun_init_IID (&i_add_d, mpfi_add_d, mpfr_add_d); + test_start (); + + check_data (&i_add_d, "add_d.dat"); + check_random (&i_add_d, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_add_d); + + return 0; +} diff --git a/tests/tadd_fr.c b/tests/tadd_fr.c new file mode 100644 index 0000000..4ed7c5d --- /dev/null +++ b/tests/tadd_fr.c @@ -0,0 +1,101 @@ +/* tadd_fr.c -- Test mpfi_add_fr. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +static void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + mpfr_t b; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_init2 (b, 53); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + mpfr_set_ui (b, +1, MPFI_RNDD); + + inexact = mpfi_add_fr (a, a, b); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_add_fr does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_add_fr does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + mpfr_set_si (b, -1, MPFI_RNDD); + + inexact = mpfi_add_fr (a, a, b); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_add_fr does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_add_fr does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (b); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_add_fr; + + test_start (); + mpfi_fun_init_IIR (&i_add_fr, mpfi_add_fr, mpfr_add); + + check_data (&i_add_fr, "add_fr.dat"); + check_overflow (); + check_random (&i_add_fr, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_add_fr); + + return 0; +} diff --git a/tests/tadd_q.c b/tests/tadd_q.c new file mode 100644 index 0000000..76e370b --- /dev/null +++ b/tests/tadd_q.c @@ -0,0 +1,98 @@ +/* tadd_q.c -- Test mpfi_add_q. + +Copyright 2010, 2011, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + mpq_t q; + int inexact; + + mpq_init (q); + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + + mpq_set_ui (q, 42, 17); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_add_q (a, a, q); + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_add_q does not correctly handle overflow.\n"); + exit (1); + } + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_add_q does not return correct value " + "when overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + mpq_set_si (q, -42, 17); + + inexact = mpfi_add_q (a, a, q); + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_add_q does not correctly handle negative " + "overflow.\n"); + exit (1); + } + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_add_q does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); + mpq_clear (q); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_add_q; + + mpfi_fun_init_IIQ (&i_add_q, mpfi_add_q, mpfr_add_q); + test_start (); + + check_data (&i_add_q, "add_q.dat"); + + if (getenv ("MPFI_CHECK_EXPENSIVE_OVERFLOW") != NULL) + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_add_q); + + return 0; +} diff --git a/tests/tadd_si.c b/tests/tadd_si.c new file mode 100644 index 0000000..c268c09 --- /dev/null +++ b/tests/tadd_si.c @@ -0,0 +1,97 @@ +/* tadd_si.c -- Test mpfi_add_si. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_add_si (a, a, +1); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_add_si does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_add_si does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_add_si (a, a, -1); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_add_si does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_add_si does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_add_si; + + mpfi_fun_init_IIS (&i_add_si, mpfi_add_si, mpfr_add_si); + + test_start (); + + check_data (&i_add_si, "add_si.dat"); + check_random (&i_add_si, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_add_si); + + return 0; +} diff --git a/tests/tadd_ui.c b/tests/tadd_ui.c new file mode 100644 index 0000000..ebc23b1 --- /dev/null +++ b/tests/tadd_ui.c @@ -0,0 +1,77 @@ +/* tadd_ui.c -- Test mpfi_add_ui. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_add_ui (a, a, +1); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_add_ui does not correctly handle overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_add_ui does not return correct value " + "when overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_add_ui; + + mpfi_fun_init_IIU (&i_add_ui, mpfi_add_ui, mpfr_add_ui); + + test_start (); + + check_data (&i_add_ui, "add_ui.dat"); + check_random (&i_add_ui, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_add_ui); + + return 0; +} diff --git a/tests/tadd_z.c b/tests/tadd_z.c new file mode 100644 index 0000000..7cd21ec --- /dev/null +++ b/tests/tadd_z.c @@ -0,0 +1,97 @@ +/* tadd_z.c -- Test mpfi_add_z. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + mpz_t n; + int inexact; + + mpz_init (n); + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + + mpz_set_ui (n, 17); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_add_z (a, a, n); + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_add_z does not correctly handle overflow.\n"); + exit (1); + } + if (!MPFI_RIGHT_IS_INEXACT (inexact) || MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_add_z does not return correct value " + "when overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + mpz_set_si (n, -17); + + inexact = mpfi_add_z (a, a, n); + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_add_z does not correctly handle negative " + "overflow.\n"); + exit (1); + } + if (!MPFI_LEFT_IS_INEXACT (inexact) || MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_add_z does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); + mpz_clear (n); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_add_z; + + mpfi_fun_init_IIZ (&i_add_z, mpfi_add_z, mpfr_add_z); + test_start (); + + check_data (&i_add_z, "add_z.dat"); + check_overflow (); + check_random (&i_add_z, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_add_z); + + return 0; +} diff --git a/tests/tan.dat b/tests/tan.dat new file mode 100644 index 0000000..bc8ae6c --- /dev/null +++ b/tests/tan.dat @@ -0,0 +1,167 @@ +# data file for mpfi_tan +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan nan 53 nan -inf +0 53 nan nan 53 -7 nan +0 53 nan nan 53 nan -0 +0 53 nan nan 53 +0 nan +0 53 nan nan 53 -inf nan +0 53 nan nan 53 -inf -inf +0 53 -inf +inf 53 -inf -7 +0 53 -inf +inf 53 -inf -0 +0 53 -inf +inf 53 -inf +8 +0 53 -inf +inf 53 -inf +inf +1 53 -0x18eb245cbee3a6p-52 -0 53 -1 -0 +0 53 +0 -0 53 +0 -0 +2 53 +0 0x18eb245cbee3a6p-52 53 +0 +1 +0 53 -inf +inf 53 +0 +8 +0 53 -inf +inf 53 +0 +inf +0 53 nan nan 53 +inf +inf + +# regular values +0 53 -inf +inf 53 0.125 17 +0 53 -inf +inf + 53 0x1921fb54442d18p-52 0x1921fb54442d19p-52 +0 53 -inf +inf 53 -2 -0.5 +0 53 -inf +inf 53 -4.5 0.625 +3 53 -0x18eb245cbee3a6p-52 -0x105785a43c4c55p-54 53 -1 -0.25 +3 53 -0x117b4f5bf3474bp-53 0x117b4f5bf3474bp-53 53 -0.5 0.5 +3 53 -0x1c8dc87ddcc134p-55 -0x1c8dc87ddcc133p-55 + 53 0x71p+76 0x71p+76 + +0 53 -inf +inf 53 -7 7 +0 53 -inf +inf 53 -7 6 +0 53 -inf +inf 53 -7 5 +0 53 -inf +inf 53 -7 4 +0 53 -inf +inf 53 -7 3 +0 53 -inf +inf 53 -7 2 +0 53 -inf +inf 53 -7 1 +0 53 -inf +inf 53 -7 -0 +0 53 -inf +inf 53 -7 -1 +0 53 -inf +inf 53 -7 -2 +0 53 -inf +inf 53 -7 -3 +0 53 -inf +inf 53 -7 -4 +3 53 -0x1be2e6e13eea79p-53 0x1b0b4b739bbb07p-51 53 -7 -5 +3 53 -0x1be2e6e13eea79p-53 0x129fd86ebb95bfp-54 53 -7 -6 +3 53 -0x1be2e6e13eea79p-53 -0x1be2e6e13eea78p-53 53 -7 -7 + +0 53 -inf +inf 53 -6 7 +0 53 -inf +inf 53 -6 6 +0 53 -inf +inf 53 -6 5 +0 53 -inf +inf 53 -6 4 +0 53 -inf +inf 53 -6 3 +0 53 -inf +inf 53 -6 2 +0 53 -inf +inf 53 -6 1 +0 53 -inf +inf 53 -6 -0 +0 53 -inf +inf 53 -6 -1 +0 53 -inf +inf 53 -6 -2 +0 53 -inf +inf 53 -6 -3 +0 53 -inf +inf 53 -6 -4 +3 53 0x129fd86ebb95bep-54 0x1b0b4b739bbb07p-51 53 -6 -5 +3 53 0x129fd86ebb95bep-54 0x129fd86ebb95bfp-54 53 -6 -6 + +0 53 -inf +inf 53 -5 7 +0 53 -inf +inf 53 -5 6 +0 53 -inf +inf 53 -5 5 +0 53 -inf +inf 53 -5 4 +0 53 -inf +inf 53 -5 3 +0 53 -inf +inf 53 -5 2 +0 53 -inf +inf 53 -5 1 +0 53 -inf +inf 53 -5 -0 +0 53 -inf +inf 53 -5 -1 +0 53 -inf +inf 53 -5 -2 +0 53 -inf +inf 53 -5 -3 +0 53 -inf +inf 53 -5 -4 +3 53 0x1b0b4b739bbb06p-51 0x1b0b4b739bbb07p-51 53 -5 -5 + +0 53 -inf +inf 53 -4 7 +0 53 -inf +inf 53 -4 6 +0 53 -inf +inf 53 -4 5 +0 53 -inf +inf 53 -4 4 +0 53 -inf +inf 53 -4 3 +0 53 -inf +inf 53 -4 2 +0 53 -inf +inf 53 -4 1 +0 53 -inf +inf 53 -4 -0 +0 53 -inf +inf 53 -4 -1 +3 53 -0x12866f9be4de14p-52 0x117af62e0950f9p-51 53 -4 -2 +3 53 -0x12866f9be4de14p-52 0x123ef71254b870p-55 53 -4 -3 +3 53 -0x12866f9be4de14p-52 -0x12866f9be4de13p-52 53 -4 -4 + +0 53 -inf +inf 53 -3 7 +0 53 -inf +inf 53 -3 6 +0 53 -inf +inf 53 -3 5 +0 53 -inf +inf 53 -3 4 +0 53 -inf +inf 53 -3 3 +0 53 -inf +inf 53 -3 2 +0 53 -inf +inf 53 -3 1 +0 53 -inf +inf 53 -3 -0 +0 53 -inf +inf 53 -3 -1 +3 53 0x123ef71254b86fp-55 0x117af62e0950f9p-51 53 -3 -2 +3 53 0x123ef71254b86fp-55 0x123ef71254b870p-55 53 -3 -3 + +0 53 -inf +inf 53 -2 7 +0 53 -inf +inf 53 -2 6 +0 53 -inf +inf 53 -2 5 +0 53 -inf +inf 53 -2 4 +0 53 -inf +inf 53 -2 3 +0 53 -inf +inf 53 -2 2 +0 53 -inf +inf 53 -2 1 +0 53 -inf +inf 53 -2 -0 +0 53 -inf +inf 53 -2 -1 +3 53 0x117af62e0950f8p-51 0x117af62e0950f9p-51 53 -2 -2 + +0 53 -inf +inf 53 -1 7 +0 53 -inf +inf 53 -1 6 +0 53 -inf +inf 53 -1 5 +0 53 -inf +inf 53 -1 4 +0 53 -inf +inf 53 -1 3 +0 53 -inf +inf 53 -1 2 +3 53 -0x18eb245cbee3a6p-52 0x18eb245cbee3a6p-52 53 -1 1 +1 53 -0x18eb245cbee3a6p-52 -0 53 -1 -0 +3 53 -0x18eb245cbee3a6p-52 -0x18eb245cbee3a5p-52 53 -1 -1 + +0 53 -inf +inf 53 1 7 +0 53 -inf +inf 53 1 6 +0 53 -inf +inf 53 1 5 +0 53 -inf +inf 53 1 4 +0 53 -inf +inf 53 1 3 +0 53 -inf +inf 53 1 2 +3 53 0x18eb245cbee3a5p-52 0x18eb245cbee3a6p-52 53 1 1 + +0 53 -inf +inf 53 2 7 +0 53 -inf +inf 53 2 6 +0 53 -inf +inf 53 2 5 +3 53 -0x117af62e0950f9p-51 0x12866f9be4de14p-52 53 2 4 +3 53 -0x117af62e0950f9p-51 -0x123ef71254b86fp-55 53 2 3 +3 53 -0x117af62e0950f9p-51 -0x117af62e0950f8p-51 53 2 2 + +0 53 -inf +inf 53 3 7 +0 53 -inf +inf 53 3 6 +0 53 -inf +inf 53 3 5 +3 53 -0x123ef71254b870p-55 0x12866f9be4de14p-52 53 3 4 +3 53 -0x123ef71254b870p-55 -0x123ef71254b86fp-55 53 3 3 + +0 53 -inf +inf 53 4 7 +0 53 -inf +inf 53 4 6 +0 53 -inf +inf 53 4 5 +3 53 0x12866f9be4de13p-52 0x12866f9be4de14p-52 53 4 4 + +3 53 -0x1b0b4b739bbb07p-51 0x1be2e6e13eea79p-53 53 5 7 +3 53 -0x1b0b4b739bbb07p-51 -0x129fd86ebb95bep-54 53 5 6 +3 53 -0x1b0b4b739bbb07p-51 -0x1b0b4b739bbb06p-51 53 5 5 + +3 53 -0x129fd86ebb95bfp-54 0x1be2e6e13eea79p-53 53 6 7 +3 53 -0x129fd86ebb95bfp-54 -0x129fd86ebb95bep-54 53 6 6 + +3 53 0x1be2e6e13eea78p-53 0x1be2e6e13eea79p-53 53 7 7 diff --git a/tests/tanh.dat b/tests/tanh.dat new file mode 100644 index 0000000..336f253 --- /dev/null +++ b/tests/tanh.dat @@ -0,0 +1,37 @@ +# data file for mpfi_tanh +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: precision of input parameter +# 6: left endpoint value of input parameter +# 7: right endpoint value of input parameter + +# special values +0 53 nan nan 53 nan nan +0 53 nan -1 53 nan -inf +0 53 -0x1ffffc832750f2p-53 nan 53 -7 nan +0 53 nan -0 53 nan -0 +0 53 +0 nan 53 +0 nan +0 53 -1 nan 53 -inf nan +0 53 -1 -1 53 -inf -inf +2 53 -1 -0x1ffffc832750f1p-53 53 -inf -7 +0 53 -1 -0 53 -inf -0 +2 53 -1 0x1fffff872a91f9p-53 53 -inf 8 +0 53 -1 +1 53 -inf +inf +1 53 -0x185efab514f395p-53 -0 53 -1 -0 +0 53 +0 -0 53 +0 -0 +2 53 +0 0x185efab514f395p-53 53 +0 1 +2 53 +0 0x1fffff872a91f9p-53 53 +0 8 +0 53 +0 +1 53 +0 +inf +0 53 +1 +1 53 +inf +inf + +# regular values +1 53 -0x1fd5992bc4b835p-56 -0 53 -0.125 -0 +2 53 +0 0x1d9353d7568af5p-54 53 0 0x10000000000001p-53 +3 53 -0x1ffdfa72153984p-53 -0x11bf47eabb8f95p-53 53 -4.5 -0.625 +3 53 0x185efab514f394p-53 0x1fd77d111a0b00p-53 53 1 3 +3 53 0x1fffffffffffe1p-53 0x1ffffffffffffcp-53 53 17 18 diff --git a/tests/tasin.c b/tests/tasin.c new file mode 100644 index 0000000..86cb894 --- /dev/null +++ b/tests/tasin.c @@ -0,0 +1,44 @@ +/* tasin.c -- Test mpfi_asin. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_asin; + + mpfi_fun_init_II (&i_asin, mpfi_asin, mpfr_asin); + test_start (); + + check_data (&i_asin, "asin.dat"); + check_random (&i_asin, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_asin); + + return 0; +} diff --git a/tests/tasinh.c b/tests/tasinh.c new file mode 100644 index 0000000..405b582 --- /dev/null +++ b/tests/tasinh.c @@ -0,0 +1,44 @@ +/* tasinh.c -- Test mpfi_asinh. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_asinh; + + mpfi_fun_init_II (&i_asinh, mpfi_asinh, mpfr_asinh); + test_start (); + + check_data (&i_asinh, "asinh.dat"); + check_random (&i_asinh, 2, 512, 10); + + test_end (); + mpfi_fun_clear (&i_asinh); + + return 0; +} diff --git a/tests/tatan.c b/tests/tatan.c new file mode 100644 index 0000000..37f84a3 --- /dev/null +++ b/tests/tatan.c @@ -0,0 +1,44 @@ +/* tatan.c -- Test mpfi_atan. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_atan; + + mpfi_fun_init_II (&i_atan, mpfi_atan, mpfr_atan); + test_start (); + + check_data (&i_atan, "atan.dat"); + check_random (&i_atan, 2, 512, 10); + + test_end (); + mpfi_fun_clear (&i_atan); + + return 0; +} diff --git a/tests/tatan2.c b/tests/tatan2.c new file mode 100644 index 0000000..7fb3fac --- /dev/null +++ b/tests/tatan2.c @@ -0,0 +1,45 @@ +/* tatan2.c -- Test mpfi_atan2. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_atan2; + + mpfi_fun_init_III (&i_atan2, mpfi_atan2, mpfr_atan2); + + test_start (); + + check_data (&i_atan2, "atan2.dat"); + check_random (&i_atan2, 2, 512, 10); + + test_end (); + mpfi_fun_clear (&i_atan2); + + return 0; +} diff --git a/tests/tatanh.c b/tests/tatanh.c new file mode 100644 index 0000000..ab242e2 --- /dev/null +++ b/tests/tatanh.c @@ -0,0 +1,44 @@ +/* tatanh.c -- Test mpfi_atanh. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_atanh; + + mpfi_fun_init_II (&i_atanh, mpfi_atanh, mpfr_atanh); + test_start (); + + check_data (&i_atanh, "atanh.dat"); + check_random (&i_atanh, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_atanh); + + return 0; +} diff --git a/tests/tbisect.c b/tests/tbisect.c new file mode 100644 index 0000000..65eaf7e --- /dev/null +++ b/tests/tbisect.c @@ -0,0 +1,164 @@ +/* tbisect.c -- Test mpfi_bisect. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; +extern unsigned long line_number; +unsigned long test_line_number; /* start line of a test */ + +static void +check (mpfi_ptr left, mpfi_ptr right, mpfi_srcptr interval, + mpfi_srcptr expected_left, mpfi_srcptr expected_right, + int expected_inex) +{ + int inex; + + inex = mpfi_bisect (left, right, interval); + if (inex != expected_inex || !same_value (left, expected_left) + || !same_value (right, expected_right)) + { + printf ("Failed line %lu.\n interval: ", test_line_number); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\n returned left: "); + mpfi_out_str (stdout, 16, 0, left); + printf ("\nreturned right: "); + mpfi_out_str (stdout, 16, 0, right); + printf ("\n expected left: "); + mpfi_out_str (stdout, 16, 0, expected_left); + printf ("\nexpected right: "); + mpfi_out_str (stdout, 16, 0, expected_right); + printf ("\n"); + if (inex != expected_inex) { + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + } + + exit (1); + } + + + /* reuse variable tests */ + + if (mpfi_get_prec (interval) == mpfi_get_prec (expected_left)) + { + mpfi_set (left, interval); + inex = mpfi_bisect (left, right, left); + if (inex != expected_inex || !same_value (left, expected_left) + || !same_value (right, expected_right)) + { + printf ("Error when reusing input argument as first output " + "(line %lu).\n interval: ", test_line_number); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\n returned left: "); + mpfi_out_str (stdout, 16, 0, left); + printf ("\nreturned right: "); + mpfi_out_str (stdout, 16, 0, right); + printf ("\n expected left: "); + mpfi_out_str (stdout, 16, 0, expected_left); + printf ("\nexpected right: "); + mpfi_out_str (stdout, 16, 0, expected_right); + printf ("\n"); + if (inex != expected_inex) { + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + } + + exit (1); + } + } + + if (mpfi_get_prec (interval) == mpfi_get_prec (expected_right)) + { + mpfi_set (right, interval); + inex = mpfi_bisect (left, right, right); + if (inex != expected_inex || !same_value (left, expected_left) + || !same_value (right, expected_right)) + { + printf ("Error when reusing input argument as second output " + "(line %lu).\n interval: ", test_line_number); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\n returned left: "); + mpfi_out_str (stdout, 16, 0, left); + printf ("\nreturned right: "); + mpfi_out_str (stdout, 16, 0, right); + printf ("\n expected left: "); + mpfi_out_str (stdout, 16, 0, expected_left); + printf ("\nexpected right: "); + mpfi_out_str (stdout, 16, 0, expected_right); + printf ("\n"); + if (inex != expected_inex) { + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + } + + exit (1); + } + } +} + +int +main (int argc, char **argv) +{ + FILE *stream; + mpfi_t interval; + mpfi_t left; + mpfi_t right; + mpfi_t expected_left; + mpfi_t expected_right; + + int retval; + + mpfi_init2 (interval, 1024); + mpfi_init2 (left, 1024); + mpfi_init2 (right, 1024); + mpfi_init2 (expected_left, 1024); + mpfi_init2 (expected_right, 1024); + + stream = open_file ("bisect.dat"); + init_reading (stream); + + while (nextchar != EOF) { + test_line_number = line_number; + read_sign (stream, &retval); + read_mpfi (stream, expected_left); + mpfi_set_prec (left, mpfi_get_prec (expected_left)); + read_mpfi (stream, expected_right); + mpfi_set_prec (right, mpfi_get_prec (expected_right)); + read_mpfi (stream, interval); + + check (left, right, interval, expected_left, expected_right, retval); + } + + close_file (stream); + mpfi_clear (interval); + mpfi_clear (left); + mpfi_clear (right); + mpfi_clear (expected_left); + mpfi_clear (expected_right); + + return 0; +} diff --git a/tests/tblow.c b/tests/tblow.c new file mode 100644 index 0000000..bcced78 --- /dev/null +++ b/tests/tblow.c @@ -0,0 +1,43 @@ +/* tblow.c -- Test mpfi_blow. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_blow; + + mpfi_fun_init_IID (&i_blow, mpfi_blow, NULL); + test_start (); + + check_data (&i_blow, "blow.dat"); + + test_end (); + mpfi_fun_clear (&i_blow); + + return 0; +} diff --git a/tests/tbounded_p.c b/tests/tbounded_p.c new file mode 100644 index 0000000..803c637 --- /dev/null +++ b/tests/tbounded_p.c @@ -0,0 +1,69 @@ +/* tbounded_p.c -- Test mpfi_bounded_p. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +void +print_error (mpfi_srcptr a) +{ + printf ("Error: mpfi_bounded_p (A) returns %d\nA = ", + mpfi_bounded_p (a)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\n"); + + exit (1); +} + +int +main (int argc, char **argv) +{ + FILE *stream; + mpfi_t interval; + int expected; + int got; + + mpfi_init2 (interval, 1024); + + stream = open_file ("bounded_p.dat"); + + init_reading (stream); + + while (nextchar != EOF) { + read_sign (stream, &expected); + read_mpfi (stream, interval); + + got = mpfi_bounded_p (interval); + if (got != expected || got * expected < 0) + print_error (interval); + } + + close_file (stream); + mpfi_clear (interval); + + return 0; +} diff --git a/tests/tcbrt.c b/tests/tcbrt.c new file mode 100644 index 0000000..c12b63c --- /dev/null +++ b/tests/tcbrt.c @@ -0,0 +1,44 @@ +/* tcbrt.c -- Test mpfi_cbrt. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_cbrt; + + mpfi_fun_init_II (&i_cbrt, mpfi_cbrt, mpfr_cbrt); + test_start (); + + check_data (&i_cbrt, "cbrt.dat"); + check_random (&i_cbrt, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_cbrt); + + return 0; +} diff --git a/tests/tcmp.c b/tests/tcmp.c new file mode 100644 index 0000000..78f1808 --- /dev/null +++ b/tests/tcmp.c @@ -0,0 +1,136 @@ +/* tcmp.c -- Test mpfi_cmp. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#define ORDER(min, max) \ + do { \ + if (mpfr_cmp ((min), (max)) > 0) \ + mpfr_swap ((min), (max)); \ + } while (0) + +void +print_error (mpfi_srcptr a, mpfi_srcptr b) +{ + printf ("Error: mpfi_cmp (A, B) returns %d\nA = ", + mpfi_cmp (a, b)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nB = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t i1, i2; + mpfr_t a, b, c, d; + int cmp; + int i; + + mpfr_init2 (a, 53); + mpfr_init2 (b, 53); + mpfr_init2 (c, 53); + mpfr_init2 (d, 53); + mpfi_init2 (i1, 53); + mpfi_init2 (i2, 53); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + random_mpfr (a); + random_mpfr (b); + random_mpfr (c); + random_mpfr (d); + ORDER (a, b); + ORDER (a, c); + ORDER (a, d); + ORDER (b, c); + ORDER (b, d); + ORDER (c, d); + + mpfi_interv_fr (i1, a, b); + mpfi_interv_fr (i2, c, d); + cmp = mpfi_cmp (i1, i2); + if (cmp > 0 || (cmp == 0 && !mpfr_equal_p (b, c))) { + print_error (i1, i2); + } + cmp = mpfi_cmp (i2, i1); + if (cmp < 0 || (cmp == 0 && !mpfr_equal_p (b, c))) { + print_error (i2, i1); + } + mpfr_set_nan (&(i1->right)); + if (mpfi_cmp (i1, i2) != 1) { + print_error (i1, i2); + } + + mpfi_interv_fr (i1, a, c); + mpfi_interv_fr (i2, b, d); + if (mpfi_cmp (i1, i2) != 0) { + print_error (i1, i2); + } + if (mpfi_cmp (i2, i1) != 0) { + print_error (i2, i1); + } + mpfr_set_nan (&(i1->right)); + if (mpfi_cmp (i1, i2) != 1) { + print_error (i1, i2); + } + + mpfi_interv_fr (i1, a, d); + mpfi_interv_fr (i2, b, c); + if (mpfi_cmp (i1, i2) != 0) { + print_error (i1, i2); + } + if (mpfi_cmp (i2, i1) != 0) { + print_error (i2, i1); + } + mpfr_set_nan (&(i1->right)); + if (mpfi_cmp (i2, i1) != 1) { + print_error (i2, i1); + } + } + + mpfr_clear (a); + mpfr_clear (b); + mpfr_clear (c); + mpfr_clear (d); + mpfi_clear (i1); + mpfi_clear (i2); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tcmp_d.c b/tests/tcmp_d.c new file mode 100644 index 0000000..993d1c0 --- /dev/null +++ b/tests/tcmp_d.c @@ -0,0 +1,122 @@ +/* tcmp_d.c -- Test mpfi_cmp_d. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#include "mpfi_config.h" + +#ifdef HAVE_FLOAT_H +#include +#endif + +/* Warning: DBL_MANT_DIG is not necessary a number of bits */ +#ifndef DBL_MANT_DIG +#define DBL_MANT_DIG 53 +#endif + +#define ORDER(min, max) \ + do { \ + if (min > max) { \ + double tmp; \ + tmp = min; \ + min = max; \ + max = tmp;} \ + } while (0) + +void +print_error (double x, mpfi_srcptr i) +{ + printf ("Error: mpfi_cmp_d (x, I) returns %d\nx = %g\nI = ", + mpfi_cmp_d (i, x), x); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t interval; + double a, b, c; + int cmp; + int i; + + mpfi_init2 (interval, DBL_MANT_DIG); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + a = random_double (); + b = random_double (); + c = random_double (); + ORDER (a, b); + ORDER (a, c); + ORDER (b, c); + + mpfi_interv_d (interval, b, c); + cmp = mpfi_cmp_d (interval, a); + if (cmp < 0 || (cmp == 0 && a != b)) { + print_error (a, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_d (interval, a) != 1) { + print_error (a, interval); + } + + mpfi_interv_d (interval, a, c); + if (mpfi_cmp_d (interval, b) != 0) { + print_error (b, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_d (interval, b) != 1) { + print_error (b, interval); + } + + mpfi_interv_d (interval, a, b); + cmp = mpfi_cmp_d (interval, c); + if (cmp > 0 || (cmp == 0 && c != b)) { + print_error (c, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_d (interval, c) != 1) { + print_error (c, interval); + } + } + + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tcmp_fr.c b/tests/tcmp_fr.c new file mode 100644 index 0000000..bb89257 --- /dev/null +++ b/tests/tcmp_fr.c @@ -0,0 +1,108 @@ +/* tcmp_fr.c -- Test mpfi_cmp_fr. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +print_error (mpfr_ptr x, mpfi_srcptr i) +{ + printf ("Error: mpfi_cmp_fr (x, I) returns %d\nx = ", + mpfi_cmp_fr (i, x)); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf ("\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t interval; + mpfr_t a, b, c; + int i; + int cmp; + + mpfr_init2 (a, 53); + mpfr_init2 (b, 53); + mpfr_init2 (c, 53); + mpfi_init2 (interval, 53); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + random_interval (interval); + mpfi_alea (b, interval); + mpfr_set (a, &(interval->left), MPFI_RNDD); + mpfr_set (c, &(interval->right), MPFI_RNDU); + + mpfi_interv_fr (interval, b, c); + cmp = mpfi_cmp_fr (interval, a); + if (cmp < 0 || (cmp == 0 && !mpfr_equal_p (a, b))) { + print_error (a, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_fr (interval, a) != 1) { + print_error (a, interval); + } + + mpfi_interv_fr (interval, a, c); + if (mpfi_cmp_fr (interval, b) != 0) { + print_error (b, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_fr (interval, b) != 1) { + print_error (b, interval); + } + + mpfi_interv_fr (interval, a, b); + cmp = mpfi_cmp_fr (interval, c); + if (cmp > 0 || (cmp == 0 && !mpfr_equal_p (c, b))) { + print_error (c, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_fr (interval, c) != 1) { + print_error (c, interval); + } + } + + mpfr_clear (a); + mpfr_clear (b); + mpfr_clear (c); + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tcmp_q.c b/tests/tcmp_q.c new file mode 100644 index 0000000..47b55f9 --- /dev/null +++ b/tests/tcmp_q.c @@ -0,0 +1,116 @@ +/* tcmp_q.c -- Test mpfi_cmp_q. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#define ORDER(min, max) \ + do { \ + if (mpq_cmp ((min), (max)) > 0) \ + mpq_swap ((min), (max)); \ + } while (0) + +void +print_error (mpq_ptr x, mpfi_srcptr i) +{ + printf ("Error: mpfi_cmp_q (x, I) returns %d\nx = ", + mpfi_cmp_q (i, x)); + mpq_out_str (stdout, 10, x); + printf ("\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t interval; + mpq_t a, b, c; + int cmp; + int i; + + mpq_init (a); + mpq_init (b); + mpq_init (c); + mpfi_init2 (interval, 53); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + random_mpq (a); + random_mpq (b); + random_mpq (c); + ORDER (a, b); + ORDER (a, c); + ORDER (b, c); + + mpfi_interv_q (interval, b, c); + cmp = mpfi_cmp_q (interval, a); + if (cmp < 0 || (cmp == 0 && mpq_cmp (a, b) != 0)) { + print_error (a, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_q (interval, a) != 1) { + print_error (a, interval); + } + + mpfi_interv_q (interval, a, c); + if (mpfi_cmp_q (interval, b) != 0) { + print_error (b, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_q (interval, b) != 1) { + print_error (b, interval); + } + + mpfi_interv_q (interval, a, b); + cmp = mpfi_cmp_q (interval, c); + if (cmp > 0 || (cmp == 0 && mpq_cmp (c, b) != 0)) { + print_error (c, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_q (interval, c) != 1) { + print_error (c, interval); + } + } + + mpq_clear (a); + mpq_clear (b); + mpq_clear (c); + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tcmp_si.c b/tests/tcmp_si.c new file mode 100644 index 0000000..b1b709a --- /dev/null +++ b/tests/tcmp_si.c @@ -0,0 +1,125 @@ +/* tcmp_si.c -- Test mpfi_cmp_si. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#include "mpfi_config.h" + +#ifdef HAVE_LIMITS_H +#include +#endif + +#ifndef LONG_MAX +# define LONG_MAX 2147483647 +#endif + +#define ORDER(min, max) \ + do { \ + if ((min) > (max)) { \ + long tmp; \ + tmp = (min); \ + (min) = (max); \ + (max) = tmp;} \ + } while (0) + +void +print_error (long x, mpfi_srcptr i) +{ + printf ("Error: mpfi_cmp_si (x, I) returns %d\nx = %ld\nI = ", + mpfi_cmp_si (i, x), x); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t interval; + long a, b, c; + int cmp; + int i; + + i = 1; + a = LONG_MAX; + while (a >>= 1) i++; + + mpfi_init2 (interval, i); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + a = random_si (); + b = random_si (); + c = random_si (); + ORDER (a, b); + ORDER (a, c); + ORDER (b, c); + + mpfi_interv_si (interval, b, c); + cmp = mpfi_cmp_si (interval, a); + if (cmp < 0 || (cmp == 0 && a != b)) { + print_error (a, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_si (interval, a) != 1) { + print_error (a, interval); + } + + mpfi_interv_si (interval, a, c); + if (mpfi_cmp_si (interval, b) != 0) { + print_error (b, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_si (interval, b) != 1) { + print_error (b, interval); + } + + mpfi_interv_si (interval, a, b); + cmp = mpfi_cmp_si (interval, c); + if (cmp > 0 || (cmp == 0 && c != b)) { + print_error (c, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_si (interval, c) != 1) { + print_error (c, interval); + } + } + + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tcmp_ui.c b/tests/tcmp_ui.c new file mode 100644 index 0000000..9e8be78 --- /dev/null +++ b/tests/tcmp_ui.c @@ -0,0 +1,125 @@ +/* tcmp_ui.c -- Test mpfi_cmp_ui. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#include "mpfi_config.h" + +#ifdef HAVE_LIMITS_H +#include +#endif + +#ifndef ULONG_MAX +# define ULONG_MAX 4294967295 +#endif + +#define ORDER(min, max) \ + do { \ + if (min > max) { \ + unsigned long tmp; \ + tmp = min; \ + min = max; \ + max = tmp;} \ + } while (0) + +void +print_error (unsigned long x, mpfi_srcptr i) +{ + printf ("Error: mpfi_cmp_ui (x, I) returns %d\nx = %lu\nI = ", + mpfi_cmp_ui (i, x), x); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t interval; + unsigned long a, b, c; + int cmp; + int i; + + i = 1; + a = ULONG_MAX; + while (a >>= 1) i++; + + mpfi_init2 (interval, i); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + a = random_ui (); + b = random_ui (); + c = random_ui (); + ORDER (a, b); + ORDER (a, c); + ORDER (b, c); + + mpfi_interv_ui (interval, b, c); + cmp = mpfi_cmp_ui (interval, a); + if (cmp < 0 || (cmp == 0 && a != b)) { + print_error (a, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_ui (interval, a) != 1) { + print_error (a, interval); + } + + mpfi_interv_ui (interval, a, c); + if (mpfi_cmp_ui (interval, b) != 0) { + print_error (b, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_ui (interval, b) != 1) { + print_error (b, interval); + } + + mpfi_interv_ui (interval, a, b); + cmp = mpfi_cmp_ui (interval, c); + if (cmp > 0 || (cmp == 0 && c != b)) { + print_error (c, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_ui (interval, c) != 1) { + print_error (c, interval); + } + } + + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tcmp_z.c b/tests/tcmp_z.c new file mode 100644 index 0000000..11990ca --- /dev/null +++ b/tests/tcmp_z.c @@ -0,0 +1,116 @@ +/* tcmp_z.c -- Test mpfi_cmp_z. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#define ORDER(min, max) \ + do { \ + if (mpz_cmp ((min), (max)) > 0) \ + mpz_swap ((min), (max)); \ + } while (0) + +void +print_error (mpz_ptr x, mpfi_srcptr i) +{ + printf ("Error: mpfi_cmp_z (x, I) returns %d\nx = ", + mpfi_cmp_z (i, x)); + mpz_out_str (stdout, 10, x); + printf ("\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t interval; + mpz_t a, b, c; + int cmp; + int i; + + mpz_init (a); + mpz_init (b); + mpz_init (c); + mpfi_init2 (interval, 53); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + random_mpz (a, 100000); + random_mpz (b, 100000); + random_mpz (c, 100000); + ORDER (a, b); + ORDER (a, c); + ORDER (b, c); + + mpfi_interv_z (interval, b, c); + cmp = mpfi_cmp_z (interval, a); + if (cmp < 0 || (cmp == 0 && mpz_cmp (a, b) != 0)) { + print_error (a, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_z (interval, a) != 1) { + print_error (a, interval); + } + + mpfi_interv_z (interval, a, c); + if (mpfi_cmp_z (interval, b) != 0) { + print_error (b, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_z (interval, b) != 1) { + print_error (b, interval); + } + + mpfi_interv_z (interval, a, b); + cmp = mpfi_cmp_z (interval, c); + if (cmp > 0 || (cmp == 0 && mpz_cmp (c, b) != 0)) { + print_error (c, interval); + } + mpfr_set_nan (&(interval->right)); + if (mpfi_cmp_z (interval, c) != 1) { + print_error (c, interval); + } + } + + mpz_clear (a); + mpz_clear (b); + mpz_clear (c); + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tconst_catalan.c b/tests/tconst_catalan.c new file mode 100644 index 0000000..ac24806 --- /dev/null +++ b/tests/tconst_catalan.c @@ -0,0 +1,41 @@ +/* tconst_catalan.c -- Test mpfi_const_catalan. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_catalan; + + mpfi_fun_init_I (&i_catalan, mpfi_const_catalan, mpfr_const_catalan); + + check_data (&i_catalan, "const_catalan.dat"); + + mpfi_fun_clear (&i_catalan); + + return 0; +} diff --git a/tests/tconst_euler.c b/tests/tconst_euler.c new file mode 100644 index 0000000..359a203 --- /dev/null +++ b/tests/tconst_euler.c @@ -0,0 +1,41 @@ +/* tconst_euler.c -- Test mpfi_const_euler. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_euler; + + mpfi_fun_init_I (&i_euler, mpfi_const_euler, mpfr_const_euler); + + check_data (&i_euler, "const_euler.dat"); + + mpfi_fun_clear (&i_euler); + + return 0; +} diff --git a/tests/tconst_log2.c b/tests/tconst_log2.c new file mode 100644 index 0000000..72d18b6 --- /dev/null +++ b/tests/tconst_log2.c @@ -0,0 +1,41 @@ +/* tconst_log2.c -- Test mpfi_const_log2. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_log2; + + mpfi_fun_init_I (&i_log2, mpfi_const_log2, mpfr_const_log2); + + check_data (&i_log2, "const_log2.dat"); + + mpfi_fun_clear (&i_log2); + + return 0; +} diff --git a/tests/tconst_pi.c b/tests/tconst_pi.c new file mode 100644 index 0000000..5f5ad68 --- /dev/null +++ b/tests/tconst_pi.c @@ -0,0 +1,41 @@ +/* tconst_pi.c -- Test mpfi_const_pi. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_pi; + + mpfi_fun_init_I (&i_pi, mpfi_const_pi, mpfr_const_pi); + + check_data (&i_pi, "const_pi.dat"); + + mpfi_fun_clear (&i_pi); + + return 0; +} diff --git a/tests/tcos.c b/tests/tcos.c new file mode 100644 index 0000000..de9d0ae --- /dev/null +++ b/tests/tcos.c @@ -0,0 +1,60 @@ +/* tcos.c -- Test mpfi_cos. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +restrict_domain (mpfi_ptr a) +{ + /* speedup some tests restricting the possible random values */ + if (mpfr_cmp_si (&(a->left), -7) < 0 || mpfr_cmp_si (&(a->left), +7) > 0) { + mpfr_set_si (&(a->left), -7, MPFI_RNDD); + } + if (mpfr_cmp_si (&(a->right), -7) < 0 + || mpfr_cmp_si (&(a->right), +7) > 0) { + mpfr_set_si (&(a->right), 7, MPFI_RNDU); + } + return 0; +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_cos; + + mpfi_fun_init_II (&i_cos, mpfi_cos, mpfr_cos); + mpfi_restrict_random (&i_cos, restrict_domain); + + test_start (); + + check_data (&i_cos, "cos.dat"); + check_random (&i_cos, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_cos); + + return 0; +} diff --git a/tests/tcosh.c b/tests/tcosh.c new file mode 100644 index 0000000..fb6e2d3 --- /dev/null +++ b/tests/tcosh.c @@ -0,0 +1,44 @@ +/* tcosh.c -- Test mpfi_cosh. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_cosh; + + mpfi_fun_init_II (&i_cosh, mpfi_cosh, mpfr_cosh); + test_start (); + + check_data (&i_cosh, "cosh.dat"); + check_random (&i_cosh, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_cosh); + + return 0; +} diff --git a/tests/tcot.c b/tests/tcot.c new file mode 100644 index 0000000..0efb4f3 --- /dev/null +++ b/tests/tcot.c @@ -0,0 +1,60 @@ +/* tcot.c -- Test mpfi_cot. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +restrict_domain (mpfi_ptr a) +{ + /* speedup some tests restricting the possible random values */ + if (mpfr_cmp_si (&(a->left), -7) < 0 || mpfr_cmp_si (&(a->left), +7) > 0) { + mpfr_set_si (&(a->left), -7, MPFI_RNDD); + } + if (mpfr_cmp_si (&(a->right), -7) < 0 + || mpfr_cmp_si (&(a->right), +7) > 0) { + mpfr_set_si (&(a->right), 7, MPFI_RNDU); + } + return 0; +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_cot; + + mpfi_fun_init_II (&i_cot, mpfi_cot, mpfr_cot); + mpfi_restrict_random (&i_cot, restrict_domain); + + test_start (); + + check_data (&i_cot, "cot.dat"); + check_random (&i_cot, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_cot); + + return 0; +} diff --git a/tests/tcoth.c b/tests/tcoth.c new file mode 100644 index 0000000..751848d --- /dev/null +++ b/tests/tcoth.c @@ -0,0 +1,44 @@ +/* tcoth.c -- Test mpfi_coth. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_coth; + + mpfi_fun_init_II (&i_coth, mpfi_coth, mpfr_coth); + test_start (); + + check_data (&i_coth, "coth.dat"); + check_random (&i_coth, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_coth); + + return 0; +} diff --git a/tests/tcsc.c b/tests/tcsc.c new file mode 100644 index 0000000..8a7de1b --- /dev/null +++ b/tests/tcsc.c @@ -0,0 +1,60 @@ +/* tcsc.c -- Test mpfi_csc. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +restrict_domain (mpfi_ptr a) +{ + /* speedup some tests restricting the possible random values */ + if (mpfr_cmp_si (&(a->left), -7) < 0 || mpfr_cmp_si (&(a->left), +7) > 0) { + mpfr_set_si (&(a->left), -7, MPFI_RNDD); + } + if (mpfr_cmp_si (&(a->right), -7) < 0 + || mpfr_cmp_si (&(a->right), +7) > 0) { + mpfr_set_si (&(a->right), 7, MPFI_RNDU); + } + return 0; +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_csc; + + mpfi_fun_init_II (&i_csc, mpfi_csc, mpfr_csc); + mpfi_restrict_random (&i_csc, restrict_domain); + + test_start (); + + check_data (&i_csc, "csc.dat"); + check_random (&i_csc, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_csc); + + return 0; +} diff --git a/tests/tcsch.c b/tests/tcsch.c new file mode 100644 index 0000000..2ec0964 --- /dev/null +++ b/tests/tcsch.c @@ -0,0 +1,44 @@ +/* tcsch.c -- Test mpfi_csch. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_csch; + + mpfi_fun_init_II (&i_csch, mpfi_csch, mpfr_csch); + test_start (); + + check_data (&i_csch, "csch.dat"); + check_random (&i_csch, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_csch); + + return 0; +} diff --git a/tests/td_div.c b/tests/td_div.c new file mode 100644 index 0000000..dd93e0b --- /dev/null +++ b/tests/td_div.c @@ -0,0 +1,125 @@ +/* td_div.c -- Test mpfi_d_div. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow (void) +{ + mpfi_t interval; + mpfi_t got; + double d = 1024.0; + int inex; + + mpfi_init2 (interval, 53); + mpfi_init2 (got, 53); + + /* right overflow: 1024.0 / [epsilon, 1] = [1024, +oo] */ + mpfr_set_ui (&(interval->left), 0, MPFI_RNDD); + mpfr_nextabove (&(interval->left)); /* tiny left endpoint x0 */ + mpfr_set_ui (&(interval->right), 1, MPFI_RNDU); + + inex = mpfi_d_div (got, d, interval); + if (MPFI_LEFT_IS_INEXACT (inex) || mpfr_cmp_ui (&(got->left), 1024) != 0 + || !MPFI_RIGHT_IS_INEXACT (inex) || !mpfr_inf_p (&(got->right))) { + printf ("Error: mpfi_d_div (rop, %g, op) does not correctly handle " + "overflow.\nop = ", d); + mpfi_out_str (stdout, 10, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + /* left overflow: 1024.0 / [-1, -epsilon] = [-oo, -1024] */ + mpfi_neg (interval, interval); + + inex = mpfi_d_div (got, d, interval); + if (!MPFI_LEFT_IS_INEXACT (inex) + || !mpfr_inf_p (&(got->left)) + || MPFI_RIGHT_IS_INEXACT (inex) + || mpfr_cmp_si (&(got->right), -1024) != 0) { + printf ("Error: mpfi_d_div (rop, %g, op) does not correctly handle " + "overflow.\nop = ", d); + mpfi_out_str (stdout, 10, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + mpfi_clear (interval); + mpfi_clear (got); +} + +void +check_nan () +{ + double nan; + mpfi_t got, interval; + int inex; + + nan = 0.0/0.0; + if (nan == nan) + return; + + mpfi_init2 (got, 53); + mpfi_init2 (interval, 53); + + mpfi_set_ui (interval, 10); + inex = mpfi_d_div (got, nan, interval); + if (!MPFI_BOTH_ARE_EXACT (inex) || !MPFI_NAN_P (got)) { + printf ("Error in mpfi_d_div (rop, %g, op).\nop = ", nan); + mpfi_out_str (stdout, 10, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nreturn value = %d\n", inex); + + exit (1); + } + + mpfi_clear (got); + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_d_div; + + mpfi_fun_init_IDI (&i_d_div, mpfi_d_div, mpfr_d_div); + test_start (); + + check_data (&i_d_div, "d_div.dat"); + check_random (&i_d_div, 2, 1000, 10); + check_overflow (); + check_nan (); + + test_end (); + mpfi_fun_clear (&i_d_div); + + return 0; +} diff --git a/tests/td_sub.c b/tests/td_sub.c new file mode 100644 index 0000000..4a2f245 --- /dev/null +++ b/tests/td_sub.c @@ -0,0 +1,98 @@ +/* td_sub.c -- Test mpfi_d_sub. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfi_t got; + mpfi_t op; + double d; + int inexact; + + mpfi_init2 (got, 53); + mpfi_init2 (op, 53); + + d = -1024.0; + mpfr_set_ui (&(op->left), 1, MPFI_RNDD); + mpfr_set_inf (&(op->right), +1); + mpfr_nextbelow (&(op->right)); + + inexact = mpfi_d_sub (got, d, op); + + if (!MPFI_LEFT_IS_INEXACT (inexact) + || !mpfr_inf_p (&(got->left)) + || MPFI_RIGHT_IS_INEXACT (inexact) + || mpfr_cmp_d (&(got->right), d - 1) != 0) { + printf ("Error: mpfi_d_div (rop, %g, op) does not correctly handle " + "overflow.\n op = ", d); + mpfi_out_str (stdout, 10, 0, op); + printf ("\nrop = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nreturn value = %d\n", inexact); + exit (1); + } + + d = +1024.0; + mpfi_neg (op, op); + + inexact = mpfi_d_sub (got, d, op); + + if (MPFI_LEFT_IS_INEXACT (inexact) + || mpfr_cmp_d (&(got->left), d + 1) != 0 + || !MPFI_RIGHT_IS_INEXACT (inexact) + || !mpfr_inf_p (&(got->right))) { + printf ("Error: mpfi_d_div (rop, %g, op) does not correctly handle " + "overflow.\n op = ", d); + mpfi_out_str (stdout, 10, 0, op); + printf ("\nrop = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nreturn value = %d\n", inexact); + exit (1); + } + + mpfi_clear (op); + mpfi_clear (got); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_d_sub; + + mpfi_fun_init_IDI (&i_d_sub, mpfi_d_sub, mpfr_d_sub); + test_start (); + + check_data (&i_d_sub, "d_sub.dat"); + check_random (&i_d_sub, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_d_sub); + + return 0; +} diff --git a/tests/tdiam.c b/tests/tdiam.c new file mode 100644 index 0000000..7afdad2 --- /dev/null +++ b/tests/tdiam.c @@ -0,0 +1,41 @@ +/* tdiam.c -- Test mpfi_diam. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_diam; + + mpfi_fun_init_RI (&i_diam, mpfi_diam, NULL); + + check_data (&i_diam, "diam.dat"); + + mpfi_fun_clear (&i_diam); + + return 0; +} diff --git a/tests/tdiam_abs.c b/tests/tdiam_abs.c new file mode 100644 index 0000000..ef2d820 --- /dev/null +++ b/tests/tdiam_abs.c @@ -0,0 +1,41 @@ +/* tdiam_abs.c -- Test mpfi_diam_abs. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_diam_abs; + + mpfi_fun_init_RI (&i_diam_abs, mpfi_diam_abs, NULL); + + check_data (&i_diam_abs, "diam_abs.dat"); + + mpfi_fun_clear (&i_diam_abs); + + return 0; +} diff --git a/tests/tdiam_rel.c b/tests/tdiam_rel.c new file mode 100644 index 0000000..0b3fa89 --- /dev/null +++ b/tests/tdiam_rel.c @@ -0,0 +1,41 @@ +/* tdiam_rel.c -- Test mpfi_diam_rel. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_diam_rel; + + mpfi_fun_init_RI (&i_diam_rel, mpfi_diam_rel, NULL); + + check_data (&i_diam_rel, "diam_rel.dat"); + + mpfi_fun_clear (&i_diam_rel); + + return 0; +} diff --git a/tests/tdiv.c b/tests/tdiv.c new file mode 100644 index 0000000..4ebf0e8 --- /dev/null +++ b/tests/tdiv.c @@ -0,0 +1,45 @@ +/* tdiv.c -- Test mpfi_div. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_div; + + mpfi_fun_init_III (&i_div, mpfi_div, mpfr_div); + + test_start (); + + check_data (&i_div, "div.dat"); + check_random (&i_div, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_div); + + return 0; +} diff --git a/tests/tdiv_2exp.c b/tests/tdiv_2exp.c new file mode 100644 index 0000000..67f7d3d --- /dev/null +++ b/tests/tdiv_2exp.c @@ -0,0 +1,45 @@ +/* tdiv_2exp.c -- Test mpfi_div_2exp. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_div_2exp; + + mpfi_fun_init_IIU (&i_div_2exp, mpfi_div_2exp, mpfr_div_2exp); + + test_start (); + + check_data (&i_div_2exp, "div_2ui.dat"); + check_random (&i_div_2exp, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_div_2exp); + + return 0; +} diff --git a/tests/tdiv_2si.c b/tests/tdiv_2si.c new file mode 100644 index 0000000..c09f0cb --- /dev/null +++ b/tests/tdiv_2si.c @@ -0,0 +1,45 @@ +/* tdiv_2si.c -- Test mpfi_div_2si. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_div_2si; + + mpfi_fun_init_IIS (&i_div_2si, mpfi_div_2si, mpfr_div_2si); + + test_start (); + + check_data (&i_div_2si, "div_2si.dat"); + check_random (&i_div_2si, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_div_2si); + + return 0; +} diff --git a/tests/tdiv_2ui.c b/tests/tdiv_2ui.c new file mode 100644 index 0000000..1d6555f --- /dev/null +++ b/tests/tdiv_2ui.c @@ -0,0 +1,45 @@ +/* tdiv_2ui.c -- Test mpfi_div_2ui. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_div_2ui; + + mpfi_fun_init_IIU (&i_div_2ui, mpfi_div_2ui, mpfr_div_2ui); + + test_start (); + + check_data (&i_div_2ui, "div_2ui.dat"); + check_random (&i_div_2ui, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_div_2ui); + + return 0; +} diff --git a/tests/tdiv_d.c b/tests/tdiv_d.c new file mode 100644 index 0000000..435ef43 --- /dev/null +++ b/tests/tdiv_d.c @@ -0,0 +1,136 @@ +/* tdiv_d.c -- Test mpfi_div_d. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_div_d (a, a, 0.5); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_div_d does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_div_d does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_div_d (a, a, 0.5); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_div_d does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_div_d does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); +} + +void +check_underflow (void) +{ + mpfi_t got, expected; + double d = 0x1p+100; + int inex; + + mpfi_init2 (got, 128); + mpfi_init2 (expected, 128); + + mpfi_set_ui (expected, 0); + mpfr_nextbelow (&(expected->left)); + mpfr_nextabove (&(expected->right)); + + inex = mpfi_div_d (got, expected, d); + if (!MPFI_BOTH_ARE_INEXACT(inex) + || !same_mpfr_value (&(got->left), &(expected->left)) + || !same_mpfr_value (&(got->right), &(expected->right))) { + printf ("Error: mpfi_div_d (rop, op, d) does not return correct value\n" + "op = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\nd = %a\ngot = ", d); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\n"); + + if (!MPFI_BOTH_ARE_INEXACT(inex)) { + printf ("return value = %d\nexpected = %d\n", inex, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + } + + exit (1); + } + + mpfi_clear (got); + mpfi_clear (expected); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_div_d; + + mpfi_fun_init_IID (&i_div_d, mpfi_div_d, mpfr_div_d); + test_start (); + + check_data (&i_div_d, "div_d.dat"); + check_random (&i_div_d, 2, 1000, 10); + check_overflow (); + check_underflow (); + + test_end (); + mpfi_fun_clear (&i_div_d); + + return 0; +} diff --git a/tests/tdiv_fr.c b/tests/tdiv_fr.c new file mode 100644 index 0000000..ea1fbf6 --- /dev/null +++ b/tests/tdiv_fr.c @@ -0,0 +1,145 @@ +/* tdiv_fr.c -- Test mpfi_div_fr. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfr_t x; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_init2 (x, 53); + mpfr_set_ui_2exp (x, 1, -1024, MPFI_RNDD); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_div_fr (a, a, x); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_div_fr does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_div_fr does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_div_fr (a, a, x); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_div_fr does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_div_fr does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); + mpfr_clear (x); +} + +void +check_underflow (void) +{ + mpfi_t got, expected; + mpfr_t x; + int inex; + + mpfr_init2 (x, 128); + mpfi_init2 (got, 128); + mpfi_init2 (expected, 128); + + mpfr_set_ui_2exp (x, 1, 1024, MPFI_RNDD); + mpfi_set_ui (expected, 0); + mpfr_nextbelow (&(expected->left)); + mpfr_nextabove (&(expected->right)); + + inex = mpfi_div_fr (got, expected, x); + if (!MPFI_BOTH_ARE_INEXACT(inex) + || !same_mpfr_value (&(got->left), &(expected->left)) + || !same_mpfr_value (&(got->right), &(expected->right))) { + printf ("Error: mpfi_div_fr (rop, op, x) does not return correct value\n" + "op = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\nx = "); + mpfr_out_str (stdout, 16, 0, x, MPFI_RNDD); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\n"); + + if (!MPFI_BOTH_ARE_INEXACT(inex)) { + printf ("return value = %d\nexpected = %d\n", inex, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + } + + exit (1); + } + + mpfr_clear (x); + mpfi_clear (got); + mpfi_clear (expected); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_div_fr; + + mpfi_fun_init_IIR (&i_div_fr, mpfi_div_fr, mpfr_div); + test_start (); + + check_data (&i_div_fr, "div_fr.dat"); + check_random (&i_div_fr, 2, 1000, 10); + check_overflow (); + check_underflow (); + + test_end (); + mpfi_fun_clear (&i_div_fr); + + return 0; +} diff --git a/tests/tdiv_q.c b/tests/tdiv_q.c new file mode 100644 index 0000000..22730ef --- /dev/null +++ b/tests/tdiv_q.c @@ -0,0 +1,184 @@ +/* tdiv_q.c -- Test mpfi_div_q. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + mpq_t q; + int inexact; + + mpq_init (q); + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set (&(a->right), max, MPFI_RNDU); + mpq_set_ui (q, 3, 4); + + inexact = mpfi_div_q (a, a, q); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error[1]: mpfi_div_q does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error[1]: mpfi_div_q does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set (&(a->right), max, MPFI_RNDU); + mpq_set_si (q, -3, 4); + + inexact = mpfi_div_q (a, a, q); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error[2]: mpfi_div_q does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error[2]: mpfi_div_q does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + mpq_set_ui (q, 3, 4); + + inexact = mpfi_div_q (a, a, q); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error[3]: mpfi_div_q does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error[3]: mpfi_div_q does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + mpq_set_si (q, -3, 4); + + inexact = mpfi_div_q (a, a, q); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error[4]: mpfi_div_q does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error[4]: mpfi_div_q does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpq_clear (q); + mpfi_clear (a); + mpfr_clear (max); +} + +void +check_underflow (void) +{ + mpfi_t got, expected; + mpq_t q; + int inex; + + mpq_init (q); + mpfi_init2 (got, 128); + mpfi_init2 (expected, 128); + + mpq_set_ui (q, 4096, 3); + mpfi_set_ui (expected, 0); + mpfr_nextbelow (&(expected->left)); + mpfr_nextabove (&(expected->right)); + + inex = mpfi_div_q (got, expected, q); + if (!MPFI_BOTH_ARE_INEXACT(inex) + || !same_mpfr_value (&(got->left), &(expected->left)) + || !same_mpfr_value (&(got->right), &(expected->right))) { + printf ("Error: mpfi_div_q (rop, op, q) does not return correct value\n" + "op = "); + mpfi_out_str (stdout, 10, 0, expected); + printf ("\nq = "); + mpq_out_str (stdout, 10, q); + printf ("\ngot = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 10, 0, expected); + printf ("\n"); + + if (!MPFI_BOTH_ARE_INEXACT(inex)) { + printf ("return value = %d\nexpected = %d\n", inex, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + } + + exit (1); + } + + mpq_clear (q); + mpfi_clear (got); + mpfi_clear (expected); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_div_q; + + mpfi_fun_init_IIQ (&i_div_q, mpfi_div_q, mpfr_div_q); + test_start (); + + check_data (&i_div_q, "div_q.dat"); + check_random (&i_div_q, 2, 1000, 10); + check_overflow (); + check_underflow (); + + test_end (); + mpfi_fun_clear (&i_div_q); + + return 0; +} diff --git a/tests/tdiv_si.c b/tests/tdiv_si.c new file mode 100644 index 0000000..a86cd4e --- /dev/null +++ b/tests/tdiv_si.c @@ -0,0 +1,85 @@ +/* tdiv_si.c -- Test mpfi_div_si. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_underflow (void) +{ + mpfi_t got, expected; + long si = 1024; + int inex; + + mpfi_init2 (got, 128); + mpfi_init2 (expected, 128); + + mpfi_set_ui (expected, 0); + mpfr_nextbelow (&(expected->left)); + mpfr_nextabove (&(expected->right)); + + inex = mpfi_div_si (got, expected, si); + if (!MPFI_BOTH_ARE_INEXACT(inex) + || !same_mpfr_value (&(got->left), &(expected->left)) + || !same_mpfr_value (&(got->right), &(expected->right))) { + printf ("Error: mpfi_div_si (rop, op, si) does not return correct value\n" + "op = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\nsi = %ld\ngot = ", si); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\n"); + + if (!MPFI_BOTH_ARE_INEXACT(inex)) { + printf ("return value = %d\nexpected = %d\n", inex, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + } + + exit (1); + } + + mpfi_clear (got); + mpfi_clear (expected); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_div_si; + + mpfi_fun_init_IIS (&i_div_si, mpfi_div_si, mpfr_div_si); + + test_start (); + + check_data (&i_div_si, "div_si.dat"); + check_random (&i_div_si, 2, 1000, 10); + check_underflow (); + + test_end (); + mpfi_fun_clear (&i_div_si); + + return 0; +} diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c new file mode 100644 index 0000000..86f2867 --- /dev/null +++ b/tests/tdiv_ui.c @@ -0,0 +1,85 @@ +/* tdiv_ui.c -- Test mpfi_div_ui. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_underflow (void) +{ + mpfi_t got, expected; + unsigned long ui = 1024; + int inex; + + mpfi_init2 (got, 128); + mpfi_init2 (expected, 128); + + mpfi_set_ui (expected, 0); + mpfr_nextbelow (&(expected->left)); + mpfr_nextabove (&(expected->right)); + + inex = mpfi_div_ui (got, expected, ui); + if (!MPFI_BOTH_ARE_INEXACT(inex) + || !same_mpfr_value (&(got->left), &(expected->left)) + || !same_mpfr_value (&(got->right), &(expected->right))) { + printf ("Error: mpfi_div_ui (rop, op, ui) does not return correct value\n" + "op = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\nui = %lu\ngot = ", ui); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\n"); + + if (!MPFI_BOTH_ARE_INEXACT(inex)) { + printf ("return value = %d\nexpected = %d\n", inex, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + } + + exit (1); + } + + mpfi_clear (got); + mpfi_clear (expected); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_div_ui; + + mpfi_fun_init_IIU (&i_div_ui, mpfi_div_ui, mpfr_div_ui); + + test_start (); + + check_data (&i_div_ui, "div_ui.dat"); + check_random (&i_div_ui, 2, 1000, 10); + check_underflow (); + + test_end (); + mpfi_fun_clear (&i_div_ui); + + return 0; +} diff --git a/tests/tdiv_z.c b/tests/tdiv_z.c new file mode 100644 index 0000000..00b13c4 --- /dev/null +++ b/tests/tdiv_z.c @@ -0,0 +1,88 @@ +/* tdiv_z.c -- Test mpfi_div_z. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_underflow (void) +{ + mpfi_t got, expected; + mpz_t z; + int inex; + + mpz_init (z); + mpfi_init2 (got, 128); + mpfi_init2 (expected, 128); + + mpz_set_ui (z, 1024); + mpfi_set_ui (expected, 0); + mpfr_nextbelow (&(expected->left)); + mpfr_nextabove (&(expected->right)); + + inex = mpfi_div_z (got, expected, z); + if (!MPFI_BOTH_ARE_INEXACT(inex) + || !same_mpfr_value (&(got->left), &(expected->left)) + || !same_mpfr_value (&(got->right), &(expected->right))) { + printf ("Error: mpfi_div_z (rop, op, z) does not return correct value\n" + "op = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\nz = "); + mpz_out_str (stdout, 16, z); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\n"); + + if (!MPFI_BOTH_ARE_INEXACT(inex)) { + printf ("return value = %d\nexpected = %d\n", inex, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + } + + exit (1); + } + + mpz_clear (z); + mpfi_clear (got); + mpfi_clear (expected); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_div_z; + + mpfi_fun_init_IIZ (&i_div_z, mpfi_div_z, mpfr_div_z); + test_start (); + + check_data (&i_div_z, "div_z.dat"); + check_random (&i_div_z, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_div_z); + + return 0; +} diff --git a/tests/terror.c b/tests/terror.c new file mode 100644 index 0000000..5741365 --- /dev/null +++ b/tests/terror.c @@ -0,0 +1,142 @@ +/* terror.c -- Frightening test of error handling. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#include "mpfi_config.h" + +#ifdef HAVE_UNISTD_H +#include +#endif + +int +read_stderr (FILE *stream) +{ + int ret = 0; + + /* something to read? */ + ret = (fgetc (stream) != EOF); + if (fseek (stream, 0, SEEK_END) != 0) { + printf ("Internal error: cannot reset stream.\n"); + exit (1); + } + + return ret; +} + +int +main (int argc, char **argv) +{ + FILE *stream; + + if (freopen ("error.tmp", "w", stderr) == NULL) { + printf ("Internal error: cannot redirect stderr to a file.\n"); + exit (1); + } + stream = fopen ("error.tmp", "r"); + if (stream == NULL) { + printf ("Internal error: cannot open the file \"error.tmp\".\n"); + exit (1); + } + + mpfi_reset_error (); + if (mpfi_is_error () == 1) { + printf ("Error: mpfi_is_error() returns 1 after a call to " + "mpfi_reset_error.\n"); + exit (1); + } + + MPFI_ERROR ("[1] this should be printed!"); + fflush (stderr); + if (!read_stderr (stream)) { + printf ("Error: MPFI_ERROR does not print message after a call to " + "mpfi_reset_error.\n"); + exit (1); + } + if (mpfi_is_error () != 1) { + printf ("Error: mpfi_is_error does not set return 1 after a call to " + "MPFI_ERROR.\n"); + exit (1); + } + + mpfi_set_error (2); + if (mpfi_is_error () == 1) { + printf ("Error: mpfi_is_error() returns 1 after calling " + "mpfi_set_error(2).\n"); + exit (1); + } + MPFI_ERROR ("[2] this should not be printed!"); + fflush (stderr); + if (read_stderr (stream)) { + printf ("Error: MPFI_ERROR prints a message while error number is " + "set.\n"); + exit (1); + } + if (mpfi_is_error () == 1) { + printf ("Error: MPFI_ERROR set error number to 1 while it was already " + "set.\n"); + exit (1); + } + + mpfi_set_error (1); + if (mpfi_is_error () != 1) { + printf ("Error: mpfi_is_error() does not return 1 after calling " + "mpfi_set_error(1).\n"); + exit (1); + } + MPFI_ERROR ("[3] this should not be printed!"); + fflush (stderr); + if (read_stderr (stream)) { + printf ("Error: MPFI_ERROR prints a message while error number is " + "set.\n"); + exit (1); + } + + mpfi_reset_error (); + if (mpfi_is_error () == 1) { + printf ("Error: mpfi_is_error() returns 1 after a call to " + "mpfi_reset_error.\n"); + exit (1); + } + MPFI_ERROR ("[4] this should be printed!"); + fflush (stderr); + if (!read_stderr (stream)) { + printf ("Error: MPFI_ERROR does not print message after a call to " + "mpfi_reset_error.\n"); + exit (1); + } + if (mpfi_is_error () != 1) { + printf ("Error: MPFI_ERROR dos not set error number to 1 after a call to " + "mpfi_reset_error.\n"); + exit (1); + } + + fclose (stream); + fclose (stderr); + unlink ("error.tmp"); + + return 0; +} diff --git a/tests/texp.c b/tests/texp.c new file mode 100644 index 0000000..55bcf77 --- /dev/null +++ b/tests/texp.c @@ -0,0 +1,44 @@ +/* texp.c -- Test mpfi_exp. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_exp; + + mpfi_fun_init_II (&i_exp, mpfi_exp, mpfr_exp); + test_start (); + + check_data (&i_exp, "exp.dat"); + check_random (&i_exp, 2, 512, 10); + + test_end (); + mpfi_fun_clear (&i_exp); + + return 0; +} diff --git a/tests/texp2.c b/tests/texp2.c new file mode 100644 index 0000000..af3361d --- /dev/null +++ b/tests/texp2.c @@ -0,0 +1,44 @@ +/* texp2.c -- Test mpfi_exp2. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_exp2; + + mpfi_fun_init_II (&i_exp2, mpfi_exp2, mpfr_exp2); + test_start (); + + check_data (&i_exp2, "exp2.dat"); + check_random (&i_exp2, 2, 512, 10); + + test_end (); + mpfi_fun_clear (&i_exp2); + + return 0; +} diff --git a/tests/texpm1.c b/tests/texpm1.c new file mode 100644 index 0000000..88e57af --- /dev/null +++ b/tests/texpm1.c @@ -0,0 +1,44 @@ +/* texpm1.c -- Test mpfi_expm1. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_expm1; + + mpfi_fun_init_II (&i_expm1, mpfi_expm1, mpfr_expm1); + test_start (); + + check_data (&i_expm1, "expm1.dat"); + check_random (&i_expm1, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_expm1); + + return 0; +} diff --git a/tests/tfr_div.c b/tests/tfr_div.c new file mode 100644 index 0000000..0b5dee1 --- /dev/null +++ b/tests/tfr_div.c @@ -0,0 +1,143 @@ +/* tfr_div.c -- Test mpfi_fr_div. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow (void) +{ + mpfi_t interval; + mpfi_t got; + mpfr_t x; + int inex; + + mpfi_init2 (interval, 53); + mpfi_init2 (got, 53); + mpfr_init2 (x, 53); + + /* right overflow: 1023 / [epsilon, 1] = [1023, +oo] */ + mpfr_set_ui (x, 1023, MPFI_RNDD); + mpfr_set_ui (&(interval->left), 0, MPFI_RNDD); + mpfr_nextabove (&(interval->left)); /* tiny left endpoint x0 */ + mpfr_set_ui (&(interval->right), 1, MPFI_RNDU); + + inex = mpfi_fr_div (got, x, interval); + + if (MPFI_LEFT_IS_INEXACT (inex) || mpfr_cmp (&(got->left), x) != 0 + || !MPFI_RIGHT_IS_INEXACT (inex) || !mpfr_inf_p (&(got->right))) { + printf ("Error: mpfi_d_div (rop, x, op) does not correctly handle " + "overflow.\n x = "); + mpfr_out_str (stdout, 16, 0, x, MPFI_RNDD); + printf ("\nop = "); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + /* left overflow: 1023 / [-1, -epsilon] = [-oo, -1023] */ + mpfi_neg (interval, interval); + + inex = mpfi_fr_div (got, x, interval); + if (!MPFI_LEFT_IS_INEXACT (inex) + || !mpfr_inf_p (&(got->left)) + || MPFI_RIGHT_IS_INEXACT (inex) + || mpfr_cmp_si (&(got->right), -1023) != 0) { + printf ("Error: mpfi_d_div (rop, x, op) does not correctly handle " + "overflow.\n x = "); + mpfr_out_str (stdout, 16, 0, x, MPFI_RNDD); + printf ("\nop = "); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + mpfr_clear (x); + mpfi_clear (interval); + mpfi_clear (got); +} + +void +check_underflow (void) +{ + mpfi_t interval; + mpfi_t got; + mpfr_t x; + int inex; + + mpfr_init2 (x, 128); + mpfi_init2 (got, 128); + mpfi_init2 (interval, 128); + + mpfr_set_ui (x, 0, MPFI_RNDD); + mpfr_nextabove (x); + mpfi_interv_ui (interval, 1, 1024); + + inex = mpfi_fr_div (got, x, interval); + + if (!MPFI_LEFT_IS_INEXACT (inex) + || !mpfr_zero_p (&(got->left)) + || MPFI_RIGHT_IS_INEXACT (inex) + || mpfr_cmp (&(got->right), x) != 0) { + printf ("Error: mpfi_fr_div (rop, x, op) does not correctly handle " + "overflow.\n x = "); + mpfr_out_str (stdout, 16, 0, x, MPFI_RNDD); + printf ("\nop = "); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("return value = %d\nexpected = %d\n", inex, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + + exit (1); + } + + mpfr_clear (x); + mpfi_clear (got); + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_fr_div; + + mpfi_fun_init_IRI (&i_fr_div, mpfi_fr_div, mpfr_div); + test_start (); + + check_data (&i_fr_div, "fr_div.dat"); + check_random (&i_fr_div, 2, 1000, 10); + check_overflow (); + check_underflow (); + + test_end (); + mpfi_fun_clear (&i_fr_div); + + return 0; +} diff --git a/tests/tfr_sub.c b/tests/tfr_sub.c new file mode 100644 index 0000000..4688ed6 --- /dev/null +++ b/tests/tfr_sub.c @@ -0,0 +1,104 @@ +/* tfr_sub.c -- Test mpfi_fr_sub. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow (void) +{ + mpfi_t interval; + mpfi_t got; + mpfr_t x; + int inex; + + mpfi_init2 (interval, 53); + mpfi_init2 (got, 53); + mpfr_init2 (x, 53); + + /* right overflow: 1023 - [-Max, 0] = [1023, +oo] */ + mpfr_set_ui (x, 1023, MPFI_RNDD); + mpfr_set_inf (&(interval->left), -1); + mpfr_nextabove (&(interval->left)); + mpfr_set_ui (&(interval->right), 0, MPFI_RNDU); + + inex = mpfi_fr_sub (got, x, interval); + + if (MPFI_LEFT_IS_INEXACT (inex) || mpfr_cmp (&(got->left), x) != 0 + || !MPFI_RIGHT_IS_INEXACT (inex) || !mpfr_inf_p (&(got->right))) { + printf ("Error: mpfi_fr_sub (rop, x, op) does not correctly handle " + "overflow.\n x = "); + mpfr_out_str (stdout, 16, 0, x, MPFI_RNDD); + printf ("\nop = "); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + /* left overflow: -1023 - [0, Max] = [-oo, -1023] */ + mpfr_neg (x, x, MPFI_RNDD); + mpfi_neg (interval, interval); + + inex = mpfi_fr_sub (got, x, interval); + + if (!MPFI_LEFT_IS_INEXACT (inex) + || !mpfr_inf_p (&(got->left)) + || MPFI_RIGHT_IS_INEXACT (inex) + || mpfr_cmp_si (&(got->right), -1023) != 0) { + printf ("Error: mpfi_fr_sub (rop, x, op) does not correctly handle " + "overflow.\n x = "); + mpfr_out_str (stdout, 16, 0, x, MPFI_RNDD); + printf ("\nop = "); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + mpfr_clear (x); + mpfi_clear (interval); + mpfi_clear (got); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_fr_sub; + + mpfi_fun_init_IRI (&i_fr_sub, mpfi_fr_sub, mpfr_sub); + test_start (); + + check_data (&i_fr_sub, "fr_sub.dat"); + check_random (&i_fr_sub, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_fr_sub); + + return 0; +} diff --git a/tests/tget_d.c b/tests/tget_d.c new file mode 100644 index 0000000..48f2c66 --- /dev/null +++ b/tests/tget_d.c @@ -0,0 +1,138 @@ +/* tget_d.c -- Test mpfi_get_d. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include +#include "mpfi-tests.h" + +#ifndef isnan +# define isnan(x) ((x) != (x)) +#endif + +#ifndef isinf +# define isinf(x) (!isnan (x) && isnan ((x) - (x))) +#endif + +void +error_message (mpfi_srcptr i, double got, const char *expected) +{ + printf ("Error: mpfi_get_d(x, I) returns wrong value.\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\ngot : %f\nexpected: %s\n", got, expected); + exit (1); +} + +void +test_special () +{ + double got; + mpfi_t i; + + mpfi_init2 (i, 53); + + /* [nan, nan] */ + mpfr_set_nan (&(i->left)); + mpfr_set_nan (&(i->right)); + got = mpfi_get_d (i); + if (!isnan (got)) + error_message (i, got, "NaN"); + + /* [-17, nan] */ + mpfr_set_si (&(i->left), -17, MPFI_RNDD); + got = mpfi_get_d (i); + if (!isnan (got)) + error_message (i, got, "NaN"); + + /* [-inf, -inf] */ + mpfr_set_inf (&(i->left), -1); + mpfr_set_inf (&(i->right), -1); + got = mpfi_get_d (i); + if (!isinf (got) || got > 0) + error_message (i, got, "-infinity"); + + /* [-inf, 17] */ + mpfr_set_ui (&(i->right), 17, MPFI_RNDD); + got = mpfi_get_d (i); + if (!isinf (got) || got > 0) + error_message (i, got, "-infinity"); + + /* [+0, +inf] */ + mpfr_set_ui (&(i->left), 0, MPFI_RNDD); + mpfr_set_inf (&(i->right), +1); + got = mpfi_get_d (i); + if (!isinf (got) || got < 0) + error_message (i, got, "+infinity"); + + /* [+inf, +inf] */ + mpfr_set_inf (&(i->left), +1); + got = mpfi_get_d (i); + if (!isinf (got) || got < 0) + error_message (i, got, "+infinity"); + + /* [-inf, +inf] */ + mpfr_set_inf (&(i->left), -1); + mpfr_set_inf (&(i->right), +1); + got = mpfi_get_d (i); + if (!isnan (got)) + error_message (i, got, "NaN"); + + /* [+0, -0] */ + mpfr_set_ui (&(i->left), 0, MPFI_RNDU); + mpfr_neg (&(i->right), &(i->left), MPFI_RNDD); + got = mpfi_get_d (i); + if (got != 0) + error_message (i, got, "0"); + + mpfi_clear (i); +} + +void +test_regular () +{ + double x; + mpfi_t i; + + /* assume IEEE-754 double */ + mpfi_init2 (i, 100); + + mpfr_set_ui_2exp (&(i->left), 1, -1, MPFI_RNDD); + mpfr_set_ui_2exp (&(i->right), 1, 53, MPFI_RNDU); + mpfr_add_ui (&(i->right), &(i->right), 1, MPFI_RNDU); + x = mpfi_get_d (i); + + if (x != 0x10000000000001P+0) + error_message (i, x, "4503599627370497"); + + mpfi_clear (i); +} + +int +main (int argc, char **argv) +{ + test_special (); + test_regular (); + + return 0; +} diff --git a/tests/tget_endpoints.c b/tests/tget_endpoints.c new file mode 100644 index 0000000..5b8d503 --- /dev/null +++ b/tests/tget_endpoints.c @@ -0,0 +1,209 @@ +/* tget_endpoints.c -- Test mpfi_get_left and mpfi_get_right. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +error_message (int side, mpfi_srcptr i, mpfr_ptr got) +{ + unsigned long pi, pgot; + pi = mpfi_get_prec (i); + pgot = mpfr_get_prec (got); + + printf ("Error: mpfi_get_%s(x, I) returns wrong value.\n" + "Precision_I = %lu. I = ", side ? "right" : "left", pi); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nPrecision_got = %lu. Got: ", pgot); + mpfr_out_str (stdout, 10, 0, got, MPFI_RNDD); + printf ("\n"); + exit (1); +} + +void +test_special () +{ + mpfi_t i; + mpfr_t l, r; + mpfr_t expected; + + mpfi_init2 (i, 53); + mpfr_init2 (l, 53); + mpfr_init2 (r, 53); + mpfr_init2 (expected, 53); + + /* [nan, nan] */ + mpfr_set_nan (expected); + mpfi_set_fr (i, expected); + mpfi_get_left (l, i); + if (!same_mpfr_value (l, expected)) + error_message (0, i, l); + mpfi_get_right (r, i); + if (!same_mpfr_value (r, expected)) + error_message (1, i, r); + + /* [-17, nan] */ + mpfr_set_si (expected, -17, MPFI_RNDD); + mpfr_set (&(i->left), expected, MPFI_RNDD); + mpfi_get_right (r, i); + if (!same_mpfr_value (r, l)) + error_message (1, i, r); + mpfi_get_left (l, i); + if (!same_mpfr_value (l, expected)) + error_message (0, i, l); + + /* [-inf, -inf] */ + mpfr_set_inf (expected, -1); + mpfi_set_fr (i, expected); + mpfi_get_left (l, i); + if (!same_mpfr_value (l, expected)) + error_message (0, i, l); + mpfi_get_right (r, i); + if (!same_mpfr_value (r, expected)) + error_message (1, i, r); + + /* [-inf, 17] */ + mpfr_set_ui (expected, 17, MPFI_RNDU); + mpfr_set (&(i->right), expected, MPFI_RNDU); + mpfi_get_left (l, i); + if (!same_mpfr_value (l, r)) + error_message (0, i, l); + mpfi_get_right (r, i); + if (!same_mpfr_value (r, expected)) + error_message (1, i, r); + + /* [+0, +inf] */ + mpfr_set_ui (&(i->left), 0, MPFI_RNDD); + mpfr_set_inf (expected, +1); + mpfr_set (&(i->right), expected, MPFI_RNDU); + mpfi_get_left (l, i); + if (mpfr_cmp_ui (l, 0) != 0) + error_message (0, i, l); + mpfi_get_right (r, i); + if (!same_mpfr_value (r, expected)) + error_message (1, i, r); + + /* [+inf, +inf] */ + mpfi_set_fr (i, expected); + mpfi_get_left (l, i); + if (!same_mpfr_value (l, expected)) + error_message (0, i, l); + mpfi_get_right (r, i); + if (!same_mpfr_value (r, expected)) + error_message (1, i, r); + + /* [-inf, +inf] */ + mpfr_set_inf (&(i->left), -1); + mpfr_set_inf (&(i->right), +1); + mpfi_get_left (l, i); + mpfr_set_inf (expected, -1); + if (!same_mpfr_value (l, expected)) + error_message (0, i, l); + mpfi_get_right (r, i); + mpfr_set_inf (expected, +1); + if (!same_mpfr_value (r, expected)) + error_message (1, i, r); + + /* [+0, -0] */ + mpfr_set_ui (expected, 0, MPFI_RNDU); + mpfi_set_fr (i, expected); + mpfi_get_left (l, i); + if (!same_mpfr_value (l, expected)) + error_message (0, i, l); + mpfi_get_right (r, i); + mpfr_neg (expected, expected, MPFI_RNDD); + if (!same_mpfr_value (r, expected)) + error_message (1, i, r); + + mpfi_clear (i); + mpfr_clear (l); + mpfr_clear (r); + mpfr_clear (expected); +} + +void +test_regular () +{ + mpfi_t i; + mpfr_t got, expected; + + mpfi_init2 (i, 53); + mpfr_init2 (got, 500); + mpfr_init2 (expected, 53); + + mpfi_interv_ui (i, 3, 5); + mpfi_inv (i, i); + + mpfr_set_ui (expected, 5, MPFI_RNDU); + mpfr_ui_div (expected, 1, expected, MPFI_RNDD); + mpfi_get_left (got, i); + if (!same_mpfr_value (got, expected)) + error_message (0, i, got); + + mpfr_set_prec (got, 53); + mpfi_get_left (got, i); + if (!same_mpfr_value (got, expected)) + error_message (0, i, got); + + mpfr_set_prec (expected, 3); + mpfr_set_prec (got, 3); + mpfr_set_ui (expected, 5, MPFI_RNDU); + mpfr_ui_div (expected, 1, expected, MPFI_RNDD); + mpfi_get_left (got, i); + if (!same_mpfr_value (got, expected)) + error_message (0, i, got); + + mpfr_set_ui (expected, 3, MPFI_RNDD); + mpfr_ui_div (expected, 1, expected, MPFI_RNDU); + mpfi_get_right (got, i); + if (!same_mpfr_value (got, expected)) + error_message (1, i, got); + + mpfr_set_prec (expected, 53); + mpfr_set_prec (got, 53); + mpfr_set_ui (expected, 3, MPFI_RNDD); + mpfr_ui_div (expected, 1, expected, MPFI_RNDU); + mpfi_get_right (got, i); + if (!same_mpfr_value (got, expected)) + error_message (1, i, got); + + mpfr_set_prec (got, 500); + mpfi_get_right (got, i); + if (!same_mpfr_value (got, expected)) + error_message (1, i, got); + + mpfi_clear (i); + mpfr_clear (got); + mpfr_clear (expected); +} + +int +main (int argc, char **argv) +{ + test_special (); + test_regular (); + + return 0; +} diff --git a/tests/tget_fr.c b/tests/tget_fr.c new file mode 100644 index 0000000..3648047 --- /dev/null +++ b/tests/tget_fr.c @@ -0,0 +1,157 @@ +/* tget_fr.c -- Test mpfi_get_fr. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +error_message (mpfi_srcptr i, mpfr_ptr got, mpfr_ptr expected) +{ + printf ("Error: mpfi_get_fr(x, I) returns wrong value.\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nGot: "); + mpfr_out_str (stdout, 10, 0, got, MPFI_RNDD); + printf ("\nExpected: "); + mpfr_out_str (stdout, 10, 0, expected, MPFI_RNDD); + printf ("\n"); + exit (1); +} + +void +test_special () +{ + mpfr_t expected, got; + mpfi_t i; + + mpfr_init2 (expected, 53); + mpfr_init2 (got, 53); + mpfi_init2 (i, 53); + + /* [nan, nan] */ + mpfr_set_nan (expected); + mpfi_set_fr (i, expected); + mpfi_get_fr (got, i); + if (!same_mpfr_value (expected, got)) + error_message (i, got, expected); + + /* [-17, nan] */ + mpfr_set_si (&(i->left), -17, MPFI_RNDD); + mpfi_get_fr (got, i); + if (!same_mpfr_value (expected, got)) + error_message (i, got, expected); + + /* [-inf, -inf] */ + mpfr_set_inf (expected, -1); + mpfi_set_fr (i, expected); + mpfi_get_fr (got, i); + if (!same_mpfr_value (expected, got)) + error_message (i, got, expected); + + /* [-inf, 17] */ + mpfr_set_ui (&(i->right), 17, MPFI_RNDD); + mpfi_get_fr (got, i); + if (!same_mpfr_value (expected, got)) + error_message (i, got, expected); + + /* [+0, +inf] */ + mpfr_set_ui (&(i->left), 0, MPFI_RNDD); + mpfr_set_inf (expected, +1); + mpfr_set (&(i->right), expected, MPFI_RNDU); + mpfi_get_fr (got, i); + if (!same_mpfr_value (expected, got)) + error_message (i, got, expected); + + /* [+inf, +inf] */ + mpfi_set_fr (i, expected); + mpfi_get_fr (got, i); + if (!same_mpfr_value (expected, got)) + error_message (i, got, expected); + + /* [-inf, +inf] */ + mpfr_set_inf (&(i->left), -1); + mpfr_set_inf (&(i->right), +1); + mpfr_set_nan (expected); + mpfi_get_fr (got, i); + if (!same_mpfr_value (expected, got)) + error_message (i, got, expected); + + /* [+0, -0] */ + mpfr_set_ui (expected, 0, MPFI_RNDU); + mpfi_set_fr (i, expected); + mpfi_get_fr (got, i); + if (!same_mpfr_value (expected, got)) + error_message (i, got, expected); + + mpfr_clear (expected); + mpfr_clear (got); + mpfi_clear (i); +} + +void +test_random (mpfr_prec_t prec_min, mpfr_prec_t prec_max) +{ + mpfr_t x; + mpfi_t i; + mpfr_prec_t prec; + unsigned long pi, px; + + mpfr_init2 (x, prec_max); + mpfi_init2 (i, prec_max); + + for (prec = prec_min; prec < prec_max; prec++) { + mpfi_set_prec (i, prec); + mpfr_set_prec (x, prec); + do { + random_interval (i); + } while (MPFI_INF_P (i)); + mpfi_get_fr (x, i); + if (mpfi_is_inside_fr (x, i) == 0) { + pi = mpfi_get_prec (i); + px = mpfr_get_prec (x); + printf ("Error: mpfi_get_fr (x, I) returns a value x outside the " + "initial interval I, while the precisions are the same.\n" + "precision_I: %lu, I = ", pi); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nprecision_x: %lu, x = ", px); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf ("\n"); + exit (1); + } + } + + mpfr_clear (x); + mpfi_clear (i); +} + +int +main (int argc, char **argv) +{ + test_start (); + test_special (); + test_random (2, 1023); + test_end (); + + return 0; +} diff --git a/tests/tget_version.c b/tests/tget_version.c new file mode 100644 index 0000000..9630a10 --- /dev/null +++ b/tests/tget_version.c @@ -0,0 +1,44 @@ +/* tget_version.c -- Test mpfi_get_version. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + if (strcmp (mpfi_get_version (), VERSION) != 0) { + printf ("Error: The value return by mpfi_get_version (\"%s\") and the " + "one of the VERSION symbol (" QUOTE(VERSION) ") differ.\n", + mpfi_get_version ()); + exit (1); + } + + printf ("MPFI version: %s\n", mpfi_get_version ()); + printf ("MPFR version: %s\n", mpfr_get_version ()); + printf ("GMP version: %s\n", gmp_version); + + return 0; +} diff --git a/tests/thas_zero.c b/tests/thas_zero.c new file mode 100644 index 0000000..6587f68 --- /dev/null +++ b/tests/thas_zero.c @@ -0,0 +1,67 @@ +/* thas_zero.c -- Test mpfi_has_zero. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +void +print_error (mpfi_srcptr i) +{ + printf ("Error: mpfi_has_zero(I) returns wrong value.\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n%d", mpfi_has_zero (i)); + exit (1); +} + +int +main (int argc, char **argv) +{ + FILE *stream; + mpfi_t interval; + int expected; + int got; + + mpfi_init2 (interval, 1024); + + stream = open_file ("bounded_p.dat"); + + init_reading (stream); + + while (nextchar != EOF) { + read_sign (stream, &expected); + read_mpfi (stream, interval); + + got = mpfi_bounded_p (interval); + if (got != expected || got * expected < 0) + print_error (interval); + } + + close_file (stream); + mpfi_clear (interval); + + return 0; +} diff --git a/tests/thypot.c b/tests/thypot.c new file mode 100644 index 0000000..a967e3f --- /dev/null +++ b/tests/thypot.c @@ -0,0 +1,45 @@ +/* thypot.c -- Test mpfi_hypot. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_hypot; + + mpfi_fun_init_III (&i_hypot, mpfi_hypot, mpfr_hypot); + + test_start (); + + check_data (&i_hypot, "hypot.dat"); + check_random (&i_hypot, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_hypot); + + return 0; +} diff --git a/tests/tincrease.c b/tests/tincrease.c new file mode 100644 index 0000000..0a6d171 --- /dev/null +++ b/tests/tincrease.c @@ -0,0 +1,43 @@ +/* tincrease.c -- Test mpfi_increase. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_increase; + + mpfi_fun_init_IR (&i_increase, mpfi_increase, mpfr_add); + test_start (); + + check_data (&i_increase, "increase.dat"); + + test_end (); + mpfi_fun_clear (&i_increase); + + return 0; +} diff --git a/tests/tinf_p.c b/tests/tinf_p.c new file mode 100644 index 0000000..7cf309b --- /dev/null +++ b/tests/tinf_p.c @@ -0,0 +1,69 @@ +/* tinf_p.c -- Test mpfi_inf_p. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +void +print_error (mpfi_srcptr a) +{ + printf ("Error: mpfi_inf_p (A) returns %d\nA = ", + mpfi_inf_p (a)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\n"); + + exit (1); +} + +int +main (int argc, char **argv) +{ + FILE *stream; + mpfi_t interval; + int expected; + int got; + + mpfi_init2 (interval, 1024); + + stream = open_file ("inf_p.dat"); + + init_reading (stream); + + while (nextchar != EOF) { + read_sign (stream, &expected); + read_mpfi (stream, interval); + + got = mpfi_inf_p (interval); + if (got != expected || got * expected < 0) + print_error (interval); + } + + close_file (stream); + mpfi_clear (interval); + + return 0; +} diff --git a/tests/tinit.c b/tests/tinit.c new file mode 100644 index 0000000..97a88e6 --- /dev/null +++ b/tests/tinit.c @@ -0,0 +1,58 @@ +/* tinit.c -- Test mpfi_init. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + mpfi_t a; + + mpfi_init (a); + if (mpfi_get_prec (a) != mpfr_get_default_prec ()) { + printf ("Error: mpfi_init does not use the default precision of MPFR." + "\nDefault precision in MPFI: %lu" + "\nDefault precision in MPFR: %lu\n", + mpfi_get_prec (a), mpfr_get_default_prec ()); + + exit (1); + } + mpfi_clear (a); + + mpfr_set_default_prec (111); + mpfi_init (a); + if (mpfi_get_prec (a) != mpfr_get_default_prec ()) { + printf ("Error: mpfi_init does not use the default precision of MPFR." + "\nDefault precision in MPFI: %lu" + "\nDefault precision in MPFR: %lu\n", + mpfi_get_prec (a), mpfr_get_default_prec ()); + + exit (1); + } + mpfi_clear (a); + + return 0; +} diff --git a/tests/tinit_set.c b/tests/tinit_set.c new file mode 100644 index 0000000..31452b4 --- /dev/null +++ b/tests/tinit_set.c @@ -0,0 +1,437 @@ +/* tinit_set.c -- Test file for mpfi_init_set functions. + +Copyright 2009, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include +#include "mpfi-tests.h" + +void +check_endpoints (mpfi_ptr i, const char *left, const char *right, + const char *function_name) +{ + mpfr_t l,r; + + mpfr_inits2 (mpfi_get_prec (i), l, r, (mpfr_ptr)0); + + mpfr_set_str (l, left, 0, MPFI_RNDD); + mpfr_set_str (r, right, 0, MPFI_RNDU); + + if (!mpfr_equal_p (&(i->left), l) || !mpfr_equal_p (&(i->right), r)) { + printf ("Error in %s\nexpected [%s, %s]\n got ", + function_name, left, right); + mpfi_out_str (stdout, 16, 0, i); + putchar ('\n'); + exit (1); + } + + mpfr_clears (l, r, (mpfr_ptr)0); +} + +void +check_ui (unsigned long ui, int expected_inex, + const char *left, const char *right) +{ + int inex; + mpfi_t fi; + + inex = mpfi_init_set_ui (fi, ui); + if (inex != expected_inex) { + printf ("Error: mpfi_init_set_ui returns unexpected value with input=%lu and " + "output precision=%lu\nexpected return value: %u, got: %u\n", + ui, mpfi_get_prec (fi), expected_inex, inex); + exit (1); + } + check_endpoints (fi, left, right, "mpfi_init_set_ui"); + if (ui == 0 && (mpfr_signbit (&(fi->left)) || !mpfr_signbit (&(fi->right)))) { + printf ("Error: mpfi_init_set_ui does not handle signed zeros correctly\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + mpfi_clear (fi); +} + +void +check_si (long si, int expected_inex, + const char *left, const char *right) +{ + mpfi_t fi; + int inex; + inex = mpfi_init_set_si (fi, si); + if (inex != expected_inex) { + printf ("Error: mpfi_init_set_si returns unexpected value with input=%lu and " + "output precision=%lu\nexpected return value: %u, got: %u\n", + si, mpfi_get_prec (fi), expected_inex, inex); + exit (1); + } + check_endpoints (fi, left, right, "mpfi_init_set_si"); + if (si == 0 && (mpfr_signbit (&(fi->left)) || !mpfr_signbit (&(fi->right)))) { + printf ("Error: mpfi_init_set_si does not handle signed zeros correctly\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + mpfi_clear(fi); +} + +void +check_d (double d, int expected_inex, + const char *left, const char *right) +{ + mpfi_t fi; + int inex; + inex = mpfi_init_set_d (fi, d); + if (inex != expected_inex) { + printf ("Error: mpfi_init_set_d returns unexpected value with input=%g and " + "output precision=%lu\nexpected return value: %u, got: %u\n", + d, mpfi_get_prec (fi), expected_inex, inex); + exit (1); + } + check_endpoints (fi, left, right, "mpfi_init_set_d"); + if (d == 0.0 + && (mpfr_signbit (&(fi->left)) || !mpfr_signbit (&(fi->right)))) { + printf ("Error: mpfi_init_set_d does not handle signed zeros correctly\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + mpfi_clear(fi); +} + +void +check_z (const char *value, int expected_inex, + const char *left, const char *right) +{ + mpfi_t fi; + int inex; + mpz_t z; + mpz_init (z); + + mpz_set_str (z, value, 0); + inex = mpfi_init_set_z (fi, z); + if (inex != expected_inex) { + printf ("Error: mpfi_init_set_z returns unexpected value with input="); + mpz_out_str (stdout, 10, z); + printf (" and output precision=%lu\nexpected return value: %u, got: %u\n", + mpfi_get_prec (fi), expected_inex, inex); + exit (1); + } + check_endpoints (fi, left, right, "mpfi_init_set_z"); + + if (mpz_cmp_ui (z,0) == 0 + && (mpfr_signbit (&(fi->left)) || !mpfr_signbit (&(fi->right)))) { + printf ("Error: mpfi_init_set_z does not handle signed zeros correctly\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + + mpz_clear (z); + mpfi_clear(fi); +} + +void +check_q (const char *value, int expected_inex, + const char *left, const char *right) +{ + mpfi_t fi; + int inex; + mpq_t q; + mpq_init (q); + + mpq_set_str (q, value, 0); + inex = mpfi_init_set_q (fi, q); + if (inex != expected_inex) { + printf ("Error: mpfi_init_set_q returns unexpected value with input="); + mpq_out_str (stdout, 10, q); + printf (" and output precision=%lu\nexpected return value: %u, got: %u\n", + mpfi_get_prec (fi), expected_inex, inex); + exit (1); + } + check_endpoints (fi, left, right, "mpfi_init_set_q"); + + if (mpq_cmp_ui (q, 0, 1) == 0 + && (mpfr_signbit (&(fi->left)) || !mpfr_signbit (&(fi->right)))) { + printf ("Error: mpfi_init_set_q does not handle signed zeros correctly\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + + mpq_clear (q); + mpfi_clear(fi); +} + +void +check_fr (mpfr_ptr fr, int expected_inex, + const char *left, const char *right) +{ + mpfi_t fi; + int inex; + + inex = mpfi_init_set_fr (fi, fr); + if (inex != expected_inex) { + printf ("Error: mpfi_init_set_fr returns unexpected value with input="); + mpfr_out_str (stdout, 10, 0, fr, MPFI_RNDD); + printf (" and output precision=%lu\nexpected return value: %u, got: %u\n", + mpfi_get_prec (fi), expected_inex, inex); + exit (1); + } + check_endpoints (fi, left, right, "mpfi_init_set_fr"); + + if (mpfr_zero_p (fr) + && (mpfr_signbit (&(fi->left)) || !mpfr_signbit (&(fi->right)))) { + printf ("Error: mpfi_init_set_fr does not handle signed zeros correctly\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + + mpfi_clear(fi); +} + +void +check_fi (mpfi_ptr in, int expected_inex, + const char *left, const char *right) +{ + mpfi_t out; + int inex; + + inex = mpfi_init_set (out, in); + if (inex != expected_inex) { + printf ("Error: mpfi_init_set returns unexpected value with input="); + mpfi_out_str (stdout, 10, 0, in); + printf (" and output precision=%lu\nexpected return value: %u, got: %u\n", + mpfi_get_prec (out), expected_inex, inex); + exit (1); + } + if (!MPFI_NAN_P (in)) { + check_endpoints (out, left, right, "mpfi_init_set"); + } + else if (!mpfr_nan_p (&(out->left)) || !mpfr_nan_p (&(out->right))) { + printf ("Error: mpfi_init_set_fr does not accept NAN\ngot: "); + mpfi_out_str (stdout, 10, 0, out); + putchar ('\n'); + exit (1); + } + + mpfi_clear(out); +} + +int +main (int argc, char **argv) +{ + int inex; + double d; + mpfr_t fr; + mpfi_t fi; + + /* check mpfi_init_set_ui */ + mpfr_set_default_prec(2); + check_ui (0x87654321L, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "0b1p+31", "0b11p+30"); + mpfr_set_default_prec(16); + check_ui (0x87654321L, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "0x8765@+4", "0x8766@+4"); + mpfr_set_default_prec(64); + check_ui (0x87654321L, + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "0x87654321", "0x87654321"); + check_ui (0, + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "+0", "-0"); + + + /* check mpfi_init_set_si */ + mpfr_set_default_prec(2); + check_si (0x80001L, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "0b10p+18", "0b11p+18"); + check_si (-0x80001L, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "-0b11p+18", "-0b10p+18"); + mpfr_set_default_prec(16); + check_si (0x80001L, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "0x8000@+1", "0x8001@+1"); + check_si (-0x80001L, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "-0x8001@+1", "-0x8000@+1"); + mpfr_set_default_prec(20); + check_si (0x80001L, + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "0x80001", "0x80001"); + check_si (-0x80001L, + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "-0x80001", "-0x80001"); + check_si (0, + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "+0", "-0"); + + + /* check mpfi_init_set_d */ + mpfr_set_default_prec(53); + check_d (1.0e6, + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "1.0e6", "1.0e6"); + mpfr_set_default_prec(12); + check_d (0.1, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "0x1999@-4", "0x199A@-4"); + check_d (-0.1, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "-0x199A@-4", "-0x1999@-4"); + check_d (+0.0, + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "+0", "-0"); + check_d (-0.0, + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "+0", "-0"); + + /* NAN, INFINITY, and DBL_MANT_DIG are symbols defined in math.h or float.h + in C99 mode */ +#ifdef NAN + d = NAN; + mpfi_init_set_d (fi, d); + if (!mpfr_nan_p (&(fi->left)) || !mpfr_nan_p (&(fi->right))) { + printf ("Error: mpfi_init_set_d does not accept NAN\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + mpfi_clear (fi); +#endif /* NAN */ + +#ifdef INFINITY + d = INFINITY; + inex = mpfi_init_set_d (fi, d); + if (!MPFI_INF_P (fi)) { + printf ("Error: mpfi_init_set_d does not accept INFINITY\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + if (!MPFI_BOTH_ARE_EXACT (inex)) { + printf ("Error: mpfi_init_set_d(INF) returns unexpected value, " + "expected: %u, got: %u\n", MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, inex); + exit (1); + } + mpfi_clear (fi); +#endif /* INFINITY */ + +#ifdef DBL_MANT_DIG + d = 0.1; + mpfr_set_default_prec (DBL_MANT_DIG); + inex = mpfi_init_set_d (fi, d); + if (!MPFI_BOTH_ARE_EXACT (inex)) { + printf ("Error: mpfi_init_set_d(%g) returns unexpected value, expected: %u, " + "got: %u\n", d, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, inex); + exit (1); + } + +# if DBL_MANT_DIG == 53 + check_endpoints (fi, "0x1999999999999A@-14", "0x1999999999999A@-14", "mpfi_init_set_d"); +# endif + mpfi_clear (fi); +#endif /* DBL_MANT_DIG */ + + + /* check mpfi_init_set_z */ + mpfr_set_default_prec(12); + check_z ("0xffffffffffffff", + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "0xffff@+10", "0x10000@+10"); + check_z ("-0xfeffffffffffff", + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "-0xff00@+10", "-0xfeff@+10"); + mpfr_set_default_prec(56); + check_z ("0xffffffffffffff", + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "0xffffffffffffff", "0xffffffffffffff"); + check_z ("-0xfeffffffffffff", + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "-0xfeffffffffffff", "-0xfeffffffffffff"); + check_z ("0", + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "+0", "-0"); + + + /* check mpfi_init_set_q */ + mpfr_set_default_prec(2); + check_q ("1/2", + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "0x1p-1", "0x1p-1"); + check_q ("5/2", + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "2", "3"); + mpfr_set_default_prec(53); + check_q ("-1/2", + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "-0x1p-1", "-0x1p-1"); + check_q ("-1/3", + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "-0xAAAAAAAAAAAABP-53", "-0x15555555555555P-54"); + check_q ("0/1", + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "+0", "-0"); + + + /* check mpfi_init_set_fr */ + mpfr_init2 (fr, 53); + + mpfr_set_default_prec(2); + mpfr_set_str (fr, "0.5", 10, MPFI_RNDD); + check_fr (fr, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "0x8@-1", "0x8@-1"); + mpfr_set_str (fr, "0.1", 10, MPFI_RNDU); + check_fr (fr, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "0b11p-5", "0b10p-4"); + + mpfr_set_default_prec(53); + check_fr (fr, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, + "0x1999999999999A@-14", "0x1999999999999A@-14"); + + mpfr_set_ui (fr, 0, MPFI_RNDD); + check_fr (fr, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "+0", "-0"); + mpfr_neg (fr, fr, MPFI_RNDD); + check_fr (fr, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "+0", "-0"); + mpfr_set_inf (fr, -1); + check_fr (fr, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "-@inf@", "-@inf@"); + + mpfr_set_nan (fr); + mpfi_init_set_fr (fi, fr); + if (!mpfr_nan_p (&(fi->left)) || !mpfr_nan_p (&(fi->right))) { + printf ("Error: mpfi_init_set_fr does not accept NAN\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + mpfi_clear (fi); + mpfr_clear (fr); + + + /* check mpfi_init_set */ + mpfi_init2 (fi, 53); + + mpfr_set_default_prec(2); + mpfi_set_str (fi, "0.5", 10); + check_fi (fi, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "0x8@-1", "0x8@-1"); + mpfi_set_str (fi, "0.1", 10); + check_fi (fi, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, "0b11p-5", "0b10p-4"); + + mpfr_set_default_prec(53); + check_fi (fi, + MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "0x19999999999999@-14", "0x1999999999999A@-14"); + + mpfr_set_inf (&(fi->left), -1); + mpfr_set_inf (&(fi->right), +1); + check_fi (fi, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "-@inf@", "+@inf@"); + + mpfr_set_ui (&(fi->left), 0, MPFI_RNDD); + mpfr_neg (&(fi->right), &(fi->left), MPFI_RNDU); + check_fi (fi, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "+0", "-0"); + + mpfr_set_nan (&(fi->left)); + mpfr_set_nan (&(fi->right)); + check_fi (fi, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, "@nan@", "@nan@"); + + mpfi_clear (fi); + + return 0; +} diff --git a/tests/tinits.c b/tests/tinits.c new file mode 100644 index 0000000..3f5e4e9 --- /dev/null +++ b/tests/tinits.c @@ -0,0 +1,76 @@ +/* Test file for mpfi_init2, mpfi_inits, mpfi_inits2 and mpfi_clears. + +Copyright 2018 Free Software Foundation, Inc. +Contributed by the AriC project, INRIA. + +This file is part of the GNU MPFI Library. + +The GNU MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MPFI Library; see the file COPYING.LESSER. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (void) +{ + mpfi_t a, b, c; + long large_prec; + + + mpfi_inits (a, b, c, (mpfi_ptr) 0); + mpfi_clears (a, b, c, (mpfi_ptr) 0); + mpfi_inits2 (200, a, b, c, (mpfi_ptr) 0); + mpfi_clears (a, b, c, (mpfi_ptr) 0); + + /* test for precision 2^31-1, see + https://gforge.inria.fr/tracker/index.php?func=detail&aid=13918 */ +/* this belongs to MPFR, no need to test this here? XXX + large_prec = 2147483647; + if (getenv ("MPFR_CHECK_LARGEMEM") != NULL) + { + size_t min_memory_limit; +*/ + + /* We assume that the precision won't be increased internally. */ +/* this belongs to MPFR, no need to test this here? XXX + if (large_prec > MPFR_PREC_MAX) + large_prec = MPFR_PREC_MAX; +*/ + + /* Increase tests_memory_limit if need be in order to avoid an + obvious failure due to insufficient memory, by choosing a bit + more than the memory used for the variables a and b. Note + that such an increase is necessary, but is not guaranteed to + be sufficient in all cases (e.g. with logging activated). */ +/* this belongs to MPFR, no need to test this here? XXX + min_memory_limit = 2 * (large_prec / MPFR_BYTES_PER_MP_LIMB) + 65536; + if (tests_memory_limit > 0 && tests_memory_limit < min_memory_limit) + tests_memory_limit = min_memory_limit; + + mpfr_inits2 (large_prec, a, b, (mpfr_ptr) 0); + mpfr_set_ui (a, 17, MPFR_RNDN); + mpfr_set (b, a, MPFR_RNDN); + if (mpfr_get_ui (a, MPFR_RNDN) != 17) + { + printf ("Error in mpfr_init2 with precision 2^31-1\n"); + exit (1); + } + mpfr_clears (a, b, (mpfr_ptr) 0); + } +*/ + + + return 0; +} diff --git a/tests/tintersect.c b/tests/tintersect.c new file mode 100644 index 0000000..5d98bc7 --- /dev/null +++ b/tests/tintersect.c @@ -0,0 +1,41 @@ +/* tintersect.c -- Test mpfi_intersect. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_intersect; + + mpfi_fun_init_III (&i_intersect, mpfi_intersect, NULL); + + check_data (&i_intersect, "intersect.dat"); + + mpfi_fun_clear (&i_intersect); + + return 0; +} diff --git a/tests/tinterv_d.c b/tests/tinterv_d.c new file mode 100644 index 0000000..7868baf --- /dev/null +++ b/tests/tinterv_d.c @@ -0,0 +1,126 @@ +/* tinterv_d.c -- Test mpfi_interv_d. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check (mpfi_ptr i, double a, double b, + mpfr_srcptr expected_left, mpfr_srcptr expected_right, + int expected_inex) +{ + int inex; + + inex = mpfi_interv_d (i, a, b); + if (inex != expected_inex) { + printf ("Error: mpfi_interv_d (i, a, b) returns %d instead of %d\n", + inex, expected_inex); + printf ("precision(i) = %lu\na = %g\nb = %g\n", mpfi_get_prec (i), a, b); + exit (1); + } + if (!same_mpfr_value (&(i->left), expected_left) + || !same_mpfr_value (&(i->right), expected_right)) { + printf ("Error: mpfi_interv_d (i, a, b) failed.\n"); + printf ("\na = %g\nb = %g\ngot i = ", a, b); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nexpected = ["); + mpfr_out_str (stdout, 10, 0, expected_left, MPFI_RNDD); + printf (", "); + mpfr_out_str (stdout, 10, 0, expected_right, MPFI_RNDU); + printf ("]\n"); + exit (1); + } +} + +int +main (int argc, char **argv) +{ + mpfr_t x, y; + + double a, b; + mpfi_t i; + + mpfi_init2 (i, 53); + mpfr_init2 (x, 53); + mpfr_init2 (y, 53); + + a = -1; + b = +1; + mpfr_set_d (x, -1, MPFI_RNDD); + mpfr_set_d (y, +1, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, b, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, a, a, x, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_set_prec (i, 4); + mpfr_set_prec (x, 4); + mpfr_set_prec (y, 4); + a = -1; + b = +40; + mpfr_set_d (x, -1, MPFI_RNDD); + mpfr_set_d (y, +40, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, b, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, a, a, x, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + a = -1; + b = +42.35; + mpfr_set_d (x, -1, MPFI_RNDD); + mpfr_set_d (y, +42.35, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, b, a, x, y, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + + a = -0.1; + mpfr_set_d (x, -0.1, MPFI_RNDD); + mpfr_set_d (y, +42.35, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + check (i, b, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + + a = -1e-4; + b = +16; + mpfr_set_d (x, -1e-4, MPFI_RNDD); + mpfr_set_d (y, +16, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + check (i, b, a, x, y, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + + mpfr_set_nan (x); + a = mpfr_get_d (x, MPFI_RNDD); /* a = NaN, if supported */ + check (i, a, b, y, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, b, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, a, a, x, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfr_set_ui (x, 0, MPFI_RNDD); + mpfr_neg (x, x, MPFI_RNDD); + a = mpfr_get_d (x, MPFI_RNDD); /* a = -0, if supported */ + mpfr_neg (x, x, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, b, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_clear (i); + mpfr_clear (x); + mpfr_clear (y); + + return 0; +} diff --git a/tests/tinterv_fr.c b/tests/tinterv_fr.c new file mode 100644 index 0000000..88a282d --- /dev/null +++ b/tests/tinterv_fr.c @@ -0,0 +1,194 @@ +/* tinterv_fr.c -- Test mpfi_interv_fr. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check (mpfi_ptr i, mpfr_srcptr a, mpfr_srcptr b, + mpfr_srcptr expected_left, mpfr_srcptr expected_right, + int expected_inex) +{ + int inex; + + inex = mpfi_interv_fr (i, a, b); + if (inex != expected_inex) { + printf ("Error: mpfi_interv_fr (i, a, b) returns %d instead of %d\n", + inex, expected_inex); + printf ("precision(i) = %lu\na =", mpfi_get_prec (i)); + mpfr_out_str (stdout, 10, 0, a, MPFI_RNDD); + printf ("\nb = "); + mpfr_out_str (stdout, 10, 0, b, MPFI_RNDU); + printf ("\n"); + exit (1); + } + if (!same_mpfr_value (&(i->left), expected_left) + || !same_mpfr_value (&(i->right), expected_right)) { + printf ("Error: mpfi_interv_fr (i, a, b) failed.\n"); + printf ("\na = "); + mpfr_out_str (stdout, 10, 0, a, MPFI_RNDD); + printf ("\nb = "); + mpfr_out_str (stdout, 10, 0, b, MPFI_RNDU); + printf ("\ngot i = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nexpected = ["); + mpfr_out_str (stdout, 10, 0, expected_left, MPFI_RNDD); + printf (", "); + mpfr_out_str (stdout, 10, 0, expected_right, MPFI_RNDU); + printf ("]\n"); + exit (1); + } +} + +int +main (int argc, char **argv) +{ + mpfr_t minf, pinf; + mpfr_t mzero, pzero; + mpfr_t nan; + mpfr_t x, y; + mpfr_t xx, yy; + + mpfi_t i; + + mpfi_init2 (i, 53); + mpfr_init2 (x, 53); + mpfr_init2 (y, 53); + mpfr_init2 (xx, 53); + mpfr_init2 (yy, 53); + mpfr_init2 (minf, 53); + mpfr_init2 (pinf, 53); + mpfr_init2 (mzero, 53); + mpfr_init2 (pzero, 53); + mpfr_init2 (nan, 53); + + mpfr_set_nan (nan); + mpfr_set_inf (minf, -1); + mpfr_set_inf (pinf, +1); + mpfr_set_ui (pzero, 0, MPFI_RNDU); + mpfr_neg (mzero, pzero, MPFI_RNDD); + + /* special values */ + check (i, minf, minf, minf, minf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, minf, mzero, minf, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, mzero, minf, minf, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, minf, pzero, minf, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pzero, minf, minf, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, minf, pinf, minf, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pinf, minf, minf, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, minf, nan, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, nan, minf, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + check (i, mzero, mzero, pzero, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, mzero, pzero, pzero, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pzero, mzero, pzero, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, mzero, pinf, pzero, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pinf, mzero, pzero, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, mzero, nan, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, nan, mzero, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + check (i, pzero, pzero, pzero, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pzero, pzero, pzero, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pzero, pinf, pzero, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pinf, pzero, pzero, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pzero, nan, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, nan, pzero, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + check (i, pinf, pinf, pinf, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pinf, nan, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, nan, pinf, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + check (i, nan, nan, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + /* regular values */ + mpfr_set_si (x, -456789, MPFI_RNDD); + mpfr_set_si (y, 123456, MPFI_RNDU); + check (i, x, y, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, y, x, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, x, minf, minf, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, minf, x, minf, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, x, mzero, x, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, mzero, x, x, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, y, mzero, pzero, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, mzero, y, pzero, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, x, pzero, x, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pzero, x, x, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, y, pzero, pzero, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pzero, y, pzero, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, x, pinf, x, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pinf, x, x, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, y, pinf, y, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, pinf, y, y, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, x, nan, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, nan, x, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, y, nan, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, nan, x, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfr_set_si (x, -400009, MPFI_RNDD); + mpfr_set_si (y, 100007, MPFI_RNDU); + mpfi_set_prec (i, 12); + mpfr_set_prec (xx, 12); + mpfr_set_prec (yy, 12); + mpfr_set (xx, x, MPFI_RNDD); + mpfr_set (yy, y, MPFI_RNDU); + check (i, x, y, xx, yy, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + check (i, y, x, xx, yy, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + mpfr_set (xx, x, MPFI_RNDU); + check (i, x, minf, minf, xx, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, minf, x, minf, xx, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, y, minf, minf, yy, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, minf, y, minf, yy, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + mpfr_set (xx, x, MPFI_RNDD); + check (i, x, mzero, xx, mzero, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + check (i, mzero, x, xx, mzero, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + check (i, y, mzero, pzero, yy, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, mzero, y, pzero, yy, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, x, pzero, xx, mzero, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + check (i, pzero, x, xx, mzero, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + check (i, y, pzero, pzero, yy, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, pzero, y, pzero, yy, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, x, pinf, xx, pinf, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + check (i, pinf, x, xx, pinf, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + mpfr_set (yy, y, MPFI_RNDD); + check (i, y, pinf, yy, pinf, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + check (i, pinf, y, yy, pinf, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + check (i, x, nan, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, nan, x, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, y, nan, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, nan, y, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_clear (i); + mpfr_clear (x); + mpfr_clear (y); + mpfr_clear (xx); + mpfr_clear (yy); + mpfr_clear (minf); + mpfr_clear (pinf); + mpfr_clear (mzero); + mpfr_clear (pzero); + mpfr_clear (nan); + + return 0; +} diff --git a/tests/tinterv_q.c b/tests/tinterv_q.c new file mode 100644 index 0000000..c01e67e --- /dev/null +++ b/tests/tinterv_q.c @@ -0,0 +1,96 @@ +/* tinterv_q.c -- Test mpfi_interv_q. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check (mpfi_ptr i, mpq_srcptr a, mpq_srcptr b, + mpfr_srcptr expected_left, mpfr_srcptr expected_right, + int expected_inex) +{ + int inex; + + inex = mpfi_interv_q (i, a, b); + if (inex != expected_inex) { + printf ("Error: mpfi_interv_q (i, a, b) returns %d instead of %d\n", + inex, expected_inex); + printf ("precision(i) = %lu\na =", mpfi_get_prec (i)); + mpq_out_str (stdout, 10, a); + printf ("\nb = "); + mpq_out_str (stdout, 10, b); + printf ("\n"); + exit (1); + } + if (!same_mpfr_value (&(i->left), expected_left) + || !same_mpfr_value (&(i->right), expected_right)) { + printf ("Error: mpfi_interv_q (i, a, b) failed.\n"); + printf ("\na = "); + mpq_out_str (stdout, 10, a); + printf ("\nb = "); + mpq_out_str (stdout, 10, b); + printf ("\ngot i = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nexpected = ["); + mpfr_out_str (stdout, 10, 0, expected_left, MPFI_RNDD); + printf (", "); + mpfr_out_str (stdout, 10, 0, expected_right, MPFI_RNDU); + printf ("]\n"); + exit (1); + } +} + +int +main (int argc, char **argv) +{ + mpfr_t x, y; + + mpq_t a, b; + mpfi_t i; + + mpq_init (a); + mpq_init (b); + mpfi_init2 (i, 53); + mpfr_init2 (x, 53); + mpfr_init2 (y, 53); + + mpq_set_si (a, -1, 3); + mpq_set_ui (b, +1, 1024); + mpfr_set_q (x, a, MPFI_RNDD); + mpfr_set_q (y, b, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + check (i, b, a, x, y, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + check (i, b, b, y, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + mpfr_set_q (y, a, MPFI_RNDU); + check (i, a, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + + mpq_clear (a); + mpq_clear (b); + mpfi_clear (i); + mpfr_clear (x); + mpfr_clear (y); + + return 0; +} diff --git a/tests/tinterv_si.c b/tests/tinterv_si.c new file mode 100644 index 0000000..53b5cdb --- /dev/null +++ b/tests/tinterv_si.c @@ -0,0 +1,113 @@ +/* tinterv_si.c -- Test mpfi_interv_si. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check (mpfi_ptr i, long a, long b, + mpfr_srcptr expected_left, mpfr_srcptr expected_right, + int expected_inex) +{ + int inex; + + inex = mpfi_interv_si (i, a, b); + if (inex != expected_inex) { + printf ("Error: mpfi_interv_si (i, a, b) returns %d instead of %d\n", + inex, expected_inex); + printf ("precision(i) = %lu\na = %ld\nb = %ld\n", mpfi_get_prec (i), a, + b); + exit (1); + } + if (!same_mpfr_value (&(i->left), expected_left) + || !same_mpfr_value (&(i->right), expected_right)) { + printf ("Error: mpfi_interv_si (i, a, b) failed.\n"); + printf ("precision(i) = %lu\n", mpfi_get_prec (i)); + printf ("a = %ld\nb = %ld\ngot i = ", a, b); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nexpected = ["); + mpfr_out_str (stdout, 10, 0, expected_left, MPFI_RNDD); + printf (", "); + mpfr_out_str (stdout, 10, 0, expected_right, MPFI_RNDU); + printf ("]\n"); + exit (1); + } +} + +int +main (int argc, char **argv) +{ + mpfr_t x, y; + + long a, b; + mpfi_t i; + + mpfi_init2 (i, 53); + mpfr_init2 (x, 53); + mpfr_init2 (y, 53); + + a = 0; + b = 42; + mpfr_set_ui (x, a, MPFI_RNDD); + mpfr_set_ui (y, b, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, b, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, b, b, y, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + mpfr_neg (y, x, MPFI_RNDD); + check (i, a, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + a = +1; + b = +123456; + mpfr_set_si (x, a, MPFI_RNDD); + mpfr_set_si (y, b, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, b, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, a, a, x, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + a = -1920; + b = -17; + mpfr_set_si (x, a, MPFI_RNDD); + mpfr_set_si (y, b, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, b, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, a, a, x, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_set_prec (i, 4); + mpfr_set_prec (x, 4); + mpfr_set_prec (y, 4); + mpfr_set_si (x, a, MPFI_RNDD); + mpfr_set_si (y, b, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, b, a, x, y, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, a, a, x, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + mpfr_set_si (x, b, MPFI_RNDD); + check (i, b, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + + mpfi_clear (i); + mpfr_clear (x); + mpfr_clear (y); + + return 0; +} diff --git a/tests/tinterv_ui.c b/tests/tinterv_ui.c new file mode 100644 index 0000000..beccf99 --- /dev/null +++ b/tests/tinterv_ui.c @@ -0,0 +1,104 @@ +/* tinterv_ui.c -- Test mpfi_interv_ui. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check (mpfi_ptr i, unsigned long a, unsigned long b, + mpfr_srcptr expected_left, mpfr_srcptr expected_right, + int expected_inex) +{ + int inex; + + inex = mpfi_interv_ui (i, a, b); + if (inex != expected_inex) { + printf ("Error: mpfi_interv_ui (i, a, b) returns %d instead of %d\n", + inex, expected_inex); + printf ("precision(i) = %lu\na = %lu\nb = %lu\n", mpfi_get_prec (i), a, + b); + exit (1); + } + if (!same_mpfr_value (&(i->left), expected_left) + || !same_mpfr_value (&(i->right), expected_right)) { + printf ("Error: mpfi_interv_ui (i, a, b) failed.\n"); + printf ("\na = %lu\nb = %lu\ngot i = ", a, b); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nexpected = ["); + mpfr_out_str (stdout, 10, 0, expected_left, MPFI_RNDD); + printf (", "); + mpfr_out_str (stdout, 10, 0, expected_right, MPFI_RNDU); + printf ("]\n"); + exit (1); + } +} + +int +main (int argc, char **argv) +{ + mpfr_t x, y; + + unsigned long a, b; + mpfi_t i; + + mpfi_init2 (i, 53); + mpfr_init2 (x, 53); + mpfr_init2 (y, 53); + + a = 0; + b = 42; + mpfr_set_ui (x, a, MPFI_RNDD); + mpfr_set_ui (y, b, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, b, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, b, b, y, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + mpfr_neg (y, x, MPFI_RNDD); + check (i, a, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + a = 1; + b = 123456; + mpfr_set_ui (x, a, MPFI_RNDD); + mpfr_set_ui (y, b, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, b, a, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + check (i, a, a, x, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_set_prec (i, 4); + mpfr_set_prec (x, 4); + mpfr_set_prec (y, 4); + mpfr_set_ui (x, a, MPFI_RNDD); + mpfr_set_ui (y, b, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, b, a, x, y, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, a, a, x, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + mpfr_set_ui (x, b, MPFI_RNDD); + check (i, b, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + + mpfi_clear (i); + mpfr_clear (x); + mpfr_clear (y); + + return 0; +} diff --git a/tests/tinterv_z.c b/tests/tinterv_z.c new file mode 100644 index 0000000..70a22b0 --- /dev/null +++ b/tests/tinterv_z.c @@ -0,0 +1,96 @@ +/* tinterv_z.c -- Test mpfi_interv_z. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check (mpfi_ptr i, mpz_srcptr a, mpz_srcptr b, + mpfr_srcptr expected_left, mpfr_srcptr expected_right, + int expected_inex) +{ + int inex; + + inex = mpfi_interv_z (i, a, b); + if (inex != expected_inex) { + printf ("Error: mpfi_interv_z (i, a, b) returns %d instead of %d\n", + inex, expected_inex); + printf ("precision(i) = %lu\na =", mpfi_get_prec (i)); + mpz_out_str (stdout, 10, a); + printf ("\nb = "); + mpz_out_str (stdout, 10, b); + printf ("\n"); + exit (1); + } + if (!same_mpfr_value (&(i->left), expected_left) + || !same_mpfr_value (&(i->right), expected_right)) { + printf ("Error: mpfi_interv_z (i, a, b) failed.\n"); + printf ("\na = "); + mpz_out_str (stdout, 10, a); + printf ("\nb = "); + mpz_out_str (stdout, 10, b); + printf ("\ngot i = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nexpected = ["); + mpfr_out_str (stdout, 10, 0, expected_left, MPFI_RNDD); + printf (", "); + mpfr_out_str (stdout, 10, 0, expected_right, MPFI_RNDU); + printf ("]\n"); + exit (1); + } +} + +int +main (int argc, char **argv) +{ + mpfr_t x, y; + + mpz_t a, b; + mpfi_t i; + + mpz_init (a); + mpz_init (b); + mpfi_init2 (i, 53); + mpfr_init2 (x, 53); + mpfr_init2 (y, 53); + + mpz_set_si (a, -10000); + mpz_fac_ui (b, 53); + mpfr_set_z (x, a, MPFI_RNDD); + mpfr_set_z (y, b, MPFI_RNDU); + check (i, a, b, x, y, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, b, a, x, y, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + check (i, a, a, x, x, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + mpfr_set_z (x, b, MPFI_RNDD); + check (i, b, b, x, y, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + + mpz_clear (a); + mpz_clear (b); + mpfi_clear (i); + mpfr_clear (x); + mpfr_clear (y); + + return 0; +} diff --git a/tests/tinv.c b/tests/tinv.c new file mode 100644 index 0000000..a9f1df3 --- /dev/null +++ b/tests/tinv.c @@ -0,0 +1,50 @@ +/* tinv.c -- Test mpfi_inv. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +fr_inv (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd) +{ + return mpfr_ui_div (y, 1, x, rnd); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_inv; + + mpfi_fun_init_II (&i_inv, mpfi_inv, fr_inv); + test_start (); + + check_data (&i_inv, "inv.dat"); + check_random (&i_inv, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_inv); + + return 0; +} diff --git a/tests/tio_str.c b/tests/tio_str.c new file mode 100644 index 0000000..a966e0b --- /dev/null +++ b/tests/tio_str.c @@ -0,0 +1,220 @@ +/* tio_str.c -- Test mpfi_inp_str and mpfi_out_str. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi_io.h" +#include "mpfi-tests.h" + +#define TMP_FILENAME "io_str.tmp" + +void +check_random_interval (mpfr_prec_t prec_min, mpfr_prec_t prec_max, mpfr_prec_t step) +{ + FILE *tmp_file; + size_t n_written, n_read; + int base; + mpfi_t i; + mpfi_t read; + mpfr_prec_t p; + + mpfi_init2 (i, prec_max); + mpfi_init2 (read, prec_max); + + for (p = prec_min; p < prec_max; p += step) { + mpfi_set_prec (i, p); + mpfi_set_prec (read, p); + random_interval (i); + + for (base = 2; base < 63; ++base) { + tmp_file = fopen (TMP_FILENAME, "w"); + if (tmp_file == NULL) { + printf ("Internal error: cannot open temporary file.\n"); + + exit (1); + } + n_written = mpfi_out_str (tmp_file, base, 0, i); + if (n_written == 0) { + printf ("Error: mpfi_out_str (\""TMP_FILENAME"\", base, 0, I) " + "failed.\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nbase = %d\n", base); + + exit (1); + } + if (fclose (tmp_file)) { + printf ("Internal error: cannot close temporary file.\n"); + + exit (1); + } + + tmp_file = fopen (TMP_FILENAME, "r"); + if (tmp_file == NULL) { + printf ("Internal error: cannot open temporary file.\n"); + + exit (1); + } + n_read = mpfi_inp_str (read, tmp_file, base); + /* Note: there is a bug in mpfr_out_str (used by mpfi_out_str): it does + not return the correct number of written characters for a special + values */ + if (mpfi_is_inside (i, read) == 0 + || (!MPFI_NAN_P (i) && !MPFI_INF_P (i) && n_read != n_written)) { + printf ("Error: mpfi_inp_str (I, \""TMP_FILENAME"\", base) did not " + "read correctly the output of mpfi_out_str.\n interval " + "read: \'"); + mpfi_out_str (stdout, 16, 0, read); + printf ("\'\ninterval written: \'"); + mpfi_out_str (stdout, 16, 0, i); + printf ("\'\nbase: %u\n", base); + + if (!MPFI_NAN_P (i) && !MPFI_INF_P (i) && n_read != n_written) { + printf ("mpfi_inp_str did not read the complete output of " + "mpfi_out_str.\nnumber of read characters: %zu\n" + "expected: %zu\n", n_read, n_written); + } + + exit (1); + } + if (fclose (tmp_file)) { + printf ("Internal error: cannot close temporary file.\n"); + exit (1); + } + + } + } + + mpfi_clear (i); + mpfi_clear (read); +} + +void +check_file (const char *datafile) +{ + FILE *stream_mpfr; + FILE *stream_mpfi; + int c; + + int base; + mpfr_prec_t p; + mpfr_t r; + mpfi_t i; + size_t n_mpfr, n_mpfi; + + mpfr_init2 (r, 1024); + mpfi_init2 (i, 1024); + + stream_mpfr = open_file (datafile); + stream_mpfi = open_file (datafile); + + for (p = 2; p < 1024; p += 17) { + mpfr_set_prec (r, p); + mpfi_set_prec (i, p); + for (base = 2; base < 63 ; ++base) { + if (fseek (stream_mpfr, 0, SEEK_SET)) { + printf ("Internal error: cannot reset position to the start of the " + "file \"%s\"\n", datafile); + + exit (1); + } + if (fseek (stream_mpfi, 0, SEEK_SET)) { + printf ("Internal error: cannot reset position to the start of the " + "file \"%s\"\n", datafile); + + exit (1); + } + n_mpfr = mpfr_inp_str (r, stream_mpfr, base, MPFR_RNDN); + n_mpfi = mpfi_inp_str (i, stream_mpfi, base); + + if (n_mpfr != n_mpfi) { + printf ("Error: mpfi_inp_str does not read the same number of " + "characters as mpfr_inp_str in file \"%s\" line 1.\n" + " read: %zu\nexpected: %zu\n", datafile, n_mpfi, n_mpfr); + + exit (1); + } + + if (!mpfi_is_inside_fr (r, i)) { + printf ("Error: when reading the file \"%s\" line 1, the number R " + "read with\nmpfr_inp_str (R, \"%s\", %u, MPFR_RNDN)\nis not " + "included in the interval I read with\nmpfi_inp_str " + "(I, \"%s\", %u)\nR = ", datafile, datafile, base, datafile, + base); + mpfr_out_str (stdout, base, 0, r, MPFR_RNDN); + printf ("(in base %u)\nI = ", base); + mpfi_out_str (stdout, base, 0, i); + printf ("(in base %u)\n", base); + + exit (1); + } + } + + while ((c = getc (stream_mpfr)) != EOF) { + ungetc (c, stream_mpfr); + + n_mpfr = mpfr_inp_str (r, stream_mpfr, 10, MPFR_RNDN); + n_mpfi = mpfi_inp_str (i, stream_mpfi, 10); + + if (n_mpfr != n_mpfi) { + printf ("Error: mpfi_inp_str does not read the same number of " + "characters as mpfr_inp_str in file \"%s\" line 1.\n" + " read: %zu\nexpected: %zu\n", datafile, n_mpfi, n_mpfr); + + exit (1); + } + + if (!mpfi_is_inside_fr (r, i)) { + printf ("Error: when reading the file \"%s\" line 1, the number R " + "read with\nmpfr_inp_str (R, \"%s\", 10, MPFR_RNDN)\nis not " + "included in the interval I read with\nmpfi_inp_str " + "(I, \"%s\", 10)\nR = ", datafile, datafile, datafile); + mpfr_out_str (stdout, 16, 0, r, MPFR_RNDN); + printf ("(in base 16)\nI = "); + mpfi_out_str (stdout, 16, 0, i); + printf ("(in base 16)\n"); + + exit (1); + } + } + } + + fclose (stream_mpfr); + fclose (stream_mpfi); + + mpfr_clear (r); + mpfi_clear (i); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check_random_interval (2, 1000, 43); + check_file ("inp_str.dat"); + + test_end (); + + return 0; +} diff --git a/tests/tis_empty.c b/tests/tis_empty.c new file mode 100644 index 0000000..9e3e0f7 --- /dev/null +++ b/tests/tis_empty.c @@ -0,0 +1,64 @@ +/* tis_empty.c -- Test mpfi_is_empty. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + mpfr_prec_t prec_min = 2; + mpfr_prec_t prec_max = 1000; + mpfr_prec_t prec; + int step = 10; + + mpfi_t i; + + test_start (); + mpfi_init2 (i, 1024); + + for (prec = prec_min; prec <= prec_max; prec += step) { + mpfi_set_prec (i, prec); + random_interval (i); + if (mpfi_is_empty (i)) { + printf ("Error: mpfi_is_empty claims that the interval I = "); + mpfi_out_str (stdout, 10, 0, i); + printf (" is empty.\n"); + exit (1); + } + mpfr_swap (&(i->left), &(i->right)); + if (!mpfi_is_empty (i) && !mpfr_equal_p (&(i->left), &(i->right))) { + printf ("Error: mpfi_is_empty claims that the interval I = "); + mpfi_out_str (stdout, 10, 0, i); + printf (" is not empty.\n"); + exit (1); + } + } + + mpfi_clear (i); + test_end (); + + return 0; +} diff --git a/tests/tis_inside.c b/tests/tis_inside.c new file mode 100644 index 0000000..9b68a7e --- /dev/null +++ b/tests/tis_inside.c @@ -0,0 +1,136 @@ +/* tis_inside.c -- Test mpfi_is_inside. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#define ORDER(min, max) \ + do { \ + if (mpfr_cmp ((min), (max)) > 0) \ + mpfr_swap ((min), (max)); \ + } while (0) + +void +print_error (mpfi_srcptr a, mpfi_srcptr b) +{ + printf ("Error: mpfi_is_inside (A, B) returns %d\nA = ", + mpfi_is_inside (a, b)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nB = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t i1, i2; + mpfr_t a, b, c, d; + int i; + + mpfr_init2 (a, 53); + mpfr_init2 (b, 53); + mpfr_init2 (c, 53); + mpfr_init2 (d, 53); + mpfi_init2 (i1, 53); + mpfi_init2 (i2, 53); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + random_mpfr (a); + random_mpfr (b); + random_mpfr (c); + random_mpfr (d); + ORDER (a, b); + ORDER (a, c); + ORDER (a, d); + ORDER (b, c); + ORDER (b, d); + ORDER (c, d); + + mpfi_interv_fr (i1, a, b); + mpfi_interv_fr (i2, c, d); + if (mpfi_is_inside (i1, i2) && !mpfr_equal_p (b, c)) { + print_error (i1, i2); + } + if (mpfi_is_inside (i2, i1) && !mpfr_equal_p (b, c)) { + print_error (i2, i1); + } + mpfr_set_nan (&(i1->right)); + if (mpfi_is_inside (i1, i2)) { + print_error (i1, i2); + } + + mpfi_interv_fr (i1, a, c); + mpfi_interv_fr (i2, b, d); + if (mpfi_is_inside (i1, i2) && !mpfr_equal_p (a, b) + && !mpfr_equal_p (b, c) && !mpfr_equal_p (c, d)) { + print_error (i1, i2); + } + if (mpfi_is_inside (i2, i1) && !mpfr_equal_p (a, b) + && !mpfr_equal_p (b, c) && !mpfr_equal_p (c, d)) { + print_error (i2, i1); + } + mpfr_set_nan (&(i1->right)); + if (mpfi_is_inside (i1, i2)) { + print_error (i1, i2); + } + + mpfi_interv_fr (i1, a, d); + mpfi_interv_fr (i2, b, c); + if (!(mpfr_equal_p (a, b) && mpfr_equal_p (c, d)) + && mpfi_is_inside (i1, i2)) { + print_error (i1, i2); + } + if (!mpfi_is_inside (i2, i1)) { + print_error (i2, i1); + } + mpfr_set_nan (&(i1->right)); + if (mpfi_is_inside (i2, i1)) { + print_error (i2, i1); + } + } + + mpfr_clear (a); + mpfr_clear (b); + mpfr_clear (c); + mpfr_clear (d); + mpfi_clear (i1); + mpfi_clear (i2); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tis_inside_d.c b/tests/tis_inside_d.c new file mode 100644 index 0000000..bd15eef --- /dev/null +++ b/tests/tis_inside_d.c @@ -0,0 +1,107 @@ +/* tis_inside_d.c -- Test mpfi_is_inside_d. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#include "mpfi_config.h" + +#ifdef HAVE_FLOAT_H +#include +#endif + +/* Warning: DBL_MANT_DIG is not necessary a number of bits */ +#ifndef DBL_MANT_DIG +#define DBL_MANT_DIG 53 +#endif + +#define ORDER(min, max) \ + do { \ + if (min > max) { \ + double tmp; \ + tmp = min; \ + min = max; \ + max = tmp;} \ + } while (0) + +void +print_error (double x, mpfi_srcptr i) +{ + printf ("Error: mpfi_is_inside_d (x, I) returns %d\nx = %g\nI = ", + mpfi_is_inside_d (x, i), x); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check_regular () +{ + mpfi_t interval; + double a, b, c; + int i; + + mpfi_init2 (interval, DBL_MANT_DIG); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + a = random_double (); + b = random_double (); + c = random_double (); + ORDER (a, b); + ORDER (a, c); + ORDER (b, c); + + mpfi_interv_d (interval, b, c); + if (a != b && mpfi_is_inside_d (a, interval)) { + print_error (a, interval); + } + + mpfi_interv_d (interval, a, c); + if (!mpfi_is_inside_d (b, interval)) { + print_error (b, interval); + } + + mpfi_interv_d (interval, a, b); + if (c != b && mpfi_is_inside_d (c, interval)) { + print_error (c, interval); + } + } + + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check_regular (); + + test_end (); + + return 0; +} diff --git a/tests/tis_inside_fr.c b/tests/tis_inside_fr.c new file mode 100644 index 0000000..fe5b787 --- /dev/null +++ b/tests/tis_inside_fr.c @@ -0,0 +1,102 @@ +/* tis_inside_fr.c -- Test mpfi_is_inside_fr. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +print_error (mpfr_srcptr x, mpfi_srcptr i) +{ + printf ("Error: mpfi_is_inside_fr (x, I) returns %d\nx = ", + mpfi_is_inside_fr (x, i)); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf ("\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t interval; + mpfr_t a, b, c; + int i; + + mpfr_init2 (a, 53); + mpfr_init2 (b, 53); + mpfr_init2 (c, 53); + mpfi_init2 (interval, 53); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + random_interval (interval); + mpfi_alea (b, interval); + mpfr_set (a, &(interval->left), MPFI_RNDD); + mpfr_set (c, &(interval->right), MPFI_RNDU); + + if (!mpfi_is_inside_fr (b, interval)) { + print_error (b, interval); + } + + mpfr_set_nan (&(interval->right)); + if (mpfi_is_inside_fr (b, interval)) { + print_error (b, interval); + } + + mpfi_interv_fr (interval, b, c); + if (!mpfr_equal_p (a, b) && mpfi_is_inside_fr (a, interval)) { + print_error (a, interval); + } + + mpfr_set_nan (&(interval->left)); + if (mpfi_is_inside_fr (a, interval)) { + print_error (a, interval); + } + + mpfi_interv_fr (interval, a, b); + if (!mpfr_equal_p (c, b) && mpfi_is_inside_fr (c, interval)) { + print_error (c, interval); + } + } + + mpfr_clear (a); + mpfr_clear (b); + mpfr_clear (c); + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tis_inside_q.c b/tests/tis_inside_q.c new file mode 100644 index 0000000..0062281 --- /dev/null +++ b/tests/tis_inside_q.c @@ -0,0 +1,111 @@ +/* tis_inside_q.c -- Test mpfi_is_inside_q. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#define ORDER(min, max) \ + do { \ + if (mpq_cmp ((min), (max)) > 0) \ + mpq_swap ((min), (max)); \ + } while (0) + +void +print_error (mpq_ptr x, mpfi_srcptr i) +{ + printf ("Error: mpfi_is_inside_q (x, I) returns %d\nx = ", + mpfi_is_inside_q (x, i)); + mpq_out_str (stdout, 10, x); + printf ("\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t interval; + mpq_t a, b, c; + int i; + + mpq_init (a); + mpq_init (b); + mpq_init (c); + mpfi_init2 (interval, 53); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + random_mpq (a); + random_mpq (b); + random_mpq (c); + ORDER (a, b); + ORDER (a, c); + ORDER (b, c); + + mpfi_interv_q (interval, a, c); + if (!mpfi_is_inside_q (b, interval)) { + print_error (b, interval); + } + + mpfr_set_nan (&(interval->right)); + if (mpfi_is_inside_q (b, interval)) { + print_error (b, interval); + } + + mpfi_interv_q (interval, b, c); + if (!mpq_cmp (a, b) != 0 && mpfi_is_inside_q (a, interval)) { + print_error (a, interval); + } + + mpfr_set_nan (&(interval->left)); + if (mpfi_is_inside_q (a, interval)) { + print_error (a, interval); + } + + mpfi_interv_q (interval, a, b); + if (mpq_cmp (c, b) != 0 && mpfi_is_inside_q (c, interval)) { + print_error (c, interval); + } + } + + mpq_clear (a); + mpq_clear (b); + mpq_clear (c); + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tis_inside_si.c b/tests/tis_inside_si.c new file mode 100644 index 0000000..69947af --- /dev/null +++ b/tests/tis_inside_si.c @@ -0,0 +1,119 @@ +/* tis_inside_si.c -- Test mpfi_is_inside_si. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#include "mpfi_config.h" + +#ifdef HAVE_LIMITS_H +#include +#endif +#ifndef LONG_MAX +# define LONG_MAX +2147483647 +#endif + +#define ORDER(min, max) \ + do { \ + if (min > max) { \ + long tmp; \ + tmp = min; \ + min = max; \ + max = tmp;} \ + } while (0) + +void +print_error (long x, mpfi_srcptr i) +{ + printf ("Error: mpfi_is_inside_si (x, I) returns %d\nx = %ld\nI = ", + mpfi_is_inside_si (x, i), x); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t interval; + long a, b, c; + int i; + + i = 1; + a = LONG_MAX; + while (a >>= 1) i++; + + mpfi_init2 (interval, i); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + a = random_si (); + b = random_si (); + c = random_si (); + ORDER (a, b); + ORDER (a, c); + ORDER (b, c); + + mpfi_interv_si (interval, b, c); + if (a != b && mpfi_is_inside_si (a, interval)) { + print_error (a, interval); + } + + mpfr_set_nan (&(interval->left)); + if (mpfi_is_inside_si (a, interval)) { + print_error (a, interval); + } + + mpfi_interv_si (interval, a, c); + if (!mpfi_is_inside_si (b, interval)) { + print_error (b, interval); + } + + mpfr_set_nan (&(interval->right)); + if (mpfi_is_inside_si (b, interval)) { + print_error (b, interval); + } + + mpfi_interv_si (interval, a, b); + if (c != b && mpfi_is_inside_si (c, interval)) { + print_error (c, interval); + } + } + + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tis_inside_ui.c b/tests/tis_inside_ui.c new file mode 100644 index 0000000..8f98ba8 --- /dev/null +++ b/tests/tis_inside_ui.c @@ -0,0 +1,119 @@ +/* tis_inside_ui.c -- Test mpfi_is_inside_ui. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#include "mpfi_config.h" + +#ifdef HAVE_LIMITS_H +#include +#endif +#ifndef ULONG_MAX +# define ULONG_MAX 4294967295 +#endif + +#define ORDER(min, max) \ + do { \ + if (min > max) { \ + unsigned long tmp; \ + tmp = min; \ + min = max; \ + max = tmp;} \ + } while (0) + +void +print_error (unsigned long x, mpfi_srcptr i) +{ + printf ("Error: mpfi_is_inside_ui (x, I) returns %d\nx = %lu\nI = ", + mpfi_is_inside_ui (x, i), x); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t interval; + unsigned long a, b, c; + int i; + + i = 1; + a = ULONG_MAX; + while (a >>= 1) i++; + + mpfi_init2 (interval, i); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + a = random_ui (); + b = random_ui (); + c = random_ui (); + ORDER (a, b); + ORDER (a, c); + ORDER (b, c); + + mpfi_interv_ui (interval, b, c); + if (a != b && mpfi_is_inside_ui (a, interval)) { + print_error (a, interval); + } + + mpfr_set_nan (&(interval->left)); + if (mpfi_is_inside_ui (a, interval)) { + print_error (a, interval); + } + + mpfi_interv_ui (interval, a, c); + if (!mpfi_is_inside_ui (b, interval)) { + print_error (b, interval); + } + + mpfr_set_nan (&(interval->right)); + if (mpfi_is_inside_ui (b, interval)) { + print_error (b, interval); + } + + mpfi_interv_ui (interval, a, b); + if (c != b && mpfi_is_inside_ui (c, interval)) { + print_error (c, interval); + } + } + + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tis_inside_z.c b/tests/tis_inside_z.c new file mode 100644 index 0000000..329d7f1 --- /dev/null +++ b/tests/tis_inside_z.c @@ -0,0 +1,111 @@ +/* tis_inside_z.c -- Test mpfi_is_inside_z. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#define ORDER(min, max) \ + do { \ + if (mpz_cmp ((min), (max)) > 0) \ + mpz_swap ((min), (max)); \ + } while (0) + +void +print_error (mpz_ptr x, mpfi_srcptr i) +{ + printf ("Error: mpfi_is_inside_z (x, I) returns %d\nx = ", + mpfi_is_inside_z (x, i)); + mpz_out_str (stdout, 10, x); + printf ("\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t interval; + mpz_t a, b, c; + int i; + + mpz_init (a); + mpz_init (b); + mpz_init (c); + mpfi_init2 (interval, 53); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + random_mpz (a, 100000); + random_mpz (b, 100000); + random_mpz (c, 100000); + ORDER (a, b); + ORDER (a, c); + ORDER (b, c); + + mpfi_interv_z (interval, a, c); + if (!mpfi_is_inside_z (b, interval)) { + print_error (b, interval); + } + + mpfr_set_nan (&(interval->right)); + if (mpfi_is_inside_z (b, interval)) { + print_error (b, interval); + } + + mpfi_interv_z (interval, b, c); + if (mpz_cmp (a, b) != 0 && mpfi_is_inside_z (a, interval)) { + print_error (a, interval); + } + + mpfr_set_nan (&(interval->left)); + if (mpfi_is_inside_z (a, interval)) { + print_error (a, interval); + } + + mpfi_interv_z (interval, a, b); + if (mpz_cmp (c, b) != 0 && mpfi_is_inside_z (c, interval)) { + print_error (c, interval); + } + } + + mpz_clear (a); + mpz_clear (b); + mpz_clear (c); + mpfi_clear (interval); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tis_neg.c b/tests/tis_neg.c new file mode 100644 index 0000000..6eab10d --- /dev/null +++ b/tests/tis_neg.c @@ -0,0 +1,69 @@ +/* tis_neg.c -- Test mpfi_is_neg. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +void +print_error (mpfi_srcptr a) +{ + printf ("Error: mpfi_is_neg (A) returns %d\nA = ", + mpfi_is_neg (a)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\n"); + + exit (1); +} + +int +main (int argc, char **argv) +{ + FILE *stream; + mpfi_t interval; + int expected; + int got; + + mpfi_init2 (interval, 1024); + + stream = open_file ("is_neg.dat"); + + init_reading (stream); + + while (nextchar != EOF) { + read_sign (stream, &expected); + read_mpfi (stream, interval); + + got = mpfi_is_neg (interval); + if (got != expected || got * expected < 0) + print_error (interval); + } + + close_file (stream); + mpfi_clear (interval); + + return 0; +} diff --git a/tests/tis_nonneg.c b/tests/tis_nonneg.c new file mode 100644 index 0000000..66b7949 --- /dev/null +++ b/tests/tis_nonneg.c @@ -0,0 +1,69 @@ +/* tis_nonneg.c -- Test mpfi_is_nonneg. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +void +print_error (mpfi_srcptr a) +{ + printf ("Error: mpfi_is_nonneg (A) returns %d\nA = ", + mpfi_is_nonneg (a)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\n"); + + exit (1); +} + +int +main (int argc, char **argv) +{ + FILE *stream; + mpfi_t interval; + int expected; + int got; + + mpfi_init2 (interval, 1024); + + stream = open_file ("is_nonneg.dat"); + + init_reading (stream); + + while (nextchar != EOF) { + read_sign (stream, &expected); + read_mpfi (stream, interval); + + got = mpfi_is_nonneg (interval); + if (got != expected || got * expected < 0) + print_error (interval); + } + + close_file (stream); + mpfi_clear (interval); + + return 0; +} diff --git a/tests/tis_nonpos.c b/tests/tis_nonpos.c new file mode 100644 index 0000000..ef0c8c0 --- /dev/null +++ b/tests/tis_nonpos.c @@ -0,0 +1,69 @@ +/* tis_nonpos.c -- Test mpfi_is_nonpos. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +void +print_error (mpfi_srcptr a) +{ + printf ("Error: mpfi_is_nonpos (A) returns %d\nA = ", + mpfi_is_nonpos (a)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\n"); + + exit (1); +} + +int +main (int argc, char **argv) +{ + FILE *stream; + mpfi_t interval; + int expected; + int got; + + mpfi_init2 (interval, 1024); + + stream = open_file ("is_nonpos.dat"); + + init_reading (stream); + + while (nextchar != EOF) { + read_sign (stream, &expected); + read_mpfi (stream, interval); + + got = mpfi_is_nonpos (interval); + if (got != expected || got * expected < 0) + print_error (interval); + } + + close_file (stream); + mpfi_clear (interval); + + return 0; +} diff --git a/tests/tis_pos.c b/tests/tis_pos.c new file mode 100644 index 0000000..9736afd --- /dev/null +++ b/tests/tis_pos.c @@ -0,0 +1,69 @@ +/* tis_pos.c -- Test mpfi_is_pos. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +void +print_error (mpfi_srcptr a) +{ + printf ("Error: mpfi_is_pos (A) returns %d\nA = ", + mpfi_is_pos (a)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\n"); + + exit (1); +} + +int +main (int argc, char **argv) +{ + FILE *stream; + mpfi_t interval; + int expected; + int got; + + mpfi_init2 (interval, 1024); + + stream = open_file ("is_pos.dat"); + + init_reading (stream); + + while (nextchar != EOF) { + read_sign (stream, &expected); + read_mpfi (stream, interval); + + got = mpfi_is_pos (interval); + if (got != expected || got * expected < 0) + print_error (interval); + } + + close_file (stream); + mpfi_clear (interval); + + return 0; +} diff --git a/tests/tis_strictly_inside.c b/tests/tis_strictly_inside.c new file mode 100644 index 0000000..9016382 --- /dev/null +++ b/tests/tis_strictly_inside.c @@ -0,0 +1,134 @@ +/* tis_strictly_inside.c -- Test mpfi_is_strictly_inside. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +#define ORDER(min, max) \ + do { \ + if (mpfr_cmp ((min), (max)) > 0) \ + mpfr_swap ((min), (max)); \ + } while (0) + +void +print_error (mpfi_srcptr a, mpfi_srcptr b) +{ + printf ("Error: mpfi_is_strictly_inside (A, B) returns %d\nA = ", + mpfi_is_strictly_inside (a, b)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nB = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\n"); + + exit (1); +} + +void +check () +{ + mpfi_t i1, i2; + mpfr_t a, b, c, d; + int i; + + mpfr_init2 (a, 53); + mpfr_init2 (b, 53); + mpfr_init2 (c, 53); + mpfr_init2 (d, 53); + mpfi_init2 (i1, 53); + mpfi_init2 (i2, 53); + + for (i = 0; i <= 1000; ++i) { + /* random numbers a < b < c */ + random_mpfr (a); + random_mpfr (b); + random_mpfr (c); + random_mpfr (d); + ORDER (a, b); + ORDER (a, c); + ORDER (a, d); + ORDER (b, c); + ORDER (b, d); + ORDER (c, d); + + mpfi_interv_fr (i1, a, b); + mpfi_interv_fr (i2, c, d); + if (mpfi_is_strictly_inside (i1, i2)) { + print_error (i1, i2); + } + if (mpfi_is_strictly_inside (i2, i1)) { + print_error (i2, i1); + } + mpfr_set_nan (&(i1->right)); + if (mpfi_is_strictly_inside (i1, i2)) { + print_error (i1, i2); + } + + mpfi_interv_fr (i1, a, c); + mpfi_interv_fr (i2, b, d); + if (mpfi_is_strictly_inside (i1, i2)) { + print_error (i1, i2); + } + if (mpfi_is_strictly_inside (i2, i1)) { + print_error (i2, i1); + } + mpfr_set_nan (&(i1->right)); + if (mpfi_is_strictly_inside (i1, i2)) { + print_error (i1, i2); + } + + mpfi_interv_fr (i1, a, d); + mpfi_interv_fr (i2, b, c); + if (mpfi_is_strictly_inside (i1, i2)) { + print_error (i1, i2); + } + if (!mpfi_is_strictly_inside (i2, i1) && !mpfr_equal_p (a, b) + && !mpfr_equal_p (b, c) && !mpfr_equal_p (c, d)) { + print_error (i2, i1); + } + mpfr_set_nan (&(i1->right)); + if (mpfi_is_strictly_inside (i2, i1)) { + print_error (i2, i1); + } + } + + mpfr_clear (a); + mpfr_clear (b); + mpfr_clear (c); + mpfr_clear (d); + mpfi_clear (i1); + mpfi_clear (i2); +} + +int +main (int argc, char **argv) +{ + test_start (); + + check (); + + test_end (); + + return 0; +} diff --git a/tests/tis_strictly_neg.c b/tests/tis_strictly_neg.c new file mode 100644 index 0000000..90a6cc7 --- /dev/null +++ b/tests/tis_strictly_neg.c @@ -0,0 +1,69 @@ +/* tis_strictly_neg.c -- Test mpfi_is_strictly_neg. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +void +print_error (mpfi_srcptr a) +{ + printf ("Error: mpfi_is_strictly_neg (A) returns %d\nA = ", + mpfi_is_strictly_neg (a)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\n"); + + exit (1); +} + +int +main (int argc, char **argv) +{ + FILE *stream; + mpfi_t interval; + int expected; + int got; + + mpfi_init2 (interval, 1024); + + stream = open_file ("is_strictly_neg.dat"); + + init_reading (stream); + + while (nextchar != EOF) { + read_sign (stream, &expected); + read_mpfi (stream, interval); + + got = mpfi_is_strictly_neg (interval); + if (got != expected || got * expected < 0) + print_error (interval); + } + + close_file (stream); + mpfi_clear (interval); + + return 0; +} diff --git a/tests/tis_strictly_pos.c b/tests/tis_strictly_pos.c new file mode 100644 index 0000000..1e8b08f --- /dev/null +++ b/tests/tis_strictly_pos.c @@ -0,0 +1,69 @@ +/* tis_strictly_pos.c -- Test mpfi_is_strictly_pos. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +void +print_error (mpfi_srcptr a) +{ + printf ("Error: mpfi_is_strictly_pos (A) returns %d\nA = ", + mpfi_is_strictly_pos (a)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\n"); + + exit (1); +} + +int +main (int argc, char **argv) +{ + FILE *stream; + mpfi_t interval; + int expected; + int got; + + mpfi_init2 (interval, 1024); + + stream = open_file ("is_strictly_pos.dat"); + + init_reading (stream); + + while (nextchar != EOF) { + read_sign (stream, &expected); + read_mpfi (stream, interval); + + got = mpfi_is_strictly_pos (interval); + if (got != expected || got * expected < 0) + print_error (interval); + } + + close_file (stream); + mpfi_clear (interval); + + return 0; +} diff --git a/tests/tis_zero.c b/tests/tis_zero.c new file mode 100644 index 0000000..6a8c923 --- /dev/null +++ b/tests/tis_zero.c @@ -0,0 +1,90 @@ +/* tis_zero.c -- Test mpfi_is_zero. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +void +print_error (mpfi_srcptr a) +{ + printf ("Error: mpfi_is_zero (A) returns %d\nA = ", + mpfi_is_zero (a)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\n"); + + exit (1); +} + +int +main (int argc, char **argv) +{ + mpfr_t x; + mpfi_t interval; + mpfr_prec_t p; + + test_start (); + + mpfr_init2 (x, 1024); + mpfi_init2 (interval, 1024); + + mpfi_set_ui (interval, 0); + if (!mpfi_is_zero (interval)) { + print_error (interval); + } + + for (p = 2; p < 1024; ++p) { + mpfr_set_prec (x, p); + mpfi_set_prec (interval, p); + + random_mpfr (x); + mpfi_set_fr (interval, x); + if (mpfi_is_zero (interval) && !mpfr_zero_p (x)) { + print_error (interval); + } + + random_mpfr (x); + if (mpfr_zero_p (x)) + mpfr_nextabove (x); + /* x != 0*/ + mpfi_put_fr (interval, x); + if (mpfi_is_zero (interval)) { + print_error (interval); + } + + mpfr_set_nan (&(interval->left)); + if (mpfi_is_zero (interval)) { + print_error (interval); + } + } + + mpfr_clear (x); + mpfi_clear (interval); + + test_end (); + + return 0; +} diff --git a/tests/tlog.c b/tests/tlog.c new file mode 100644 index 0000000..d3cfada --- /dev/null +++ b/tests/tlog.c @@ -0,0 +1,44 @@ +/* tlog.c -- Test mpfi_log. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_log; + + mpfi_fun_init_II (&i_log, mpfi_log, mpfr_log); + test_start (); + + check_data (&i_log, "log.dat"); + check_random (&i_log, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_log); + + return 0; +} diff --git a/tests/tlog10.c b/tests/tlog10.c new file mode 100644 index 0000000..b930a91 --- /dev/null +++ b/tests/tlog10.c @@ -0,0 +1,61 @@ +/* tlog10.c -- Test mpfi_log10. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +restrict_domain (mpfi_ptr a) +{ + /* speedup some tests restricting the possible random values */ + if (mpfr_cmp_si (&(a->left), -100) < 0 + || mpfr_cmp_si (&(a->left), +100) > 0) { + mpfr_set_si (&(a->left), -100, MPFI_RNDD); + } + if (mpfr_cmp_si (&(a->right), -100) < 0 + || mpfr_cmp_si (&(a->right), +100) > 0) { + mpfr_set_si (&(a->right), 100, MPFI_RNDU); + } + return 0; +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_log10; + + mpfi_fun_init_II (&i_log10, mpfi_log10, mpfr_log10); + mpfi_restrict_random (&i_log10, restrict_domain); + + test_start (); + + check_data (&i_log10, "log10.dat"); + check_random (&i_log10, 2, 512, 10); + + test_end (); + mpfi_fun_clear (&i_log10); + + return 0; +} diff --git a/tests/tlog1p.c b/tests/tlog1p.c new file mode 100644 index 0000000..7404c12 --- /dev/null +++ b/tests/tlog1p.c @@ -0,0 +1,44 @@ +/* tlog1p.c -- Test mpfi_log1p. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_log1p; + + mpfi_fun_init_II (&i_log1p, mpfi_log1p, mpfr_log1p); + test_start (); + + check_data (&i_log1p, "log1p.dat"); + check_random (&i_log1p, 2, 512, 10); + + test_end (); + mpfi_fun_clear (&i_log1p); + + return 0; +} diff --git a/tests/tlog2.c b/tests/tlog2.c new file mode 100644 index 0000000..fa1162d --- /dev/null +++ b/tests/tlog2.c @@ -0,0 +1,44 @@ +/* tlog2.c -- Test mpfi_log2. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_log2; + + mpfi_fun_init_II (&i_log2, mpfi_log2, mpfr_log2); + test_start (); + + check_data (&i_log2, "log2.dat"); + check_random (&i_log2, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_log2); + + return 0; +} diff --git a/tests/tmag.c b/tests/tmag.c new file mode 100644 index 0000000..6a7dba7 --- /dev/null +++ b/tests/tmag.c @@ -0,0 +1,107 @@ +/* tmag.c -- Test mpfi_mag. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +test_random (mpfr_prec_t prec_min, mpfr_prec_t prec_max) +{ + mpfr_t x; + mpfi_t i; + mpfr_prec_t prec; + int dl, dr, d0; + int ret; + + mpfr_init2 (x, prec_max); + mpfi_init2 (i, prec_max); + + for (prec = prec_min; prec < prec_max; prec++) { + mpfi_set_prec (i, prec); + mpfr_set_prec (x, prec); + random_interval (i); + ret = mpfi_mag (x, i); + dl = mpfr_cmp_abs (x, &(i->left)); + dr = mpfr_cmp_abs (x, &(i->right)); + if (dl < 0 || dr < 0) { + printf ("Error: mpfi_mag(x, I) returns a value x less than some " + "elements in I.\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf ("\n"); + exit (1); + } + d0 = mpfr_cmp_ui (x, 0); + if (d0 < 0) { + printf ("Error: mpfi_mag(x, I) returns a negative value.\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf ("\n"); + exit (1); + } + if (dl != 0 && dr != 0 && d0 != 0) { + printf ("Error: mpfi_mag(x, I) returns a value x that is not an " + "endpoint of abs(I).\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf ("\n"); + exit (1); + } + if (ret != 0) { + printf ("Error: mpfi_mag(x, I) returns a nonexact value x while the " + "precisions of x and I are equal.\nprecision(I) = %lu, I = ", + mpfi_get_prec (i)); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nprecision(x) = %lu, x = ", mpfr_get_prec (x)); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf ("\n"); + exit (1); + } + } + + mpfr_clear (x); + mpfi_clear (i); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mag; + + mpfi_fun_init_RI (&i_mag, mpfi_mag, NULL); + + test_start (); + + check_data (&i_mag, "mag.dat"); + test_random (2, 1023); + + test_end (); + mpfi_fun_clear (&i_mag); + + return 0; +} diff --git a/tests/tmid.c b/tests/tmid.c new file mode 100644 index 0000000..3dd629d --- /dev/null +++ b/tests/tmid.c @@ -0,0 +1,118 @@ +/* tmid.c -- Test mpfi_mid. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow (void) +{ + mpfi_t i; + mpfr_t expected; + mpfr_t got; + int inex; + + mpfr_init2 (expected, 128); + mpfr_init2 (got, 128); + mpfi_init2 (i, 128); + + mpfr_set_inf (&(i->right), +1); + mpfr_nextbelow (&(i->right)); + mpfr_set (expected, &(i->right), MPFI_RNDD); + mpfr_nextbelow (expected); + mpfr_set (&(i->left), expected, MPFI_RNDD); + mpfr_nextbelow (&(i->left)); + + inex = mpfi_mid (got, i); + + if (mpfr_cmp (got, expected) != 0 || inex != 0) { + printf ("Error: mpfi_mid(I) does not correct value.\nI ="); + mpfi_out_str (stdout, 16, 0, I); + printf (" result: "); + mpfr_out_str (stdout, 16, 0, got, MPFI_RNDU); + if (inex >= 0) { + printf ("return value: %d\n expected: 0\n", inex); + } + else { + printf ("\nexpected: "); + mpfr_out_str (stdout, 16, 0, expected, MPFI_RNDU); + printf ("\n"); + } + + exit (1); + } + + mpfr_clear (expected); + mpfr_clear (got); + mpfi_clear (i); +} + +void +check_underflow (void) +{ + mpfi_t i; + mpfr_t m; + int inex; + + mpfr_init2 (m, 128); + mpfi_init2 (i, 128); + mpfi_set_ui (i, 0); + mpfr_nextabove (&(i->right)); + + inex = mpfi_mid (m, i); + + if (!mpfr_zero_p (m) || inex >= 0) { + printf ("Error: mpfi_mid(I) does not correct value.\nI ="); + mpfi_out_str (stdout, 10, 0, I); + printf (" result: "); + mpfr_out_str (stdout, 10, 0, m, MPFI_RNDU); + if (inex >= 0) { + printf ("return value: %d\n expected: -1\n", inex); + } + else { + printf ("\nexpected: 0\n"); + } + exit (1); + } + + mpfr_clear (m); + mpfi_clear (i); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mid; + + mpfi_fun_init_RI (&i_mid, mpfi_mid, NULL); + + check_data (&i_mid, "mid.dat"); + check_overflow (); + check_underflow (); + + mpfi_fun_clear (&i_mid); + + return 0; +} diff --git a/tests/tmig.c b/tests/tmig.c new file mode 100644 index 0000000..3c915cf --- /dev/null +++ b/tests/tmig.c @@ -0,0 +1,107 @@ +/* tmig.c -- Test mpfi_mig. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +test_random (mpfr_prec_t prec_min, mpfr_prec_t prec_max) +{ + mpfr_t x; + mpfi_t i; + mpfr_prec_t prec; + int dl, dr, d0; + int ret; + + mpfr_init2 (x, prec_max); + mpfi_init2 (i, prec_max); + + for (prec = prec_min; prec < prec_max; prec++) { + mpfi_set_prec (i, prec); + mpfr_set_prec (x, prec); + random_interval (i); + ret = mpfi_mig (x, i); + dl = mpfr_cmp_abs (x, &(i->left)); + dr = mpfr_cmp_abs (x, &(i->right)); + if (dl > 0 || dr > 0) { + printf ("Error: mpfi_mig (x, I) returns a value x greater than some " + "elements in I.\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf ("\n"); + exit (1); + } + d0 = mpfr_cmp_ui (x, 0); + if (d0 < 0) { + printf ("Error: mpfi_mig (x, I) returns a negative value.\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf ("\n"); + exit (1); + } + if (dl != 0 && dr != 0 && d0 != 0) { + printf ("Error: mpfi_mig(x, I) returns a value x that is not an " + "endpoint of abs(I).\nI = "); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf ("\n"); + exit (1); + } + if (ret != 0) { + printf ("Error: mpfi_mig(x, I) returns a nonexact value x while the " + "precisions of x and I are equal.\nprecision(I) = %lu, I = ", + mpfi_get_prec (i)); + mpfi_out_str (stdout, 10, 0, i); + printf ("\nprecision(x) = %lu, x = ", mpfr_get_prec (x)); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDD); + printf ("\n"); + exit (1); + } + } + + mpfr_clear (x); + mpfi_clear (i); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mig; + + mpfi_fun_init_RI (&i_mig, mpfi_mig, NULL); + + test_start (); + + check_data (&i_mig, "mig.dat"); + test_random (2, 1023); + + test_end (); + mpfi_fun_clear (&i_mig); + + return 0; +} diff --git a/tests/tmul.c b/tests/tmul.c new file mode 100644 index 0000000..6406b6d --- /dev/null +++ b/tests/tmul.c @@ -0,0 +1,44 @@ +/* tmul.c -- Test mpfi_mul. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mul; + + mpfi_fun_init_III (&i_mul, mpfi_mul, mpfr_mul); + test_start (); + + check_data (&i_mul, "mul.dat"); + check_random (&i_mul, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_mul); + + return 0; +} diff --git a/tests/tmul_2exp.c b/tests/tmul_2exp.c new file mode 100644 index 0000000..d9b7bd1 --- /dev/null +++ b/tests/tmul_2exp.c @@ -0,0 +1,45 @@ +/* tmul_2exp.c -- Test mpfi_mul_2exp. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mul_2exp; + + mpfi_fun_init_IIU (&i_mul_2exp, mpfi_mul_2exp, mpfr_mul_2exp); + + test_start (); + + check_data (&i_mul_2exp, "mul_2ui.dat"); + check_random (&i_mul_2exp, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_mul_2exp); + + return 0; +} diff --git a/tests/tmul_2si.c b/tests/tmul_2si.c new file mode 100644 index 0000000..e4a28f5 --- /dev/null +++ b/tests/tmul_2si.c @@ -0,0 +1,45 @@ +/* tmul_2si.c -- Test mpfi_mul_2si. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mul_2si; + + mpfi_fun_init_IIS (&i_mul_2si, mpfi_mul_2si, mpfr_mul_2si); + + test_start (); + + check_data (&i_mul_2si, "mul_2si.dat"); + check_random (&i_mul_2si, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_mul_2si); + + return 0; +} diff --git a/tests/tmul_2ui.c b/tests/tmul_2ui.c new file mode 100644 index 0000000..3ebec44 --- /dev/null +++ b/tests/tmul_2ui.c @@ -0,0 +1,45 @@ +/* tmul_2ui.c -- Test mpfi_mul_2ui. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mul_2ui; + + mpfi_fun_init_IIU (&i_mul_2ui, mpfi_mul_2ui, mpfr_mul_2ui); + + test_start (); + + check_data (&i_mul_2ui, "mul_2ui.dat"); + check_random (&i_mul_2ui, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_mul_2ui); + + return 0; +} diff --git a/tests/tmul_d.c b/tests/tmul_d.c new file mode 100644 index 0000000..9c3fef7 --- /dev/null +++ b/tests/tmul_d.c @@ -0,0 +1,182 @@ +/* tmul_d.c -- Test mpfi_mul_d. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check (mpfi_ptr got, mpfi_srcptr a, double d, mpfi_srcptr expected, + int expected_retval) +{ + int ret; + + ret = mpfi_mul_d (got, a, d); + if (ret != expected_retval) { + printf ("Error: mpfi_mul does not return expected value.\ninterval: "); + mpfi_out_str (stdout, 16, 0, a); + printf ("\n factor: %g\n got: %d\nexpected: %d\n", + d, ret, expected_retval); + exit (1); + } + if (!same_value (got, expected)) { + printf ("Error: mpfi_mul does not return expected value.\n" + "interval:"); + mpfi_out_str (stdout, 16, 0, a); + printf ("\n factor: %g\n got:", d); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected:"); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\n"); + exit (1); + } +} + +void +check_overflow () +{ + mpfi_t a, b, c; + + mpfi_init2 (a, 53); + mpfi_init2 (b, 53); + mpfi_init2 (c, 53); + + mpfr_set_ui (&(a->left), 10, MPFI_RNDD); + mpfr_set_inf (&(a->right), +1); + mpfr_nextbelow (&(a->right)); + mpfr_set_ui (&(c->left), 15, MPFI_RNDD); + mpfr_set_inf (&(c->right), +1); + check (b, a, 1.5, c, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + + mpfr_set_inf (&(a->left), -1); + mpfr_nextabove (&(a->left)); + mpfr_set_ui (&(a->right), 10, MPFI_RNDU); + mpfr_set_inf (&(c->left), -1); + mpfr_set_ui (&(c->right), 15, MPFI_RNDD); + check (b, a, 1.5, c, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + + mpfr_set_inf (&(a->left), -1); + mpfr_nextabove (&(a->left)); + mpfr_set_str (&(a->right), "0x123456789abcdfp-53", 0, MPFI_RNDU); + mpfr_set_inf (&(c->left), -1); + mpfr_set_str (&(c->right), "0x1b4e81b4e81b4fp-53", 0, MPFI_RNDU); + check (b, a, 1.5, c, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + + mpfi_clear (a); + mpfi_clear (b); + mpfi_clear (c); +} + +void +check_underflow () +{ + mpfi_t a, b, c; + + mpfi_init2 (a, 53); + mpfi_init2 (b, 53); + mpfi_init2 (c, 53); + + mpfr_set_si (&(a->left), 0, MPFI_RNDD); + mpfr_nextabove (&(a->left)); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + mpfi_interv_d (c, 0, 0.5); + check (b, a, 0.5, c, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + + mpfi_interv_d (c, -0.25, 0); + check (b, a, -0.25, c, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + + mpfi_neg (a, a); + mpfi_interv_d (c, -0.125, 0); + check (b, a, 0.125, c, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + + mpfi_interv_d (c, 0.625, 0); + check (b, a, -0.625, c, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + + mpfr_set_si (&(a->left), -1, MPFI_RNDD); + mpfr_set_ui (&(a->right), 0, MPFI_RNDU); + mpfr_nextabove (&(a->right)); + mpfr_set_d (&(c->left), -0.5, MPFI_RNDD); + mpfr_set (&(c->right), &(a->right), MPFI_RNDU); + check (b, a, 0.5, c, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + + mpfi_neg (c, c); + mpfr_set_d (&(c->right), 0.25, MPFI_RNDU); + check (b, a, -0.25, c, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + + mpfi_neg (a, a); + mpfr_set_d (&(c->right), 0.125, MPFI_RNDU); + check (b, a, 0.125, c, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + + mpfi_neg (c, c); + mpfr_set_d (&(c->left), -0.625, MPFI_RNDU); + check (b, a, -0.625, c, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + + mpfi_clear (a); + mpfi_clear (b); + mpfi_clear (c); +} + +void +check_nan () +{ + double nan; + mpfi_t a, b, c; + + nan = 0.0/0.0; + if (nan == nan) + return; + + mpfi_init2 (a, 53); + mpfi_init2 (b, 53); + mpfi_init2 (c, 53); + + mpfi_set_ui (a, 10); + mpfr_set_nan (&(c->left)); + mpfr_set_nan (&(c->right)); + check (b, a, nan, c, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_clear (a); + mpfi_clear (b); + mpfi_clear (c); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mul_d; + + mpfi_fun_init_IID (&i_mul_d, mpfi_mul_d, mpfr_mul_d); + test_start (); + + check_data (&i_mul_d, "mul_d.dat"); + check_random (&i_mul_d, 2, 1000, 10); + check_overflow (); + check_underflow (); + check_nan (); + + test_end (); + mpfi_fun_clear (&i_mul_d); + + return 0; +} diff --git a/tests/tmul_fr.c b/tests/tmul_fr.c new file mode 100644 index 0000000..640a281 --- /dev/null +++ b/tests/tmul_fr.c @@ -0,0 +1,145 @@ +/* tmul_fr.c -- Test mpfi_mul_fr. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfr_t x; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_init2 (x, 53); + mpfr_set_ui_2exp (x, 1, 1024, MPFI_RNDD); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_mul_fr (a, a, x); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_mul_fr does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_mul_fr does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_mul_fr (a, a, x); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_mul_fr does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_mul_fr does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); + mpfr_clear (x); +} + +void +check_underflow (void) +{ + mpfi_t got, expected; + mpfr_t x; + int inex; + + mpfr_init2 (x, 128); + mpfi_init2 (got, 128); + mpfi_init2 (expected, 128); + + mpfr_set_ui_2exp (x, 1, -1024, MPFI_RNDD); + mpfi_set_ui (expected, 0); + mpfr_nextbelow (&(expected->left)); + mpfr_nextabove (&(expected->right)); + + inex = mpfi_mul_fr (got, expected, x); + if (!MPFI_BOTH_ARE_INEXACT(inex) + || !same_mpfr_value (&(got->left), &(expected->left)) + || !same_mpfr_value (&(got->right), &(expected->right))) { + printf ("Error: mpfi_mul_fr (rop, op, x) does not return correct value\n" + "op = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\nx = "); + mpfr_out_str (stdout, 16, 0, x, MPFI_RNDD); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + printf ("\n"); + + if (!MPFI_BOTH_ARE_INEXACT(inex)) { + printf ("return value = %d\nexpected = %d\n", inex, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + } + + exit (1); + } + + mpfr_clear (x); + mpfi_clear (got); + mpfi_clear (expected); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mul_fr; + + mpfi_fun_init_IIR (&i_mul_fr, mpfi_mul_fr, mpfr_mul); + test_start (); + + check_data (&i_mul_fr, "mul_fr.dat"); + check_random (&i_mul_fr, 2, 1000, 10); + check_overflow (); + check_underflow (); + + test_end (); + mpfi_fun_clear (&i_mul_fr); + + return 0; +} diff --git a/tests/tmul_q.c b/tests/tmul_q.c new file mode 100644 index 0000000..5f36a77 --- /dev/null +++ b/tests/tmul_q.c @@ -0,0 +1,182 @@ +/* tmul_q.c -- Test mpfi_mul_q. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + mpq_t q; + int inexact; + + mpq_init (q); + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + + /* [3, Max] * 4096/3 = [4096, +oo] */ + mpq_set_ui (q, 4096, 3); + mpfr_set_ui (&(a->left), 3, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_mul_q (a, a, q); + if (!mpfr_inf_p (&(a->right))) { + printf ("Error[1]: mpfi_mul_q does not correctly handle positive " + "overflow.\n"); + exit (1); + } + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error[1]: mpfi_mul_q does not return correct value in positive " + "overflow.\nGot: %d, expected: %d\n", inexact, + MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + exit (1); + } + + /* [3, Max] * -4096/3 = [-oo, -4096] */ + mpfr_set_ui (&(a->left), 3, MPFI_RNDD); + mpfr_set (&(a->right), max, MPFI_RNDU); + mpq_neg (q, q); + + inexact = mpfi_mul_q (a, a, q); + if (!mpfr_inf_p (&(a->left))) { + printf ("Error[1]: mpfi_mul_q does not correctly handle negative " + "overflow.\n"); + exit (1); + } + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error[1]: mpfi_mul_q does not return correct value in negative " + "overflow.\nGot: %d, expected: %d\n", inexact, + MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + exit (1); + } + + /* [-Max, 3] * -4096/3 = [-4096, +oo] */ + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 3, MPFI_RNDU); + + inexact = mpfi_mul_q (a, a, q); + if (!mpfr_inf_p (&(a->right))) { + printf ("Error[2]: mpfi_mul_q does not correctly handle positive " + "overflow.\n"); + exit (1); + } + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error[2]: mpfi_mul_q does not return correct value in positive " + "overflow.\nGot: %d, expected: %d\n", inexact, + MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + exit (1); + } + + /* [-Max, 3] * 4096/3 = [-oo, 4096] */ + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 3, MPFI_RNDU); + mpq_neg (q, q); + + inexact = mpfi_mul_q (a, a, q); + if (!mpfr_inf_p (&(a->left))) { + printf ("Error[2]: mpfi_mul_q does not correctly handle negative " + "overflow.\n"); + exit (1); + } + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error[2]: mpfi_mul_q does not return correct value in negative " + "overflow.\nGot: %d, expected: %d\n", inexact, + MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + exit (1); + } + + mpq_clear (q); + mpfi_clear (a); + mpfr_clear (max); +} + +void +check_underflow (void) +{ + mpfi_t got, expected; + mpq_t q; + int inex; + + mpq_init (q); + mpfi_init2 (got, 128); + mpfi_init2 (expected, 128); + + mpq_set_ui (q, 1, 1024); + mpfi_set_ui (expected, 0); + mpfr_nextbelow (&(expected->left)); + mpfr_nextabove (&(expected->right)); + + inex = mpfi_mul_q (got, expected, q); + if (!MPFI_BOTH_ARE_INEXACT(inex) + || !same_mpfr_value (&(got->left), &(expected->left)) + || !same_mpfr_value (&(got->right), &(expected->right))) { + printf ("Error: mpfi_mul_q (rop, op, q) does not return correct value\n" + "op = "); + mpfi_out_str (stdout, 10, 0, expected); + printf ("\nq = "); + mpq_out_str (stdout, 10, q); + printf ("\ngot = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 10, 0, expected); + printf ("\n"); + + if (!MPFI_BOTH_ARE_INEXACT(inex)) { + printf ("return value = %d\nexpected = %d\n", inex, + MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT); + } + + exit (1); + } + + mpq_clear (q); + mpfi_clear (got); + mpfi_clear (expected); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mul_q; + + mpfi_fun_init_IIQ (&i_mul_q, mpfi_mul_q, mpfr_mul_q); + test_start (); + + check_data (&i_mul_q, "mul_q.dat"); + check_random (&i_mul_q, 2, 1000, 10); + check_overflow (); + check_underflow (); + + test_end (); + mpfi_fun_clear (&i_mul_q); + + return 0; +} diff --git a/tests/tmul_si.c b/tests/tmul_si.c new file mode 100644 index 0000000..5d20d42 --- /dev/null +++ b/tests/tmul_si.c @@ -0,0 +1,97 @@ +/* tmul_si.c -- Test mpfi_mul_si. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_mul_si (a, a, 1024); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_mul_si does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_mul_si does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_mul_si (a, a, 1024); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_mul_si does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_mul_si does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mul_si; + + mpfi_fun_init_IIS (&i_mul_si, mpfi_mul_si, mpfr_mul_si); + + test_start (); + + check_data (&i_mul_si, "mul_si.dat"); + check_random (&i_mul_si, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_mul_si); + + return 0; +} diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c new file mode 100644 index 0000000..93ec936 --- /dev/null +++ b/tests/tmul_ui.c @@ -0,0 +1,97 @@ +/* tmul_ui.c -- Test mpfi_mul_ui. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_mul_ui (a, a, 1024); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_mul_ui does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_mul_ui does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_mul_ui (a, a, 1024); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_mul_ui does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_mul_ui does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mul_ui; + + mpfi_fun_init_IIU (&i_mul_ui, mpfi_mul_ui, mpfr_mul_ui); + + test_start (); + + check_data (&i_mul_ui, "mul_ui.dat"); + check_random (&i_mul_ui, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_mul_ui); + + return 0; +} diff --git a/tests/tmul_z.c b/tests/tmul_z.c new file mode 100644 index 0000000..18d423b --- /dev/null +++ b/tests/tmul_z.c @@ -0,0 +1,100 @@ +/* tmul_z.c -- Test mpfi_mul_z. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + mpz_t z; + int inexact; + + mpz_init (z); + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpz_set_ui (z, 4096); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_mul_z (a, a, z); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_mul_z does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_mul_z does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_mul_z (a, a, z); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_mul_z does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_mul_z does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpz_clear (z); + mpfi_clear (a); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_mul_z; + + mpfi_fun_init_IIZ (&i_mul_z, mpfi_mul_z, mpfr_mul_z); + test_start (); + + check_data (&i_mul_z, "mul_z.dat"); + check_random (&i_mul_z, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_mul_z); + + return 0; +} diff --git a/tests/tnan_p.c b/tests/tnan_p.c new file mode 100644 index 0000000..53bb84c --- /dev/null +++ b/tests/tnan_p.c @@ -0,0 +1,69 @@ +/* tnan_p.c -- Test mpfi_nan_p. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern int nextchar; + +void +print_error (mpfi_srcptr a) +{ + printf ("Error: mpfi_nan_p (A) returns %d\nA = ", + mpfi_nan_p (a)); + mpfi_out_str (stdout, 10, 0, a); + printf ("\n"); + + exit (1); +} + +int +main (int argc, char **argv) +{ + FILE *stream; + mpfi_t interval; + int expected; + int got; + + mpfi_init2 (interval, 1024); + + stream = open_file ("nan_p.dat"); + + init_reading (stream); + + while (nextchar != EOF) { + read_sign (stream, &expected); + read_mpfi (stream, interval); + + got = mpfi_nan_p (interval); + if (got != expected || got * expected < 0) + print_error (interval); + } + + close_file (stream); + mpfi_clear (interval); + + return 0; +} diff --git a/tests/tneg.c b/tests/tneg.c new file mode 100644 index 0000000..caa2b81 --- /dev/null +++ b/tests/tneg.c @@ -0,0 +1,44 @@ +/* tneg.c -- Test mpfi_neg. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_neg; + + mpfi_fun_init_II (&i_neg, mpfi_neg, mpfr_neg); + test_start (); + + check_data (&i_neg, "neg.dat"); + check_random (&i_neg, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_neg); + + return 0; +} diff --git a/tests/tput_d.c b/tests/tput_d.c new file mode 100644 index 0000000..a8a02c0 --- /dev/null +++ b/tests/tput_d.c @@ -0,0 +1,41 @@ +/* tput_d.c -- Test mpfi_put_d. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_put_d; + + mpfi_fun_init_ID (&i_put_d, mpfi_put_d, NULL); + + check_data (&i_put_d, "put_d.dat"); + + mpfi_fun_clear (&i_put_d); + + return 0; +} diff --git a/tests/tput_fr.c b/tests/tput_fr.c new file mode 100644 index 0000000..77058ff --- /dev/null +++ b/tests/tput_fr.c @@ -0,0 +1,41 @@ +/* tput_fr.c -- Test mpfi_put_fr. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_put_fr; + + mpfi_fun_init_IR (&i_put_fr, mpfi_put_fr, NULL); + + check_data (&i_put_fr, "put_fr.dat"); + + mpfi_fun_clear (&i_put_fr); + + return 0; +} diff --git a/tests/tput_q.c b/tests/tput_q.c new file mode 100644 index 0000000..add1113 --- /dev/null +++ b/tests/tput_q.c @@ -0,0 +1,41 @@ +/* tput_q.c -- Test mpfi_put_q. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_put_q; + + mpfi_fun_init_IQ (&i_put_q, mpfi_put_q, NULL); + + check_data (&i_put_q, "put_q.dat"); + + mpfi_fun_clear (&i_put_q); + + return 0; +} diff --git a/tests/tput_si.c b/tests/tput_si.c new file mode 100644 index 0000000..2986d50 --- /dev/null +++ b/tests/tput_si.c @@ -0,0 +1,41 @@ +/* tput_si.c -- Test mpfi_put_si. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_put_si; + + mpfi_fun_init_IS (&i_put_si, mpfi_put_si, NULL); + + check_data (&i_put_si, "put_si.dat"); + + mpfi_fun_clear (&i_put_si); + + return 0; +} diff --git a/tests/tput_ui.c b/tests/tput_ui.c new file mode 100644 index 0000000..6e7a229 --- /dev/null +++ b/tests/tput_ui.c @@ -0,0 +1,41 @@ +/* tput_ui.c -- Test mpfi_put_ui. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_put_ui; + + mpfi_fun_init_IU (&i_put_ui, mpfi_put_ui, NULL); + + check_data (&i_put_ui, "put_ui.dat"); + + mpfi_fun_clear (&i_put_ui); + + return 0; +} diff --git a/tests/tput_z.c b/tests/tput_z.c new file mode 100644 index 0000000..9ea4d00 --- /dev/null +++ b/tests/tput_z.c @@ -0,0 +1,41 @@ +/* tput_z.c -- Test mpfi_put_z. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_put_z; + + mpfi_fun_init_IZ (&i_put_z, mpfi_put_z, NULL); + + check_data (&i_put_z, "put_z.dat"); + + mpfi_fun_clear (&i_put_z); + + return 0; +} diff --git a/tests/tq_div.c b/tests/tq_div.c new file mode 100644 index 0000000..cd82485 --- /dev/null +++ b/tests/tq_div.c @@ -0,0 +1,119 @@ +/* tq_div.c -- Test mpfi_q_div. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +error_message (int inex, int expected_inex, mpfi_ptr got, + mpq_ptr op1, mpfi_ptr op2, mpfi_ptr expected) +{ + printf ("Failed when checking overflow.\nop1 = "); + mpq_out_str (stdout, 10, op1); + printf ("\nop2 = "); + mpfi_out_str (stdout, 10, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 10, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + exit (1); +} + +void +check_overflow (struct mpfi_function_t *i_q_div) +{ + mpfi_ptr got = MPFI_FUN_ARG (*i_q_div, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*i_q_div, 2, mpfi); + mpq_ptr op1 = MPFI_FUN_ARG (*i_q_div, 3, mpq); + mpfi_ptr op2 = MPFI_FUN_ARG (*i_q_div, 4, mpfi); + int inex; + mpfr_exp_t emin; + mpfr_exp_t emax; + + emin = mpfr_get_emin (); + emax = mpfr_get_emax (); + if (-emax < emin - 1) + return; + + mpfi_set_prec (got, 53); + mpfi_set_prec (expected, 53); + mpfi_set_prec (op2, 53); + + /* op2 = [2^-emax, 1] */ + mpfr_set_ui_2exp (&(op2->left), 1, -emax, MPFI_RNDD); + mpfr_set_ui (&(op2->right), 1, MPFI_RNDD); + /* op1 = 6 */ + mpq_set_ui (op1, 6, 1); + inex = mpfi_q_div (got, op1, op2); + mpfr_set_ui (&(expected->left), 6, MPFI_RNDD); + mpfr_set_inf (&(expected->right), +1); + if (inex != 2 || !same_value (got, expected)) { + error_message (inex, 2, got, op1, op2, expected); + } + + /* op1 = 17/3 ~ 6 */ + mpq_set_ui (op1, 17, 3); + inex = mpfi_q_div (got, op1, op2); + mpfr_set_q (&(expected->left), op1, MPFI_RNDD); + if (inex != 3 || !same_value (got, expected)) { + error_message (inex, 3, got, op1, op2, expected); + } + + /* op2 = [-1, -2^-emax] */ + mpfi_neg (op2, op2); + inex = mpfi_q_div (got, op1, op2); + mpfr_set_inf (&(expected->left), -1); + mpq_neg (op1, op1); + mpfr_set_q (&(expected->right), op1, MPFI_RNDU); + if (inex != 3 || !same_value (got, expected)) { + error_message (inex, 3, got, op1, op2, expected); + } + + /* op1 = 6 */ + mpq_set_ui (op1, 6, 1); + inex = mpfi_q_div (got, op1, op2); + mpfr_set_si (&(expected->right), -6, MPFI_RNDU); + if (inex != 1 || !same_value (got, expected)) { + error_message (inex, 1, got, op1, op2, expected); + } +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_q_div; + + mpfi_fun_init_IQI (&i_q_div, mpfi_q_div, NULL); + + check_data (&i_q_div, "q_div.dat"); + check_overflow (&i_q_div); + + mpfi_fun_clear (&i_q_div); + + return 0; +} diff --git a/tests/tq_sub.c b/tests/tq_sub.c new file mode 100644 index 0000000..afacfa9 --- /dev/null +++ b/tests/tq_sub.c @@ -0,0 +1,122 @@ +/* tq_sub.c -- Test mpfi_q_sub. + +Copyright 2010, 2012, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" +#include "mpfi_config.h" + +void +check_overflow () +{ + mpfi_t interval; + mpfi_t got; + mpq_t q; + int inex; + + mpfi_init2 (interval, 53); + mpfi_init2 (got, 53); + mpq_init (q); + + /* right overflow: 1023 - [-Max, 0] = [1023, +oo] */ + mpq_set_ui (q, 1023, 1); + mpfr_set_inf (&(interval->left), -1); + mpfr_nextabove (&(interval->left)); + mpfr_set_ui (&(interval->right), 0, MPFI_RNDU); + + inex = mpfi_q_sub (got, q, interval); + + if (MPFI_LEFT_IS_INEXACT (inex) || mpfr_cmp_q (&(got->left), q) != 0 + || !MPFI_RIGHT_IS_INEXACT (inex) || !mpfr_inf_p (&(got->right))) { + printf ("Error: mpfi_q_sub (rop, q, op) does not correctly handle " + "overflow.\n q = "); + mpq_out_str (stdout, 16, q); + printf ("\nop = "); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + /* left overflow: -1023 - [0, Max] = [-oo, -1023] */ + mpq_neg (q, q); + mpfi_neg (interval, interval); + + inex = mpfi_q_sub (got, q, interval); + + if (!MPFI_LEFT_IS_INEXACT (inex) + || !mpfr_inf_p (&(got->left)) + || MPFI_RIGHT_IS_INEXACT (inex) + || mpfr_cmp_si (&(got->right), -1023) != 0) { + printf ("Error: mpfi_q_sub (rop, q, op) does not correctly handle " + "overflow.\n q = "); + mpq_out_str (stdout, 16, q); + printf ("\nop = "); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + mpq_clear (q); + mpfi_clear (interval); + mpfi_clear (got); +} + +#ifndef HAVE_MPFR_Q_SUB +/* fake non-existing function */ +int +mpfr_q_sub (mpfr_ptr x, mpq_srcptr q, mpfr_srcptr y, mpfr_rnd_t rnd) +{ + int ret; + + /* invert rounding mode */ + if (rnd == MPFI_RNDU) + rnd = MPFI_RNDD; + else if (rnd == MPFI_RNDD) + rnd = MPFI_RNDU; + ret = mpfr_sub_q (x, y, q, rnd); + mpfr_neg (x, x, MPFI_RNDU); + return -ret; +} +#endif /* HAVE_MPFR_Q_SUB */ + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_q_sub; + + mpfi_fun_init_IQI (&i_q_sub, mpfi_q_sub, mpfr_q_sub); + test_start (); + + check_data (&i_q_sub, "q_sub.dat"); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_q_sub); + + return 0; +} diff --git a/tests/tround_prec.c b/tests/tround_prec.c new file mode 100644 index 0000000..fd9c081 --- /dev/null +++ b/tests/tround_prec.c @@ -0,0 +1,183 @@ +/* tround_prec.c -- Test mpfi_round_prec. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check (mpfi_ptr i, mpfr_prec_t new_prec, + mpfr_srcptr expected_left, mpfr_srcptr expected_right, + int expected_inex) +{ + int inex; + + inex = mpfi_round_prec (i, new_prec); + if (inex != expected_inex) { + printf ("Error: mpfi_round_prec (i, p) returns %d instead of %d\n", + inex, expected_inex); + printf ("precision of i before function call = %lu\np = %lu\n", + mpfi_get_prec (i), new_prec); + exit (1); + } + if (!same_mpfr_value (&(i->left), expected_left) + || !same_mpfr_value (&(i->right), expected_right)) { + printf ("Error: mpfi_round_prec (i, p) failed.\n"); + printf ("precision of i before function call = %lu\np = %lu\n", + mpfi_get_prec (i), new_prec); + printf ("\ngot i = "); + mpfi_out_str (stdout, 2, 0, i); + printf ("\nexpected = ["); + mpfr_out_str (stdout, 2, 0, expected_left, MPFI_RNDD); + printf (", "); + mpfr_out_str (stdout, 2, 0, expected_right, MPFI_RNDU); + printf ("]\n"); + exit (1); + } +} + +void +special (void) +{ + mpfr_t minf, pinf; + mpfr_t mzero, pzero; + mpfr_t nan; + mpfi_t i; + + mpfi_init2 (i, 53); + mpfr_init2 (minf, 53); + mpfr_init2 (pinf, 53); + mpfr_init2 (mzero, 53); + mpfr_init2 (pzero, 53); + mpfr_init2 (nan, 53); + + mpfr_set_nan (nan); + mpfr_set_inf (minf, -1); + mpfr_set_inf (pinf, +1); + mpfr_set_ui (pzero, 0, MPFI_RNDU); + mpfr_neg (mzero, pzero, MPFI_RNDD); + + mpfr_set (&(i->left), minf, MPFI_RNDD); + mpfr_set (&(i->right), minf, MPFI_RNDU); + check (i, 2, minf, minf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_set_prec (i, 53); + mpfr_set (&(i->left), minf, MPFI_RNDD); + mpfr_set (&(i->right), mzero, MPFI_RNDU); + check (i, 3, minf, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_set_prec (i, 53); + mpfr_set (&(i->left), minf, MPFI_RNDD); + mpfr_set (&(i->right), pinf, MPFI_RNDU); + check (i, 4, minf, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_set_prec (i, 53); + mpfr_set (&(i->left), minf, MPFI_RNDD); + mpfr_set_nan (&(i->right)); + check (i, 5, minf, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_set_prec (i, 53); + mpfr_set (&(i->left), pzero, MPFI_RNDD); + mpfr_set (&(i->right), mzero, MPFI_RNDU); + check (i, 6, pzero, mzero, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_set_prec (i, 53); + mpfr_set (&(i->left), pzero, MPFI_RNDD); + mpfr_set (&(i->right), pinf, MPFI_RNDU); + check (i, 7, pzero, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_set_prec (i, 53); + mpfr_set (&(i->left), pzero, MPFI_RNDD); + mpfr_set_nan (&(i->right)); + check (i, 8, pzero, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_set_prec (i, 53); + mpfr_set (&(i->left), pinf, MPFI_RNDD); + mpfr_set (&(i->right), pinf, MPFI_RNDU); + check (i, 9, pinf, pinf, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_set_prec (i, 53); + mpfr_set_nan (&(i->left)); + mpfr_set_nan (&(i->right)); + check (i, 10, nan, nan, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + mpfi_clear (i); + mpfr_clear (minf); + mpfr_clear (pinf); + mpfr_clear (mzero); + mpfr_clear (pzero); + mpfr_clear (nan); +} + +void +swing (void) +{ + mpfr_prec_t p; + mpfi_t i; + mpfr_t left, right, tmp; + int inex [2] = { + MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT, + MPFI_FLAGS_LEFT_ENDPOINT_INEXACT + }; + + mpfi_init2 (i, 1024); + mpfr_init2 (left, 53); + mpfr_init2 (right, 53); + mpfr_init (tmp); + + mpfr_set_str (left, "0x35555555555555p-54", 0, MPFI_RNDD); + mpfr_set_str (right, "0x35555555555555p-54", 0, MPFI_RNDU); + + mpfi_set_prec (i, 53); + mpfr_set (&(i->left), left, MPFI_RNDD); + mpfr_set (&(i->right), right, MPFI_RNDU); + + check (i, 1024, left, right, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT); + + for (p = 52; p > 2; --p) { + mpfr_set_prec (tmp, p); + mpfr_set (tmp, left, MPFI_RNDD); + mpfr_swap (tmp, left); /* Warning: precisions are swap too */ + + mpfr_set_prec (tmp, p); + mpfr_set (tmp, right, MPFI_RNDU); + mpfr_swap (tmp, right); + + check (i, p, left, right, inex[p % 2]); + } + + mpfi_clear (i); + mpfr_clear (left); + mpfr_clear (right); + mpfr_clear (tmp); +} + +int +main (int argc, char **argv) +{ + special (); + swing (); + + return 0; +} diff --git a/tests/tsec.c b/tests/tsec.c new file mode 100644 index 0000000..1737021 --- /dev/null +++ b/tests/tsec.c @@ -0,0 +1,60 @@ +/* tsec.c -- Test mpfi_sec. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +restrict_domain (mpfi_ptr a) +{ + /* speedup some tests restricting the possible random values */ + if (mpfr_cmp_si (&(a->left), -7) < 0 || mpfr_cmp_si (&(a->left), +7) > 0) { + mpfr_set_si (&(a->left), -7, MPFI_RNDD); + } + if (mpfr_cmp_si (&(a->right), -7) < 0 + || mpfr_cmp_si (&(a->right), +7) > 0) { + mpfr_set_si (&(a->right), 7, MPFI_RNDU); + } + return 0; +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sec; + + mpfi_fun_init_II (&i_sec, mpfi_sec, mpfr_sec); + mpfi_restrict_random (&i_sec, restrict_domain); + + test_start (); + + check_data (&i_sec, "sec.dat"); + check_random (&i_sec, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_sec); + + return 0; +} diff --git a/tests/tsech.c b/tests/tsech.c new file mode 100644 index 0000000..20fba18 --- /dev/null +++ b/tests/tsech.c @@ -0,0 +1,45 @@ +/* tsech.c -- Test mpfi_sech. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sech; + + mpfi_fun_init_II (&i_sech, mpfi_sech, mpfr_sech); + + test_start (); + + check_data (&i_sech, "sech.dat"); + check_random (&i_sech, 2, 512, 10); + + test_end (); + mpfi_fun_clear (&i_sech); + + return 0; +} diff --git a/tests/tset.c b/tests/tset.c new file mode 100644 index 0000000..9029fb5 --- /dev/null +++ b/tests/tset.c @@ -0,0 +1,132 @@ +/* tset.c -- Test file for mpfi_set functions. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_endpoints (mpfi_t i, const char *left, const char *right, + const char *function_name) +{ + mpfr_t l,r; + + mpfr_inits2 (mpfi_get_prec (i), l, r, (mpfr_ptr)0); + + mpfr_set_str (l, left, 0, MPFI_RNDD); + mpfr_set_str (r, right, 0, MPFI_RNDU); + + if (!mpfr_equal_p (&(i->left), l) || !mpfr_equal_p (&(i->right), r)) { + printf ("Error in %s\nexpected [%s, %s]\n got ", + function_name, left, right); + mpfi_out_str (stdout, 16, 0, i); + putchar ('\n'); + exit (1); + } + + mpfr_clears (l, r, (mpfr_ptr)0); +} + +void +check_fi (mpfi_ptr out, mpfi_ptr in, int expected_inex, + const char *left, const char *right) +{ + int inex; + + inex = mpfi_set (out, in); + if (inex != expected_inex) { + printf ("Error: mpfi_set returns unexpected value with input="); + mpfi_out_str (stdout, 10, 0, in); + printf (" and output precision=%lu\nexpected return value: %u, got: %u\n", + mpfi_get_prec (out), expected_inex, inex); + exit (1); + } + check_endpoints (out, left, right, "mpfi_set"); +} + +int +main (int argc, char **argv) +{ + mpfi_t fi1; + mpfi_t fi2; + + mpfi_init2 (fi1, 1024); + mpfi_init2 (fi2, 1024); + + mpfi_set_prec (fi1, 2); + mpfi_set_prec (fi2, 53); + mpfr_set_str (&(fi1->left), "0.1", 0, MPFI_RNDD); + mpfr_set_str (&(fi1->right), "0.1", 0, MPFI_RNDU); + check_fi (fi2, fi1, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, + "0b11p-5", "0b10p-4"); + + mpfr_set_nan (&(fi1->left)); + mpfr_set_nan (&(fi1->right)); + mpfi_set (fi2, fi1); + if (!mpfr_nan_p (&(fi2->left)) || !mpfr_nan_p (&(fi2->right))) { + printf ("Error: mpfi_set does not handle NAN correctly\ngot: "); + mpfi_out_str (stdout, 10, 0, fi2); + putchar ('\n'); + exit (1); + } + + mpfi_set_prec (fi1, 53); + mpfi_set_prec (fi2, 2); + mpfr_set_str (&(fi1->left), "0.1", 0, MPFI_RNDD); + mpfr_set_str (&(fi1->right), "0.1", 0, MPFI_RNDU); + check_fi (fi2, fi1, MPFI_FLAGS_BOTH_ENDPOINTS_INEXACT, + "0x18@-2", "0x2@-1"); + + mpfr_set_str (&(fi1->left), "0.1", 0, MPFI_RNDD); + mpfr_set_str (&(fi1->right), "0.5", 0, MPFI_RNDU); + check_fi (fi2, fi1, MPFI_FLAGS_LEFT_ENDPOINT_INEXACT, + "0x18@-2", "0x8@-1"); + + mpfr_set_str (&(fi1->left), "-0.5", 0, MPFI_RNDD); + mpfr_set_str (&(fi1->right), "-0.1", 0, MPFI_RNDU); + check_fi (fi2, fi1, MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT, + "-0x8@-1", "-0x18@-2"); + + mpfr_set_inf (&(fi1->left), -1); + mpfr_set_inf (&(fi1->right), -1); + check_fi (fi2, fi1, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, + "-@inf@", "-@inf@"); + + /* signed zeros */ + mpfr_set_ui (&(fi1->left), 0, MPFI_RNDU); + mpfr_neg (&(fi1->right), &(fi1->left), MPFI_RNDD); + check_fi (fi2, fi1, MPFI_FLAGS_BOTH_ENDPOINTS_EXACT, + "+0", "-0"); + if (mpfr_signbit (&(fi2->left)) || !mpfr_signbit (&(fi2->right))) { + printf ("Error: mpfi_set does not handle signed zeros correctly\ngot: "); + mpfi_out_str (stdout, 10, 0, fi2); + putchar ('\n'); + exit (1); + } + + mpfi_clear (fi1); + mpfi_clear (fi2); + + return 0; +} diff --git a/tests/tset_d.c b/tests/tset_d.c new file mode 100644 index 0000000..98bca5b --- /dev/null +++ b/tests/tset_d.c @@ -0,0 +1,41 @@ +/* tset_d.c -- Test mpfi_set_d. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_set_d; + + mpfi_fun_init_ID (&i_set_d, mpfi_set_d, NULL); + + check_data (&i_set_d, "set_d.dat"); + + mpfi_fun_clear (&i_set_d); + + return 0; +} diff --git a/tests/tset_flt.c b/tests/tset_flt.c new file mode 100644 index 0000000..87c7b77 --- /dev/null +++ b/tests/tset_flt.c @@ -0,0 +1,38 @@ +/* tset_flt.c -- Test mpfi_set_flt. + +Copyright 2018 + AriC project, Inria Grenoble - Rhone-Alpes, France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_set_flt; + + mpfi_fun_init_IF (&i_set_flt, mpfi_set_flt, NULL); + + check_data (&i_set_flt, "set_flt.dat"); + + mpfi_fun_clear (&i_set_flt); + + return 0; +} diff --git a/tests/tset_fr.c b/tests/tset_fr.c new file mode 100644 index 0000000..2865664 --- /dev/null +++ b/tests/tset_fr.c @@ -0,0 +1,41 @@ +/* tset_fr.c -- Test mpfi_set_fr. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_set_fr; + + mpfi_fun_init_IR (&i_set_fr, mpfi_set_fr, NULL); + + check_data (&i_set_fr, "set_fr.dat"); + + mpfi_fun_clear (&i_set_fr); + + return 0; +} diff --git a/tests/tset_ld.c b/tests/tset_ld.c new file mode 100644 index 0000000..4228d40 --- /dev/null +++ b/tests/tset_ld.c @@ -0,0 +1,38 @@ +/* tset_ld.c -- Test mpfi_set_ld. + +Copyright 2018 + AriC project, Inria Grenoble - Rhone-Alpes, France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_set_ld; + + mpfi_fun_init_IL (&i_set_ld, mpfi_set_ld, NULL); + + check_data (&i_set_ld, "set_ld.dat"); + + mpfi_fun_clear (&i_set_ld); + + return 0; +} diff --git a/tests/tset_q.c b/tests/tset_q.c new file mode 100644 index 0000000..9739ee6 --- /dev/null +++ b/tests/tset_q.c @@ -0,0 +1,41 @@ +/* tset_q.c -- Test mpfi_set_q. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_set_q; + + mpfi_fun_init_IQ (&i_set_q, mpfi_set_q, NULL); + + check_data (&i_set_q, "set_q.dat"); + + mpfi_fun_clear (&i_set_q); + + return 0; +} diff --git a/tests/tset_si.c b/tests/tset_si.c new file mode 100644 index 0000000..95dd939 --- /dev/null +++ b/tests/tset_si.c @@ -0,0 +1,41 @@ +/* tset_si.c -- Test mpfi_set_si. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_set_si; + + mpfi_fun_init_IS (&i_set_si, mpfi_set_si, NULL); + + check_data (&i_set_si, "set_si.dat"); + + mpfi_fun_clear (&i_set_si); + + return 0; +} diff --git a/tests/tset_sj.c b/tests/tset_sj.c new file mode 100644 index 0000000..fdee201 --- /dev/null +++ b/tests/tset_sj.c @@ -0,0 +1,38 @@ +/* tset_sj.c -- Test mpfi_set_sj. + +Copyright 2018-2018 + AriC project, Inria Grenoble - Rhone-Alpes, France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_set_sj; + + mpfi_fun_init_JS (&i_set_sj, mpfi_set_sj, NULL); + + check_data (&i_set_sj, "set_sj.dat"); + + mpfi_fun_clear (&i_set_sj); + + return 0; +} diff --git a/tests/tset_str.c b/tests/tset_str.c new file mode 100644 index 0000000..9346d2f --- /dev/null +++ b/tests/tset_str.c @@ -0,0 +1,235 @@ +/* tset_str.c -- Test file for mpfi_set_str. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_endpoints (mpfi_ptr i, const char *left, const char *right) +{ + mpfr_t l,r; + + mpfr_inits2 (mpfi_get_prec (i), l, r, (mpfr_ptr)0); + + mpfr_set_str (l, left, 0, MPFI_RNDD); + mpfr_set_str (r, right, 0, MPFI_RNDU); + + if (!mpfr_equal_p (&(i->left), l) || !mpfr_equal_p (&(i->right), r)) { + printf ("Error in mpfi_set_str\nexpected [%s, %s]\n got ", + left, right); + mpfi_out_str (stdout, 16, 0, i); + putchar ('\n'); + exit (1); + } + + mpfr_clears (l, r, (mpfr_ptr)0); +} + +void +check_str (mpfi_ptr fi, const char *value, const char *left, const char *right) +{ + int ret; + ret = mpfi_set_str (fi, value, 0); + if (ret) { + printf ("Error when parsing \"%s\"\n", value); + exit (1); + } + check_endpoints (fi, left, right); +} + +void +check_base (mpfi_ptr fi, const char *value, int base, + const char *left, const char *right) +{ + int ret; + ret = mpfi_set_str (fi, value, base); + if (ret) { + printf ("Error when parsing \"%s\"\n", value); + exit (1); + } + check_endpoints (fi, left, right); +} + +void +check_invalid_string (mpfi_ptr fi, const char* s, int base) +{ + int ret; + + ret = mpfi_set_str (fi, s, base); + if (ret != 1) { + printf ("Error when parsing \"%s\":" + " the input string should be considered invalid\n", s); + exit (1); + } +} + +int +main (int argc, char **argv) +{ + int ret; + mpfi_t fi; + + mpfi_init2 (fi, 1024); + + fclose (stderr); /* mute (internal) error messages */ + + /* invalid inputs */ + check_invalid_string (fi, "", 10); + check_invalid_string (fi, " ", 10); + check_invalid_string (fi, ",", 10); + check_invalid_string (fi, "[]", 10); + check_invalid_string (fi, "[,]", 10); + check_invalid_string (fi, "[ ", 10); + check_invalid_string (fi, "[0 ", 10); + check_invalid_string (fi, "[1 , ", 10); + check_invalid_string (fi, "[ 2,", 10); + check_invalid_string (fi, "[3,3.21", 10); + check_invalid_string (fi, "[+4, 44 ", 10); + check_invalid_string (fi, "[-5,5[", 10); + check_invalid_string (fi, "[-6,6 [", 10); + + check_invalid_string (fi, "[0]", 10); + check_invalid_string (fi, "[-1,1,1]", 10); + check_invalid_string (fi, "[2e+2,]", 10); + check_invalid_string (fi, "[,300]", 10); + check_invalid_string (fi, "[+-4,4]", 10); + check_invalid_string (fi, "[5e+,-5]", 10); + check_invalid_string (fi, "[+,6]", 10); + check_invalid_string (fi, "7[1,1]", 10); + check_invalid_string (fi, "[8 8]", 10); + check_invalid_string (fi, "[-0x9,9]", 10); + check_invalid_string (fi, "17 invalid-string", 10); + + check_invalid_string (fi, "[1, 2]", 2); + check_invalid_string (fi, "[1, 3]", 3); + check_invalid_string (fi, "[1, 4]", 4); + check_invalid_string (fi, "[1, 5]", 5); + check_invalid_string (fi, "[1, 6]", 6); + check_invalid_string (fi, "[1, 7]", 7); + check_invalid_string (fi, "[1, 8]", 8); + check_invalid_string (fi, "[1, 9]", 9); + check_invalid_string (fi, "[1, a]", 10); + check_invalid_string (fi, "[1, b]", 11); + check_invalid_string (fi, "[1, c]", 12); + check_invalid_string (fi, "[1, d]", 13); + check_invalid_string (fi, "[1, e]", 14); + check_invalid_string (fi, "[1, f]", 15); + check_invalid_string (fi, "[1, g]", 16); + check_invalid_string (fi, "[1, h]", 17); + check_invalid_string (fi, "[1, i]", 18); + check_invalid_string (fi, "[1, j]", 19); + check_invalid_string (fi, "[1, k]", 20); + check_invalid_string (fi, "[1, l]", 21); + check_invalid_string (fi, "[1, m]", 22); + check_invalid_string (fi, "[1, n]", 23); + check_invalid_string (fi, "[1, o]", 24); + check_invalid_string (fi, "[1, p]", 25); + check_invalid_string (fi, "[1, q]", 26); + check_invalid_string (fi, "[1, r]", 27); + check_invalid_string (fi, "[1, s]", 28); + check_invalid_string (fi, "[1, t]", 29); + check_invalid_string (fi, "[1, u]", 30); + check_invalid_string (fi, "[1, v]", 31); + check_invalid_string (fi, "[1, w]", 32); + check_invalid_string (fi, "[1, x]", 33); + check_invalid_string (fi, "[1, y]", 34); + check_invalid_string (fi, "[1, z]", 35); + + + /* real number inputs */ + check_str (fi, "0", "0", "0"); + check_str (fi, "-1", "-1", "-1"); + check_str (fi, "2e-1", "2e-1", "2e-1"); + + /* special values */ + ret = mpfi_set_str (fi, " [@nan@,@nan@]", 0); + if (ret) { + printf ("Error when parsing \"[@nan@,@nan@]\"\n"); + exit (1); + } + if (!mpfr_nan_p (&(fi->left)) || !mpfr_nan_p (&(fi->right))) { + printf ("Error: mpfi_set_str does not accept NAN\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + ret = mpfi_set_str (fi, "[ 10 , @nan@ ] ", 0); + if (ret) { + printf ("Error when parsing \" [ 10 , @nan@ ] \"\n"); + exit (1); + } + if (!mpfr_nan_p (&(fi->right))) { + printf ("Error: mpfi_set_str does not accept NAN\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + ret = mpfi_set_str (fi, "[@nan@, 20]", 0); + if (ret) { + printf ("Error when parsing \"[ @nan@, 20]\"\n"); + exit (1); + } + if (!mpfr_nan_p (&(fi->left))) { + printf ("Error: mpfi_set_str does not accept NAN\ngot: "); + mpfi_out_str (stdout, 10, 0, fi); + putchar ('\n'); + exit (1); + } + check_str (fi, "[-@inf@, +@inf@]", "-@inf@", "+@inf@"); + check_str (fi, "[+@inf@, -@inf@]", "+@inf@", "-@inf@"); + check_str (fi, "[+0, -0]", "+0", "-0"); + /* no guarantee on the validity of the returned interval */ + check_str (fi, "[-0,+0]", "-0", "+0"); + + + /* check regular values */ + mpfi_set_prec (fi, 2); + check_str (fi, "[0x80001,0x80001]", "0b10p+18", "0b11p+18"); + check_str (fi, "[-0x80001, 0x80001]", "-0b11p+18", "0b11p+18"); + mpfi_set_prec (fi, 16); + check_str (fi, " [0x80001,0xA2310]", "0x8000@+1", "0xa2310"); + check_str (fi, "[ -0xfffff , -0x80001 ] ", "-0x100000", "-0x80000"); + mpfi_set_prec (fi, 20); + check_str (fi, "[-0x80001, 0x80001]", "-0x80001", "0x80001"); + + + /* check bases */ + mpfi_set_prec (fi, 53); + check_base (fi, "101010101010101010101010101010101010101010101010101010101", + 2, "0x155555555555550", "0x155555555555560"); + check_base (fi, "[-10, 10] -ignored-", 3, "-0x3", "+0x3"); + check_base (fi, "[-1@4, 1@40]", 4, "-0x100", "0x1@20"); + check_base (fi, "[-1@53, -1@10]", 5, "-0x85A36366EB71F8@17", "-0x9502F9"); + check_base (fi, "[-1@53, 10]", 6, "-0x20111FB4CE3C18@21", "0x6"); + check_base (fi, "[-1@53, 10]", 7, "-0x1BA95C5079317E@24", "0x7"); + check_base (fi, "[-1@53, 17]", 8, "-0x8@39", "0xf"); + check_base (fi, "[-1@53, 17]", 9, "-0x10112449B5FECD@29", "0x10"); + check_base (fi, "[-1@53, 17]", 16, "-0x1@53", "0x17"); + check_base (fi, "[-baba, zaza]", 36, "-0x808f6", "0x192256"); + + mpfi_clear (fi); + + return 0; +} diff --git a/tests/tset_ui.c b/tests/tset_ui.c new file mode 100644 index 0000000..656b005 --- /dev/null +++ b/tests/tset_ui.c @@ -0,0 +1,41 @@ +/* tset_ui.c -- Test mpfi_set_ui. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_set_ui; + + mpfi_fun_init_IU (&i_set_ui, mpfi_set_ui, NULL); + + check_data (&i_set_ui, "set_ui.dat"); + + mpfi_fun_clear (&i_set_ui); + + return 0; +} diff --git a/tests/tset_uj.c b/tests/tset_uj.c new file mode 100644 index 0000000..02a62cb --- /dev/null +++ b/tests/tset_uj.c @@ -0,0 +1,38 @@ +/* tset_uj.c -- Test mpfi_set_uj. + +Copyright 2018-2018 + AriC project, Inria Grenoble - Rhone-Alpes, France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_set_uj; + + mpfi_fun_init_IU (&i_set_uj, mpfi_set_uj, NULL); + + check_data (&i_set_uj, "set_uj.dat"); + + mpfi_fun_clear (&i_set_uj); + + return 0; +} diff --git a/tests/tset_z.c b/tests/tset_z.c new file mode 100644 index 0000000..2665429 --- /dev/null +++ b/tests/tset_z.c @@ -0,0 +1,41 @@ +/* tset_z.c -- Test mpfi_set_z. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_set_z; + + mpfi_fun_init_IZ (&i_set_z, mpfi_set_z, NULL); + + check_data (&i_set_z, "set_z.dat"); + + mpfi_fun_clear (&i_set_z); + + return 0; +} diff --git a/tests/tsi_div.c b/tests/tsi_div.c new file mode 100644 index 0000000..7c5f09a --- /dev/null +++ b/tests/tsi_div.c @@ -0,0 +1,95 @@ +/* tdiv_si.c -- Test mpfi_si_div. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow (void) +{ + mpfi_t interval; + mpfi_t got; + long si = 1024.0; + int inex; + + mpfi_init2 (interval, 53); + mpfi_init2 (got, 53); + + /* right overflow: 1024 / [epsilon, 1] = [1024, +oo] */ + mpfr_set_ui (&(interval->left), 0, MPFI_RNDD); + mpfr_nextabove (&(interval->left)); /* tiny left endpoint x0 */ + mpfr_set_ui (&(interval->right), 1, MPFI_RNDU); + + inex = mpfi_si_div (got, si, interval); + if (MPFI_LEFT_IS_INEXACT (inex) || mpfr_cmp_si (&(got->left), si) != 0 + || !MPFI_RIGHT_IS_INEXACT (inex) || !mpfr_inf_p (&(got->right))) { + printf ("Error: mpfi_si_div (rop, %ld, op) does not correctly handle " + "overflow.\nop = ", si); + mpfi_out_str (stdout, 10, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + /* left overflow: 1024.0 / [-1, -epsilon] = [-oo, -1024] */ + mpfi_neg (interval, interval); + + inex = mpfi_si_div (got, si, interval); + if (!MPFI_LEFT_IS_INEXACT (inex) + || !mpfr_inf_p (&(got->left)) + || MPFI_RIGHT_IS_INEXACT (inex) + || mpfr_cmp_si (&(got->right), -si) != 0) { + printf ("Error: mpfi_si_div (rop, %ld, op) does not correctly handle " + "overflow.\nop = ", si); + mpfi_out_str (stdout, 10, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + mpfi_clear (interval); + mpfi_clear (got); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_si_div; + + mpfi_fun_init_ISI (&i_si_div, mpfi_si_div, mpfr_si_div); + + test_start (); + + check_data (&i_si_div, "si_div.dat"); + check_random (&i_si_div, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_si_div); + + return 0; +} diff --git a/tests/tsi_sub.c b/tests/tsi_sub.c new file mode 100644 index 0000000..23f1053 --- /dev/null +++ b/tests/tsi_sub.c @@ -0,0 +1,44 @@ +/* tsi_sub.c -- Test mpfi_si_sub. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_si_sub; + + mpfi_fun_init_ISI (&i_si_sub, mpfi_si_sub, mpfr_si_sub); + test_start (); + + check_data (&i_si_sub, "si_sub.dat"); + check_random (&i_si_sub, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_si_sub); + + return 0; +} diff --git a/tests/tsin.c b/tests/tsin.c new file mode 100644 index 0000000..dd15db8 --- /dev/null +++ b/tests/tsin.c @@ -0,0 +1,60 @@ +/* tsin.c -- Test mpfi_sin. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +restrict_domain (mpfi_ptr a) +{ + /* speedup some tests restricting the possible random values */ + if (mpfr_cmp_si (&(a->left), -7) < 0 || mpfr_cmp_si (&(a->left), +7) > 0) { + mpfr_set_si (&(a->left), -7, MPFI_RNDD); + } + if (mpfr_cmp_si (&(a->right), -7) < 0 + || mpfr_cmp_si (&(a->right), +7) > 0) { + mpfr_set_si (&(a->right), 7, MPFI_RNDU); + } + return 0; +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sin; + + mpfi_fun_init_II (&i_sin, mpfi_sin, mpfr_sin); + mpfi_restrict_random (&i_sin, restrict_domain); + + test_start (); + + check_data (&i_sin, "sin.dat"); + check_random (&i_sin, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_sin); + + return 0; +} diff --git a/tests/tsinh.c b/tests/tsinh.c new file mode 100644 index 0000000..15729d3 --- /dev/null +++ b/tests/tsinh.c @@ -0,0 +1,45 @@ +/* tsinh.c -- Test mpfi_sinh. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sinh; + + mpfi_fun_init_II (&i_sinh, mpfi_sinh, mpfr_sinh); + + test_start (); + + check_data (&i_sinh, "sinh.dat"); + check_random (&i_sinh, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_sinh); + + return 0; +} diff --git a/tests/tsqr.c b/tests/tsqr.c new file mode 100644 index 0000000..ff2d32f --- /dev/null +++ b/tests/tsqr.c @@ -0,0 +1,44 @@ +/* tsqr.c -- Test mpfi_sqr. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sqr; + + mpfi_fun_init_II (&i_sqr, mpfi_sqr, mpfr_sqr); + test_start (); + + check_data (&i_sqr, "sqr.dat"); + check_random (&i_sqr, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_sqr); + + return 0; +} diff --git a/tests/tsqrt.c b/tests/tsqrt.c new file mode 100644 index 0000000..ffabaa5 --- /dev/null +++ b/tests/tsqrt.c @@ -0,0 +1,44 @@ +/* tsqrt.c -- Test mpfi_sqrt. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sqrt; + + mpfi_fun_init_II (&i_sqrt, mpfi_sqrt, mpfr_sqrt); + test_start (); + + check_data (&i_sqrt, "sqrt.dat"); + check_random (&i_sqrt, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_sqrt); + + return 0; +} diff --git a/tests/tsub.c b/tests/tsub.c new file mode 100644 index 0000000..d16a4eb --- /dev/null +++ b/tests/tsub.c @@ -0,0 +1,45 @@ +/* tsub.c -- Test mpfi_sub. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sub; + + mpfi_fun_init_III (&i_sub, mpfi_sub, mpfr_sub); + + test_start (); + + check_data (&i_sub, "sub.dat"); + check_random (&i_sub, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_sub); + + return 0; +} diff --git a/tests/tsub_d.c b/tests/tsub_d.c new file mode 100644 index 0000000..a0e60d5 --- /dev/null +++ b/tests/tsub_d.c @@ -0,0 +1,97 @@ +/* tsub_d.c -- Test mpfi_sub_d. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_sub_d (a, a, -1024.5); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_sub_d does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_sub_d does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_sub_d (a, a, 1024.5); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_sub_d does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_sub_d does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sub_d; + + mpfi_fun_init_IID (&i_sub_d, mpfi_sub_d, mpfr_sub_d); + + test_start (); + + check_data (&i_sub_d, "sub_d.dat"); + check_random (&i_sub_d, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_sub_d); + + return 0; +} diff --git a/tests/tsub_fr.c b/tests/tsub_fr.c new file mode 100644 index 0000000..65e0683 --- /dev/null +++ b/tests/tsub_fr.c @@ -0,0 +1,106 @@ +/* tsub_fr.c -- Test mpfi_sub_fr. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfr_t x; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_init2 (x, 53); + + /* right overflow: [1, max] - (-2^50) = [2^50 + 1, +oo] */ + mpfr_set_si_2exp (x, -1, 50, MPFI_RNDD); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_sub_fr (a, a, x); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_sub_fr does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact) || MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_sub_fr does not return correct value when positive " + "overflow.\n got = %d\nexpected = %d\n", inexact, + MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + exit (1); + } + + /* left overflow: [-max, 1] - (2^50) = [-oo, -2^50 + 1] */ + mpfr_neg (x, x, MPFI_RNDU); + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_sub_fr (a, a, x); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_sub_fr does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact) || MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_sub_fr does not return correct value when negative " + "overflow.\n got = %d\nexpected = %d\n", inexact, + MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); + mpfr_clear (x); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sub_fr; + + mpfi_fun_init_IIR (&i_sub_fr, mpfi_sub_fr, mpfr_sub); + test_start (); + + check_data (&i_sub_fr, "sub_fr.dat"); + check_random (&i_sub_fr, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_sub_fr); + + return 0; +} diff --git a/tests/tsub_q.c b/tests/tsub_q.c new file mode 100644 index 0000000..b409127 --- /dev/null +++ b/tests/tsub_q.c @@ -0,0 +1,100 @@ +/* tsub_q.c -- Test mpfi_sub_q. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + mpq_t q; + int inexact; + + mpq_init (q); + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpq_set_si (q, -1024, 1); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_sub_q (a, a, q); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_sub_q does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact) || MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_sub_q does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpq_set_si (q, 1024, 1); + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_sub_q (a, a, q); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_sub_q does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact) || MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_sub_q does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpq_clear (q); + mpfi_clear (a); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sub_q; + + mpfi_fun_init_IIQ (&i_sub_q, mpfi_sub_q, mpfr_sub_q); + test_start (); + + check_data (&i_sub_q, "sub_q.dat"); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_sub_q); + + return 0; +} diff --git a/tests/tsub_si.c b/tests/tsub_si.c new file mode 100644 index 0000000..9ee58c8 --- /dev/null +++ b/tests/tsub_si.c @@ -0,0 +1,97 @@ +/* tsub_si.c -- Test mpfi_sub_si. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_sub_si (a, a, -1024); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_sub_si does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact) || MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_sub_si does not return correct value when positive " + "overflow.\n"); + exit (1); + } + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_sub_si (a, a, 1024); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_sub_si does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact) || MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_sub_si does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sub_si; + + mpfi_fun_init_IIS (&i_sub_si, mpfi_sub_si, mpfr_sub_si); + + test_start (); + + check_data (&i_sub_si, "sub_si.dat"); + check_random (&i_sub_si, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_sub_si); + + return 0; +} diff --git a/tests/tsub_ui.c b/tests/tsub_ui.c new file mode 100644 index 0000000..a1cb48f --- /dev/null +++ b/tests/tsub_ui.c @@ -0,0 +1,79 @@ +/* tsub_ui.c -- Test mpfi_sub_ui. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + int inexact; + + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_sub_si (a, a, 1024); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_sub_si does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact) || MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_sub_si does not return correct value when negative " + "overflow.\n"); + exit (1); + } + + mpfi_clear (a); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sub_ui; + + mpfi_fun_init_IIU (&i_sub_ui, mpfi_sub_ui, mpfr_sub_ui); + + test_start (); + + check_data (&i_sub_ui, "sub_ui.dat"); + check_random (&i_sub_ui, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_sub_ui); + + return 0; +} diff --git a/tests/tsub_z.c b/tests/tsub_z.c new file mode 100644 index 0000000..12eea1f --- /dev/null +++ b/tests/tsub_z.c @@ -0,0 +1,103 @@ +/* tsub_z.c -- Test mpfi_sub_z. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfr_t max; + mpfi_t a; + mpz_t z; + int inexact; + + mpz_init (z); + mpfi_init2 (a, 53); + mpfr_init2 (max, 53); + mpz_set_si (z, -4096); + mpfr_set_ui (&(a->left), 1, MPFI_RNDD); + mpfr_set_inf (max, +1); + mpfr_nextbelow (max); + mpfr_set (&(a->right), max, MPFI_RNDU); + + inexact = mpfi_sub_z (a, a, z); + + if (!mpfr_inf_p (&(a->right))) { + printf ("Error: mpfi_sub_z does not correctly handle positive " + "overflow.\n"); + exit (1); + } + + if (!MPFI_RIGHT_IS_INEXACT (inexact) || MPFI_LEFT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_sub_z does not return correct value when positive " + "overflow.\n got = %d\nexpected = %d\n", inexact, + MPFI_FLAGS_RIGHT_ENDPOINT_INEXACT); + exit (1); + } + + mpz_neg (z, z); + mpfr_set_inf (max, -1); + mpfr_nextabove (max); + mpfr_set (&(a->left), max, MPFI_RNDD); + mpfr_set_ui (&(a->right), 1, MPFI_RNDU); + + inexact = mpfi_sub_z (a, a, z); + + if (!mpfr_inf_p (&(a->left))) { + printf ("Error: mpfi_sub_z does not correctly handle negative " + "overflow.\n"); + exit (1); + } + + if (!MPFI_LEFT_IS_INEXACT (inexact) || MPFI_RIGHT_IS_INEXACT (inexact)) { + printf ("Error: mpfi_sub_z does not return correct value when negative " + "overflow.\n got = %d\nexpected = %d\n", inexact, + MPFI_FLAGS_LEFT_ENDPOINT_INEXACT); + exit (1); + } + + mpz_clear (z); + mpfi_clear (a); + mpfr_clear (max); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_sub_z; + + mpfi_fun_init_IIZ (&i_sub_z, mpfi_sub_z, mpfr_sub_z); + test_start (); + + check_data (&i_sub_z, "sub_z.dat"); + check_random (&i_sub_z, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_sub_z); + + return 0; +} diff --git a/tests/tswap.c b/tests/tswap.c new file mode 100644 index 0000000..2f99a4c --- /dev/null +++ b/tests/tswap.c @@ -0,0 +1,65 @@ +/* tget_swap.c -- Test mpfi_swap. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + mpfi_t a, b; + unsigned long pa, pb; + + mpfi_init2 (a, 53); + mpfi_init2 (b, 2); + + mpfr_set_ui (&(a->left), 4, MPFI_RNDD); + mpfr_set_ui (&(a->right), 7, MPFI_RNDU); + mpfr_set_ui (&(b->left), 0, MPFI_RNDD); + mpfr_set_ui (&(b->right), 2, MPFI_RNDU); + mpfi_swap (a, b); + if (mpfr_cmp_ui (&(b->left), 4) != 0 + || mpfr_cmp_ui (&(b->right), 7) != 0 + || mpfr_cmp_ui (&(a->left), 0) != 0 + || mpfr_cmp_ui (&(a->right), 2) != 0) { + printf ("Error: mpfi_swap (a, b) does not swap values.\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\n"); + exit (1); + } + if (mpfi_get_prec (a) != 2 || mpfi_get_prec (b) != 53) { + pa = mpfi_get_prec (a); + pb = mpfi_get_prec (b); + printf ("Error: mpfi_swap(a, b) does not swap precisions.\n" + "precision of a = %lu\nprecision of b = %lu", pa, pb); + exit (1); + } + + mpfi_clear (a); + mpfi_clear (b); + return 0; +} diff --git a/tests/ttan.c b/tests/ttan.c new file mode 100644 index 0000000..eec764a --- /dev/null +++ b/tests/ttan.c @@ -0,0 +1,60 @@ +/* ttan.c -- Test mpfi_tan. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +restrict_domain (mpfi_ptr a) +{ + /* speedup some tests restricting the possible random values */ + if (mpfr_cmp_si (&(a->left), -7) < 0 || mpfr_cmp_si (&(a->left), +7) > 0) { + mpfr_set_si (&(a->left), -7, MPFI_RNDD); + } + if (mpfr_cmp_si (&(a->right), -7) < 0 + || mpfr_cmp_si (&(a->right), +7) > 0) { + mpfr_set_si (&(a->right), 7, MPFI_RNDU); + } + return 0; +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_tan; + + mpfi_fun_init_II (&i_tan, mpfi_tan, mpfr_tan); + mpfi_restrict_random (&i_tan, restrict_domain); + + test_start (); + + check_data (&i_tan, "tan.dat"); + check_random (&i_tan, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_tan); + + return 0; +} diff --git a/tests/ttanh.c b/tests/ttanh.c new file mode 100644 index 0000000..7c798e1 --- /dev/null +++ b/tests/ttanh.c @@ -0,0 +1,45 @@ +/* ttanh.c -- Test mpfi_tanh. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_tanh; + + mpfi_fun_init_II (&i_tanh, mpfi_tanh, mpfr_tanh); + + test_start (); + + check_data (&i_tanh, "tanh.dat"); + check_random (&i_tanh, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_tanh); + + return 0; +} diff --git a/tests/tui_div.c b/tests/tui_div.c new file mode 100644 index 0000000..6da0dc9 --- /dev/null +++ b/tests/tui_div.c @@ -0,0 +1,95 @@ +/* tui_div.c -- Test mpfi_ui_div. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow (void) +{ + mpfi_t interval; + mpfi_t got; + unsigned long ui = 1024.0; + int inex; + + mpfi_init2 (interval, 53); + mpfi_init2 (got, 53); + + /* right overflow: 1024 / [epsilon, 1] = [1024, +oo] */ + mpfr_set_ui (&(interval->left), 0, MPFI_RNDD); + mpfr_nextabove (&(interval->left)); /* tiny left endpoint x0 */ + mpfr_set_ui (&(interval->right), 1, MPFI_RNDU); + + inex = mpfi_ui_div (got, ui, interval); + if (MPFI_LEFT_IS_INEXACT (inex) || mpfr_cmp_ui (&(got->left), ui) != 0 + || !MPFI_RIGHT_IS_INEXACT (inex) || !mpfr_inf_p (&(got->right))) { + printf ("Error: mpfi_ui_div (rop, %lu, op) does not correctly handle " + "overflow.\nop = ", ui); + mpfi_out_str (stdout, 10, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + /* left overflow: 1024.0 / [-1, -epsilon] = [-oo, -1024] */ + mpfi_neg (interval, interval); + + inex = mpfi_ui_div (got, ui, interval); + if (!MPFI_LEFT_IS_INEXACT (inex) + || !mpfr_inf_p (&(got->left)) + || MPFI_RIGHT_IS_INEXACT (inex) + || mpfr_cmp_si (&(got->right), -(long)ui) != 0) { + printf ("Error: mpfi_ui_div (rop, %lu, op) does not correctly handle " + "overflow.\nop = ", ui); + mpfi_out_str (stdout, 10, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + mpfi_clear (interval); + mpfi_clear (got); +} + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_ui_div; + + mpfi_fun_init_IUI (&i_ui_div, mpfi_ui_div, mpfr_ui_div); + + test_start (); + + check_data (&i_ui_div, "ui_div.dat"); + check_random (&i_ui_div, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_ui_div); + + return 0; +} diff --git a/tests/tui_sub.c b/tests/tui_sub.c new file mode 100644 index 0000000..81fa0e3 --- /dev/null +++ b/tests/tui_sub.c @@ -0,0 +1,44 @@ +/* tui_sub.c -- Test mpfi_ui_sub. + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_ui_sub; + + mpfi_fun_init_IUI (&i_ui_sub, mpfi_ui_sub, mpfr_ui_sub); + test_start (); + + check_data (&i_ui_sub, "ui_sub.dat"); + check_random (&i_ui_sub, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_ui_sub); + + return 0; +} diff --git a/tests/tunion.c b/tests/tunion.c new file mode 100644 index 0000000..e2e8bd5 --- /dev/null +++ b/tests/tunion.c @@ -0,0 +1,68 @@ +/* tunion.c -- Test mpfi_union. + +Copyright 2009, 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +/* the middle of two points is in their convex hull */ +int +middle (mpfr_ptr m, mpfr_srcptr a, mpfr_srcptr b, mpfr_rnd_t rnd) +{ + mpfr_t min, max; + + if (mpfr_cmp (a, b) < 0) { + min[0] = a[0]; + max[0] = b[0]; + } + else { + min[0] = b[0]; + max[0] = a[0]; + } + mpfr_sub (m, max, min, rnd); + mpfr_div_2exp (m, m, 1, rnd); + mpfr_add (m, min, m, rnd); + + return 0; +} + + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_union; + + mpfi_fun_init_III (&i_union, mpfi_union, middle); + + test_start (); + + + check_data (&i_union, "union.dat"); + check_random (&i_union, 2, 1000, 10); + + test_end (); + mpfi_fun_clear (&i_union); + + return 0; +} diff --git a/tests/type_i.c b/tests/type_i.c new file mode 100644 index 0000000..f41f147 --- /dev/null +++ b/tests/type_i.c @@ -0,0 +1,152 @@ +/* type_i.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_i (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); +} + +void +check_monotonicity (mpfi_function_ptr this) +{ + mpfr_prec_t precision; + mpfr_prec_t initial_precision; + + /* rename operands for better readability */ + I_fun f_I = MPFI_FUN_GET (*this, I); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + initial_precision = mpfi_get_prec (expected); + + for (precision = initial_precision; precision > 1; precision >>= 2) { + mpfi_set_prec (got, precision); + + f_I (got); + + if (!mpfi_is_inside (expected, got)) { + printf ("Failed at precision %lu.\n", precision); + mpfi_out_str (stdout, 2, 0, got); + printf ("\ndoes not include "); + mpfi_out_str (stdout, 2, 0, expected); + putchar ('\n'); + + exit (1); + } + } +} + +void +check_line_i (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + I_fun f_I = MPFI_FUN_GET (*this, I); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_I (got); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.", test_line_number); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + + /* monotonic? */ + if (!MPFI_NAN_P (expected)) { + check_monotonicity (this); + } +} + +void +set_prec_i (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); +} + +void +clear_i (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +void +mpfi_fun_init_I (mpfi_function_ptr this, I_fun mpfi_function, + R_fun mpfr_function) +{ + this->type = I; + this->func.I = mpfi_function; + this->mpfr_func.I = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (3 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + + /* init methods */ + this->set_prec = set_prec_i; + this->read_line = read_line_i; + this->check_line = check_line_i; + this->random = NULL; + this->clear = clear_i; +} diff --git a/tests/type_id.c b/tests/type_id.c new file mode 100644 index 0000000..94838ef --- /dev/null +++ b/tests/type_id.c @@ -0,0 +1,134 @@ +/* type_id.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, double). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern char * pathname; +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_id (mpfi_function_ptr this, FILE* fp) +{ + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + test_line_number = line_number; + /* [0] initial value */ + read_mpfi (fp, got); + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, expected); + /* [3] integral operand */ + read_double (fp, &(MPFI_FUN_ARG (*this, 3, d))); + + /* data validation */ + if (mpfi_get_prec (got) != mpfi_get_prec (expected)) { + printf ("Error in data file %s line %lu\nThe precisions of intervals " + "are different.\n", pathname, test_line_number); + exit (1); + } +} + +void +check_line_id (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + ID_fun f_ID = MPFI_FUN_GET (*this, ID); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + double op = MPFI_FUN_ARG (*this, 3, d); + + inex = f_ID (got, op); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop = %a", test_line_number, op); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } +} + +void +set_prec_id (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); +} + +void +clear_id (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (double), needs no deallocation */ + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_ID (mpfi_function_ptr this, ID_fun mpfi_function, + NULL_fun mpfr_function) +{ + this->type = ID; + this->func.ID = mpfi_function; + this->mpfr_func.ID = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] operand (double), needs no initialization */ + + /* init methods */ + this->set_prec = set_prec_id; + this->read_line = read_line_id; + this->check_line = check_line_id; + this->random = NULL; + this->clear = clear_id; +} diff --git a/tests/type_idi.c b/tests/type_idi.c new file mode 100644 index 0000000..d149260 --- /dev/null +++ b/tests/type_idi.c @@ -0,0 +1,201 @@ +/* type_idi.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, double, mpfi_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_idi (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] double operand */ + read_double (fp, &(MPFI_FUN_ARG (*this, 3, d))); + /* [4] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 4, mpfi)); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ + +void +check_line_idi (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IDI_fun f_IDI = MPFI_FUN_GET (*this, IDI); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + double op1 = MPFI_FUN_ARG (*this, 3, d); + mpfi_ptr op2 = MPFI_FUN_ARG (*this, 4, mpfi); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_IDI (got, op1, op2); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = %g\nop2 = ", test_line_number, op1); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op2)) { + mpfi_set (got, op2); + + inex = f_IDI (got, op1, got); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = %g\nop2 = ", test_line_number, op1); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of a random point chosen in the given interval is in the + image of this interval. */ +void +random_idi (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + IDI_fun f_IDI = MPFI_FUN_GET (*this, IDI); + RDR_fun f_RDR = MPFI_FUN_MPFR_FUNCTION (*this, IDI); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr a = MPFI_FUN_ARG (*this, 4, mpfi); + double d; + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + + d = random_double (); + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + mpfi_alea (x, a); + f_IDI (b, d, a); + f_RDR (y, d, x, MPFI_RNDD); + + if (!mpfr_nan_p (y) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (y, b)) { + printf ("Error: the interval b, image of (d, a), does not contain the " + "point y, image of (d, x) where x is in a.\nd = %g\na = ", d); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_idi (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 4, mpfi), prec); +} + +void +clear_idi (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (double), needs no deallocation */ + /* [4] operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 4, mpfi)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IDI (mpfi_function_ptr this, IDI_fun mpfi_function, + RDR_fun mpfr_function) +{ + this->type = IDI; + this->func.IDI = mpfi_function; + this->mpfr_func.IDI = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] first operand (double), needs no initialization */ + /* [4] second operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 4, mpfi), 1024); + + /* init methods */ + this->set_prec = set_prec_idi; + this->read_line = read_line_idi; + this->check_line = check_line_idi; + this->random = random_idi; + this->clear = clear_idi; +} diff --git a/tests/type_if.c b/tests/type_if.c new file mode 100644 index 0000000..d3b85dc --- /dev/null +++ b/tests/type_if.c @@ -0,0 +1,131 @@ +/* type_if.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, float). + +Copyright 2018, + AriC project, Inria Grenoble - Rhone-Alpes, France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern char * pathname; +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_if (mpfi_function_ptr this, FILE* fp) +{ + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + test_line_number = line_number; + /* [0] initial value */ + read_mpfi (fp, got); + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, expected); + /* [3] integral operand */ + read_float (fp, &(MPFI_FUN_ARG (*this, 3, f))); + + /* data validation */ + if (mpfi_get_prec (got) != mpfi_get_prec (expected)) { + printf ("Error in data file %s line %lu\nThe precisions of intervals " + "are different.\n", pathname, test_line_number); + exit (1); + } +} + +void +check_line_if (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IF_fun f_IF = MPFI_FUN_GET (*this, IF); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + float op = MPFI_FUN_ARG (*this, 3, f); + + inex = f_IF (got, op); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop = %a", test_line_number, op); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } +} + +void +set_prec_if (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); +} + +void +clear_if (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (float), needs no deallocation */ + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IF (mpfi_function_ptr this, IF_fun mpfi_function, + NULL_fun mpfr_function) +{ + this->type = IF; + this->func.IF = mpfi_function; + this->mpfr_func.IF = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] operand (float), needs no initialization */ + + /* init methods */ + this->set_prec = set_prec_if; + this->read_line = read_line_if; + this->check_line = check_line_if; + this->random = NULL; + this->clear = clear_if; +} diff --git a/tests/type_ii.c b/tests/type_ii.c new file mode 100644 index 0000000..6f7bb17 --- /dev/null +++ b/tests/type_ii.c @@ -0,0 +1,283 @@ +/* type_ii.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpfi_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_ii (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 3, mpfi)); +} + +/* check_with_different_prec used by both check_line_ii and check_line_iii */ +/* when one (at least) endpoint of the result is exact, it can be + used to check the function at a different precision. */ +void +check_with_different_prec (mpfi_function_ptr function, mpfr_prec_t prec) +{ + mpfr_t x; + + /* rename operands for better readability */ + int type_II = MPFI_FUN_TYPE (*function) == II; + II_fun f_II = MPFI_FUN_GET (*function, II); + III_fun f_III = MPFI_FUN_GET (*function, III); + mpfi_ptr got = MPFI_FUN_ARG (*function, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*function, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*function, 2, mpfi); + mpfi_ptr op1 = MPFI_FUN_ARG (*function, 3, mpfi); + mpfi_ptr op2 = type_II ? NULL : MPFI_FUN_ARG (*function, 4, mpfi); + + + mpfr_init2 (x, prec); + mpfi_set_prec (got, prec); + + if (type_II) + f_II (got, op1); + else + f_III (got, op1, op2); + + if (!MPFI_LEFT_IS_INEXACT (expected_inex)) { + mpfr_set (x, &(expected->left), MPFI_RNDD); + if (!same_mpfr_value (x, &(got->left))) { + printf ("Error at precision = %lu (line %lu).\n", + (unsigned long)prec, test_line_number); + if (type_II) { + printf ("op = "); + mpfi_out_str (stdout, 16, 0, op1); + } + else { + printf ("op1 = "); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = "); + mpfi_out_str (stdout, 16, 0, op2); + } + printf ("\nleft endpoint: got = "); + mpfr_out_str (stdout, 2, 0, &(got->left), MPFI_RNDD); + printf ("\n expected = "); + mpfr_out_str (stdout, 2, 0, x, MPFI_RNDD); + putchar ('\n'); + + exit (1); + } + } + + if (!MPFI_RIGHT_IS_INEXACT (expected_inex)) { + mpfr_set (x, &(expected->right), MPFI_RNDU); + if (!same_mpfr_value (x, &(got->right))) { + printf ("Error at precision = %lu (line %lu).\n", + (unsigned long)prec, test_line_number); + if (type_II) { + printf ("op = "); + mpfi_out_str (stdout, 16, 0, op1); + } + else { + printf ("op1 = "); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = "); + mpfi_out_str (stdout, 16, 0, op2); + } + printf ("\nright endpoint: got = "); + mpfr_out_str (stdout, 2, 0, &(got->right), MPFI_RNDU); + printf ("\n expected = "); + mpfr_out_str (stdout, 2, 0, x, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } + } + + mpfr_clear (x); +} + + +/* check function against data at different precisions and test if an + input variable can be reused as output */ + +void +check_line_ii (mpfi_function_ptr function) +{ + int inex; + + /* rename operands for better readability + [0]: value set by function + [1]: return value (inexact flag) + [2]: expected value + [3]: first operand */ + II_fun f_II = MPFI_FUN_GET (*function, II); + mpfi_ptr got = MPFI_FUN_ARG (*function, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*function, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*function, 2, mpfi); + mpfi_ptr op1 = MPFI_FUN_ARG (*function, 3, mpfi); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + inex = f_II (got, op1); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\n", test_line_number); + printf ("op = "); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + exit (1); + } + + /* when one endpoint is exact, compute function at lower and higher + precision */ + if (!MPFI_NAN_P (expected) && !MPFI_BOTH_ARE_INEXACT (inex)) { + check_with_different_prec (function, 2); + check_with_different_prec (function, 2 * mpfi_get_prec (expected)); + mpfi_set_prec (got, mpfi_get_prec (expected)); + } + + /* reuse input variable as output (when they have the same precision) */ + if (mpfi_get_prec (got) == mpfi_get_prec (op1)) { + mpfi_set (got, op1); + inex = f_II (got, got); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing input argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of a random point chosen in the given interval is in the + image of this interval. */ +void +random_ii (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + II_fun f_II = MPFI_FUN_GET (*this, II); + RR_fun f_RR = MPFI_FUN_MPFR_FUNCTION (*this, II); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr a = MPFI_FUN_ARG (*this, 3, mpfi); + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + mpfi_alea (x, a); + f_II (b, a); + f_RR (y, x, MPFI_RNDD); + if (!mpfr_nan_p (y) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (y, b)) { + printf ("Error: the image b of a does not contain the image y " + "of the point x of a.\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_ii (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 3, mpfi), prec); +} + +void +clear_ii (mpfi_function_ptr this) +{ + /* [0] auxiliary variable (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 3, mpfi)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_II (mpfi_function_ptr this, II_fun mpfi_function, + RR_fun mpfr_function) +{ + this->type = II; + this->func.II = mpfi_function; + this->mpfr_func.II = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] auxiliary variable (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 3, mpfi), 1024); + + /* init methods */ + this->set_prec = set_prec_ii; + this->read_line = read_line_ii; + this->check_line = check_line_ii; + this->random = random_ii; + this->clear = clear_ii; +} diff --git a/tests/type_iid.c b/tests/type_iid.c new file mode 100644 index 0000000..643427a --- /dev/null +++ b/tests/type_iid.c @@ -0,0 +1,202 @@ +/* type_iid.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpfi_t, double). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iid (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] double operand */ + read_double (fp, &(MPFI_FUN_ARG (*this, 4, d))); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ + +void +check_line_iid (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IID_fun f_IID = MPFI_FUN_GET (*this, IID); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr op1 = MPFI_FUN_ARG (*this, 3, mpfi); + double op2 = MPFI_FUN_ARG (*this, 4, d); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_IID (got, op1, op2); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = %g", op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op1)) { + mpfi_set (got, op1); + + inex = f_IID (got, got, op2); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = %g", op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of a random point chosen in the given interval is in the + image of this interval. */ +void +random_iid (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + IID_fun f_IID = MPFI_FUN_GET (*this, IID); + RRD_fun f_RRD = MPFI_FUN_MPFR_FUNCTION (*this, IID); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr a = MPFI_FUN_ARG (*this, 3, mpfi); + double d; + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + + d = random_double (); + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + mpfi_alea (x, a); + f_IID (b, a, d); + f_RRD (y, x, d, MPFI_RNDD); + if (!mpfr_nan_p (y) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (y, b)) { + printf ("Error: the interval b, image of (a, d), does not contain " + "the point y, image of (x, d) where x is in a.\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nd = %g\nb = ", d); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_iid (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 3, mpfi), prec); +} + +void +clear_iid (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] operand (double), needs no deallocation */ + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IID (mpfi_function_ptr this, IID_fun mpfi_function, + RRD_fun mpfr_function) +{ + this->type = IID; + this->func.IID = mpfi_function; + this->mpfr_func.IID = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] first operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 3, mpfi), 1024); + /* [4] second operand (double), needs no initialization */ + + /* init methods */ + this->set_prec = set_prec_iid; + this->read_line = read_line_iid; + this->check_line = check_line_iid; + this->random = random_iid; + this->clear = clear_iid; +} diff --git a/tests/type_iii.c b/tests/type_iii.c new file mode 100644 index 0000000..5a51f90 --- /dev/null +++ b/tests/type_iii.c @@ -0,0 +1,256 @@ +/* type_iii.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpfi_t, mpfi_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iii (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] first operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] second operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 4, mpfi)); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ + +void +check_line_iii (mpfi_function_ptr function) +{ + int inex; + + /* rename operands for better readability + [0]: value set by function + [1]: return value (inexact flag) + [2]: expected value + [3]: first operand + [4]: second operand */ + III_fun f_III = MPFI_FUN_GET (*function, III); + mpfi_ptr got = MPFI_FUN_ARG (*function, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*function, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*function, 2, mpfi); + mpfi_ptr op1 = MPFI_FUN_ARG (*function, 3, mpfi); + mpfi_ptr op2 = MPFI_FUN_ARG (*function, 4, mpfi); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_III (got, op1, op2); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\n", test_line_number); + printf ("op1 = "); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = "); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + exit (1); + } + + /* when one endpoint is exact, compute function at lower and higher + precision */ + if (!MPFI_NAN_P (expected) && !MPFI_BOTH_ARE_INEXACT (inex)) { + check_with_different_prec (function, 2); + check_with_different_prec (function, 2 * mpfi_get_prec (expected)); + mpfi_set_prec (got, mpfi_get_prec (expected)); + } + + /* reuse input variable as output (when they have the same precision) */ + if (mpfi_get_prec (got) == mpfi_get_prec (op1)) { + mpfi_set (got, op1); + + inex = f_III (got, got, op2); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = "); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } + + if (mpfi_get_prec (got) == mpfi_get_prec (op2)) { + mpfi_set (got, op2); + inex = f_III (got, op1, got); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing second argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = "); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of random points chosen in the given intervals is in the + image of these intervals. */ +void +random_iii (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + III_fun f_III = MPFI_FUN_GET (*this, III); + RRR_fun f_RRR = MPFI_FUN_MPFR_FUNCTION (*this, III); + mpfi_ptr c = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr b = MPFI_FUN_ARG (*this, 3, mpfi); + mpfi_ptr a = MPFI_FUN_ARG (*this, 4, mpfi); + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + mpfr_t z; + + mpfr_init2 (z, mpfi_get_prec (c)); + + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + mpfi_alea (x, a); + random_interval (b); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (b); + } + mpfi_alea (y, b); + f_III (c, a, b); + f_RRR (z, x, y, MPFI_RNDD); + if (!mpfr_nan_p (z) && !MPFI_NAN_P (c) && !mpfi_is_inside_fr (z, c)) { + printf ("Error: the image c of (a, b) does not contain the image z " + "of (x, y) where x (resp. y) is in a (resp. b).\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nc = "); + mpfi_out_str (stdout, 10, 0, c); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + printf ("\nz = "); + mpfr_out_str (stdout, 10, 0, z, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } + + mpfr_clear (z); +} + +void +set_prec_iii (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 3, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 4, mpfi), prec); +} + +void +clear_iii (mpfi_function_ptr this) +{ + /* [0] auxiliary variable (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] first operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] second operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 4, mpfi)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_III (mpfi_function_ptr this, III_fun mpfi_function, + RRR_fun mpfr_function) +{ + this->type = III; + this->func.III = mpfi_function; + this->mpfr_func.III = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] auxiliary variable (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] first operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 3, mpfi), 1024); + /* [4] second operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 4, mpfi), 1024); + + /* init methods */ + this->set_prec = set_prec_iii; + this->read_line = read_line_iii; + this->check_line = check_line_iii; + this->random = random_iii; + this->clear = clear_iii; +} diff --git a/tests/type_iiq.c b/tests/type_iiq.c new file mode 100644 index 0000000..e16d941 --- /dev/null +++ b/tests/type_iiq.c @@ -0,0 +1,207 @@ +/* type_iiq.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpfi_t, mpq_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iiq (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] mpq_t operand */ + read_mpq (fp, MPFI_FUN_ARG (*this, 4, mpq)); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ +void +check_line_iiq (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IIQ_fun f_IIQ = MPFI_FUN_GET (*this, IIQ); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr op1 = MPFI_FUN_ARG (*this, 3, mpfi); + mpq_ptr op2 = MPFI_FUN_ARG (*this, 4, mpq); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_IIQ (got, op1, op2); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = ", test_line_number); + mpfi_out_str (stdout, 10, 0, op1); + printf ("\nop2 = "); + mpq_out_str (stdout, 10, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 10, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op1)) { + mpfi_set (got, op1); + + inex = f_IIQ (got, got, op2); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpfi_out_str (stdout, 10, 0, op1); + printf ("\nop2 = "); + mpq_out_str (stdout, 10, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 10, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of a random point chosen in the given interval is in the + image of this interval. */ +void +random_iiq (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + IIQ_fun f_IIQ = MPFI_FUN_GET (*this, IIQ); + RRQ_fun f_RRQ = MPFI_FUN_MPFR_FUNCTION (*this, IIQ); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr a = MPFI_FUN_ARG (*this, 3, mpfi); + mpq_ptr q = MPFI_FUN_ARG (*this, 4, mpq); + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + + random_mpq (q); + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + mpfi_alea (x, a); + f_IIQ (b, a, q); + f_RRQ (y, x, q, MPFI_RNDD); + + if (!mpfr_nan_p (y) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (y, b)) { + printf ("Error: the interval b, image of (a, q), does not contain " + "the point y, image of (x, q) where x is in a.\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nq = "); + mpq_out_str (stdout, 10, q); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_iiq (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 3, mpfi), prec); +} + +void +clear_iiq (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] operand (mpz_t) */ + mpq_clear (MPFI_FUN_ARG (*this, 4, mpq)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IIQ (mpfi_function_ptr this, IIQ_fun mpfi_function, + RRQ_fun mpfr_function) +{ + this->type = IIQ; + this->func.IIQ = mpfi_function; + this->mpfr_func.IIQ = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] first operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 3, mpfi), 1024); + /* [4] second operand (mpq_t) */ + mpq_init (MPFI_FUN_ARG (*this, 4, mpq)); + + /* init methods */ + this->set_prec = set_prec_iiq; + this->read_line = read_line_iiq; + this->check_line = check_line_iiq; + this->random = random_iiq; + this->clear = clear_iiq; +} diff --git a/tests/type_iir.c b/tests/type_iir.c new file mode 100644 index 0000000..c525fdc --- /dev/null +++ b/tests/type_iir.c @@ -0,0 +1,208 @@ +/* type_iir.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpfi_t, mpfr_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iir (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] mpfr_t operand */ + read_mpfr (fp, MPFI_FUN_ARG (*this, 4, mpfr)); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ +void +check_line_iir (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IIR_fun f_IIR = MPFI_FUN_GET (*this, IIR); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr op1 = MPFI_FUN_ARG (*this, 3, mpfi); + mpfr_ptr op2 = MPFI_FUN_ARG (*this, 4, mpfr); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_IIR (got, op1, op2); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = "); + mpfr_out_str (stdout, 16, 0, op2, MPFI_RNDD); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op1)) { + mpfi_set (got, op1); + + inex = f_IIR (got, got, op2); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = "); + mpfr_out_str (stdout, 16, 0, op2, MPFI_RNDD); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of random points chosen in the given intervals is in the + image of these intervals. */ +void +random_iir (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + IIR_fun f_IIR = MPFI_FUN_GET (*this, IIR); + RRR_fun f_RRR = MPFI_FUN_MPFR_FUNCTION (*this, IIR); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr a = MPFI_FUN_ARG (*this, 3, mpfi); + mpfr_ptr x = MPFI_FUN_ARG (*this, 4, mpfr); + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr y = &(i->left); + mpfr_ptr z = &(i->right); + + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + random_mpfr (x); + mpfi_alea (y, a); + f_IIR (b, a, x); + f_RRR (z, y, x, MPFI_RNDD); + if (!mpfr_nan_p (z) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (z, b)) { + printf ("Error: the image b of (a, x) does not contain the image z " + "of (y, x) where y is in a.\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + printf ("\nz = "); + mpfr_out_str (stdout, 10, 0, z, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_iir (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 3, mpfi), prec); + mpfr_set_prec (MPFI_FUN_ARG (*this, 4, mpfr), prec); +} + +void +clear_iir (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] first operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] second operand (mpfr_t) */ + mpfr_clear (MPFI_FUN_ARG (*this, 4, mpfr)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IIR (mpfi_function_ptr this, IIR_fun mpfi_function, + RRR_fun mpfr_function) +{ + this->type = IIR; + this->func.IIR = mpfi_function; + this->mpfr_func.IIR = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] first operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 3, mpfi), 1024); + /* [4] second operand (mpfr_t) */ + mpfr_init2 (MPFI_FUN_ARG (*this, 4, mpfr), 1024); + + /* init methods */ + this->set_prec = set_prec_iir; + this->read_line = read_line_iir; + this->check_line = check_line_iir; + this->random = random_iir; + this->clear = clear_iir; +} diff --git a/tests/type_iis.c b/tests/type_iis.c new file mode 100644 index 0000000..4a02043 --- /dev/null +++ b/tests/type_iis.c @@ -0,0 +1,202 @@ +/* type_iis.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpfi_t, long). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iis (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] signed integral operand */ + read_si (fp, &(MPFI_FUN_ARG (*this, 4, si))); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ + +void +check_line_iis (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IIS_fun f_IIS = MPFI_FUN_GET (*this, IIS); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr op1 = MPFI_FUN_ARG (*this, 3, mpfi); + long op2 = MPFI_FUN_ARG (*this, 4, si); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_IIS (got, op1, op2); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = %ld", op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op1)) { + mpfi_set (got, op1); + + inex = f_IIS (got, got, op2); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = %ld", op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of a random point chosen in the given interval is in the + image of this interval. */ +void +random_iis (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + IIS_fun f_IIS = MPFI_FUN_GET (*this, IIS); + RRS_fun f_RRS = MPFI_FUN_MPFR_FUNCTION (*this, IIS); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr a = MPFI_FUN_ARG (*this, 3, mpfi); + long si; + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + + si = random_si (); + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + mpfi_alea (x, a); + f_IIS (b, a, si); + f_RRS (y, x, si, MPFI_RNDD); + if (!mpfr_nan_p (y) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (y, b)) { + printf ("Error: the interval b, image of (a, n), does not contain " + "the point y, image of (x, n) where x is in a.\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nn = %ld\nb = ", si); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_iis (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 3, mpfi), prec); +} + +void +clear_iis (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] operand (signed long), needs no deallocation */ + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IIS (mpfi_function_ptr this, IIS_fun mpfi_function, + RRS_fun mpfr_function) +{ + this->type = IIS; + this->func.IIS = mpfi_function; + this->mpfr_func.IIS = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] first operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 3, mpfi), 1024); + /* [4] second operand (signed long), needs no initialization */ + + /* init methods */ + this->set_prec = set_prec_iis; + this->read_line = read_line_iis; + this->check_line = check_line_iis; + this->random = random_iis; + this->clear = clear_iis; +} diff --git a/tests/type_iiu.c b/tests/type_iiu.c new file mode 100644 index 0000000..4068c7e --- /dev/null +++ b/tests/type_iiu.c @@ -0,0 +1,202 @@ +/* type_iiu.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpfi_t, unsigned long). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iiu (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] unsigned integral operand */ + read_ui (fp, &(MPFI_FUN_ARG (*this, 4, ui))); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ + +void +check_line_iiu (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IIU_fun f_IIU = MPFI_FUN_GET (*this, IIU); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr op1 = MPFI_FUN_ARG (*this, 3, mpfi); + unsigned long op2 = MPFI_FUN_ARG (*this, 4, ui); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_IIU (got, op1, op2); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = %lu", op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op1)) { + mpfi_set (got, op1); + + inex = f_IIU (got, got, op2); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = %lu", op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of a random point chosen in the given interval is in the + image of this interval. */ +void +random_iiu (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + IIU_fun f_IIU = MPFI_FUN_GET (*this, IIU); + RRU_fun f_RRU = MPFI_FUN_MPFR_FUNCTION (*this, IIU); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr a = MPFI_FUN_ARG (*this, 3, mpfi); + unsigned long ui; + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + + ui = random_ui (); + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + mpfi_alea (x, a); + f_IIU (b, a, ui); + f_RRU (y, x, ui, MPFI_RNDD); + if (!mpfr_nan_p (y) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (y, b)) { + printf ("Error: the interval b, image of (a, n), does not contain " + "the point y, image of (x, n) where x is in a.\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nn = %lu\nb = ", ui); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_iiu (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 3, mpfi), prec); +} + +void +clear_iiu (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] operand (unsigned long), needs no deallocation */ + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IIU (mpfi_function_ptr this, IIU_fun mpfi_function, + RRU_fun mpfr_function) +{ + this->type = IIU; + this->func.IIU = mpfi_function; + this->mpfr_func.IIU = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] first operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 3, mpfi), 1024); + /* [4] second operand (unsigned long), needs no initialization */ + + /* init methods */ + this->set_prec = set_prec_iiu; + this->read_line = read_line_iiu; + this->check_line = check_line_iiu; + this->random = random_iiu; + this->clear = clear_iiu; +} diff --git a/tests/type_iiz.c b/tests/type_iiz.c new file mode 100644 index 0000000..280e5b4 --- /dev/null +++ b/tests/type_iiz.c @@ -0,0 +1,209 @@ +/* type_iiz.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpfi_t, mpz_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; /* current line */ +static unsigned long test_line_number; /* start line of current test */ + +void +read_line_iiz (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] mpz_t operand */ + read_mpz (fp, MPFI_FUN_ARG (*this, 4, mpz)); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ + +void +check_line_iiz (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IIZ_fun f_IIZ = MPFI_FUN_GET (*this, IIZ); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr op1 = MPFI_FUN_ARG (*this, 3, mpfi); + mpz_ptr op2 = MPFI_FUN_ARG (*this, 4, mpz); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_IIZ (got, op1, op2); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = "); + mpz_out_str (stdout, 16, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op1)) { + mpfi_set (got, op1); + + inex = f_IIZ (got, got, op2); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op1); + printf ("\nop2 = "); + mpz_out_str (stdout, 16, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of a random point chosen in the given interval is in the + image of this interval. */ +void +random_iiz (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + IIZ_fun f_IIZ = MPFI_FUN_GET (*this, IIZ); + RRZ_fun f_RRZ = MPFI_FUN_MPFR_FUNCTION (*this, IIZ); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr a = MPFI_FUN_ARG (*this, 3, mpfi); + mpz_ptr z = MPFI_FUN_ARG (*this, 4, mpz); + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + unsigned long n = mpfi_get_prec (a) + 17; + + random_mpz (z, n); + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + mpfi_alea (x, a); + f_IIZ (b, a, z); + f_RRZ (y, x, z, MPFI_RNDD); + if (!mpfr_nan_p (y) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (y, b)) { + printf ("Error: the interval b, image of (a, n), does not contain " + "the point y, image of (x, n) where x is in a.\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nn = "); + mpz_out_str (stdout, 10, z); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_iiz (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 3, mpfi), prec); +} + +void +clear_iiz (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 3, mpfi)); + /* [4] operand (mpz_t) */ + mpz_clear (MPFI_FUN_ARG (*this, 4, mpz)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IIZ (mpfi_function_ptr this, IIZ_fun mpfi_function, + RRZ_fun mpfr_function) +{ + this->type = IIZ; + this->func.IIZ = mpfi_function; + this->mpfr_func.IIZ = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] first operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 3, mpfi), 1024); + /* [4] second operand (mpz_t) */ + mpz_init (MPFI_FUN_ARG (*this, 4, mpz)); + + /* init methods */ + this->set_prec = set_prec_iiz; + this->read_line = read_line_iiz; + this->check_line = check_line_iiz; + this->random = random_iiz; + this->clear = clear_iiz; +} diff --git a/tests/type_il.c b/tests/type_il.c new file mode 100644 index 0000000..e354abd --- /dev/null +++ b/tests/type_il.c @@ -0,0 +1,131 @@ +/* type_il.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, long double). + +Copyright 2018 + AriC project, Inria Grenoble - Rhone-Alpes, France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern char * pathname; +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_il (mpfi_function_ptr this, FILE* fp) +{ + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + test_line_number = line_number; + /* [0] initial value */ + read_mpfi (fp, got); + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, expected); + /* [3] integral operand */ + read_long_double (fp, &(MPFI_FUN_ARG (*this, 3, ld))); + + /* data validation */ + if (mpfi_get_prec (got) != mpfi_get_prec (expected)) { + printf ("Error in data file %s line %lu\nThe precisions of intervals " + "are different.\n", pathname, test_line_number); + exit (1); + } +} + +void +check_line_il (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IL_fun f_IL = MPFI_FUN_GET (*this, IL); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + long double op = MPFI_FUN_ARG (*this, 3, ld); + + inex = f_IL (got, op); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop = %La", test_line_number, op); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } +} + +void +set_prec_il (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); +} + +void +clear_il (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (long double), needs no deallocation */ + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IL (mpfi_function_ptr this, IL_fun mpfi_function, + NULL_fun mpfr_function) +{ + this->type = IL; + this->func.IL = mpfi_function; + this->mpfr_func.IL = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] operand (long double), needs no initialization */ + + /* init methods */ + this->set_prec = set_prec_il; + this->read_line = read_line_il; + this->check_line = check_line_il; + this->random = NULL; + this->clear = clear_il; +} diff --git a/tests/type_iq.c b/tests/type_iq.c new file mode 100644 index 0000000..7a2f4c7 --- /dev/null +++ b/tests/type_iq.c @@ -0,0 +1,137 @@ +/* type_iq.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpq_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern char * pathname; +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iq (mpfi_function_ptr this, FILE* fp) +{ + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + test_line_number = line_number; + /* [0] initial value */ + read_mpfi (fp, got); + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, expected); + /* [3] integral operand */ + read_mpq (fp, MPFI_FUN_ARG (*this, 3, mpq)); + + /* data validation */ + if (mpfi_get_prec (got) != mpfi_get_prec (expected)) { + printf ("Error in data file %s line %lu\nThe precisions of intervals " + "are different.\n", pathname, test_line_number); + exit (1); + } +} + +void +check_line_iq (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IQ_fun f_IQ = MPFI_FUN_GET (*this, IQ); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpq_ptr op = MPFI_FUN_ARG (*this, 3, mpq); + + inex = f_IQ (got, op); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop = ", test_line_number); + mpq_out_str (stdout, 10, op); + printf ("\ngot = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 10, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } +} + +void +set_prec_iq (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); +} + +void +clear_iq (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (mpq_t) */ + mpq_clear (MPFI_FUN_ARG (*this, 3, mpq)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IQ (mpfi_function_ptr this, IQ_fun mpfi_function, + NULL_fun mpfr_function) +{ + this->type = IQ; + this->func.IQ = mpfi_function; + this->mpfr_func.IQ = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] operand (mpq_t) */ + mpq_init (MPFI_FUN_ARG (*this, 3, mpq)); + + /* init methods */ + this->set_prec = set_prec_iq; + this->read_line = read_line_iq; + this->check_line = check_line_iq; + this->random = NULL; + this->clear = clear_iq; +} diff --git a/tests/type_iqi.c b/tests/type_iqi.c new file mode 100644 index 0000000..1bc49dd --- /dev/null +++ b/tests/type_iqi.c @@ -0,0 +1,211 @@ +/* type_iqi.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpq_t, mpfi_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iqi (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] mpq_t operand */ + read_mpq (fp, MPFI_FUN_ARG (*this, 3, mpq)); + /* [4] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 4, mpfi)); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ +void +check_line_iqi (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IQI_fun f_IQI = MPFI_FUN_GET (*this, IQI); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpq_ptr op1 = MPFI_FUN_ARG (*this, 3, mpq); + mpfi_ptr op2 = MPFI_FUN_ARG (*this, 4, mpfi); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_IQI (got, op1, op2); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = ", test_line_number); + mpq_out_str (stdout, 10, op1); + printf ("\nop2 = "); + mpfi_out_str (stdout, 10, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 10, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + + if (mpfi_get_prec (got) != mpfi_get_prec (op2)) { + return; + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op2)) { + mpfi_set (got, op2); + + inex = f_IQI (got, op1, got); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing second input argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpq_out_str (stdout, 10, op1); + printf ("\nop2 = "); + mpfi_out_str (stdout, 10, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 10, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of a random point chosen in the given interval is in the + image of this interval. */ +void +random_iqi (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + IQI_fun f_IQI = MPFI_FUN_GET (*this, IQI); + RQR_fun f_RQR = MPFI_FUN_MPFR_FUNCTION (*this, IQI); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpq_ptr q = MPFI_FUN_ARG (*this, 3, mpq); + mpfi_ptr a = MPFI_FUN_ARG (*this, 4, mpfi); + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + random_mpq (q); + mpfi_alea (x, a); + f_IQI (b, q, a); + f_RQR (y, q, x, MPFI_RNDD); + if (!mpfr_nan_p (y) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (y, b)) { + printf ("Error: the image b of (q, a) does not contain the image y " + "of (q, x) where x is in a.\nq= "); + mpq_out_str (stdout, 10, q); + printf ("\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_iqi (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 4, mpfi), prec); +} + +void +clear_iqi (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (mpq_t) */ + mpq_clear (MPFI_FUN_ARG (*this, 3, mpq)); + /* [4] operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 4, mpfi)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IQI (mpfi_function_ptr this, IQI_fun mpfi_function, + RQR_fun mpfr_function) +{ + this->type = IQI; + this->func.IQI = mpfi_function; + this->mpfr_func.IQI = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] second operand (mpq_t) */ + mpq_init (MPFI_FUN_ARG (*this, 3, mpq)); + /* [4] first operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 4, mpfi), 1024); + + /* init methods */ + this->set_prec = set_prec_iqi; + this->read_line = read_line_iqi; + this->check_line = check_line_iqi; + this->random = random_iqi; + this->clear = clear_iqi; +} diff --git a/tests/type_ir.c b/tests/type_ir.c new file mode 100644 index 0000000..ab3163e --- /dev/null +++ b/tests/type_ir.c @@ -0,0 +1,137 @@ +/* type_ir.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpfr_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern char * pathname; +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_ir (mpfi_function_ptr this, FILE* fp) +{ + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + test_line_number = line_number; + /* [0] initial value */ + read_mpfi (fp, got); + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, expected); + /* [3] integral operand */ + read_mpfr (fp, MPFI_FUN_ARG (*this, 3, mpfr)); + + /* data validation */ + if (mpfi_get_prec (got) != mpfi_get_prec (expected)) { + printf ("Error in data file %s line %lu\nThe precisions of intervals " + "are different.\n", pathname, test_line_number); + exit (1); + } +} + +void +check_line_ir (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IR_fun f_IR = MPFI_FUN_GET (*this, IR); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpfr_ptr op = MPFI_FUN_ARG (*this, 3, mpfr); + + inex = f_IR (got, op); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop = ", test_line_number); + mpfr_out_str (stdout, 16, 0, op, MPFI_RNDD); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } +} + +void +set_prec_ir (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfr_set_prec (MPFI_FUN_ARG (*this, 3, mpfr), prec); +} + +void +clear_ir (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (mpfr_t) */ + mpfr_clear (MPFI_FUN_ARG (*this, 3, mpfr)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IR (mpfi_function_ptr this, IR_fun mpfi_function, + NULL_fun mpfr_function) +{ + this->type = IR; + this->func.IR = mpfi_function; + this->mpfr_func.IR = mpfr_function; + this->random_domain = NULL; + + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] operand (mpfr_t) */ + mpfr_init2 (MPFI_FUN_ARG (*this, 3, mpfr), 1024); + + /* init methods */ + this->set_prec = set_prec_ir; + this->read_line = read_line_ir; + this->check_line = check_line_ir; + this->random = NULL; + this->clear = clear_ir; +} diff --git a/tests/type_iri.c b/tests/type_iri.c new file mode 100644 index 0000000..a815ea6 --- /dev/null +++ b/tests/type_iri.c @@ -0,0 +1,208 @@ +/* type_iri.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpfi_t, mpfr_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iri (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] mpfr_t operand */ + read_mpfr (fp, MPFI_FUN_ARG (*this, 3, mpfr)); + /* [4] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 4, mpfi)); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ +void +check_line_iri (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IRI_fun f_IRI = MPFI_FUN_GET (*this, IRI); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpfr_ptr op1 = MPFI_FUN_ARG (*this, 3, mpfr); + mpfi_ptr op2 = MPFI_FUN_ARG (*this, 4, mpfi); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_IRI (got, op1, op2); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = ", test_line_number); + mpfr_out_str (stdout, 16, 0, op1, MPFI_RNDD); + printf ("\nop2 = "); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op2)) { + mpfi_set (got, op2); + + inex = f_IRI (got, op1, got); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpfr_out_str (stdout, 16, 0, op1, MPFI_RNDD); + printf ("\nop2 = "); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of random points chosen in the given intervals is in the + image of these intervals. */ +void +random_iri (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + IRI_fun f_IRI = MPFI_FUN_GET (*this, IRI); + RRR_fun f_RRR = MPFI_FUN_MPFR_FUNCTION (*this, IRI); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpfr_ptr x = MPFI_FUN_ARG (*this, 3, mpfr); + mpfi_ptr a = MPFI_FUN_ARG (*this, 4, mpfi); + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr y = &(i->left); + mpfr_ptr z = &(i->right); + + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + random_mpfr (x); + mpfi_alea (y, a); + f_IRI (b, x, a); + f_RRR (z, x, y, MPFI_RNDD); + if (!mpfr_nan_p (z) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (z, b)) { + printf ("Error: the image b of (x, a) does not contain the image z " + "of (x, y) where y is in a.\nx= "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + printf ("\nz = "); + mpfr_out_str (stdout, 10, 0, z, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_iri (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfr_set_prec (MPFI_FUN_ARG (*this, 3, mpfr), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 4, mpfi), prec); +} + +void +clear_iri (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] first operand (mpfr_t) */ + mpfr_clear (MPFI_FUN_ARG (*this, 3, mpfr)); + /* [4] second operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 4, mpfi)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IRI (mpfi_function_ptr this, IRI_fun mpfi_function, + RRR_fun mpfr_function) +{ + this->type = IRI; + this->func.IRI = mpfi_function; + this->mpfr_func.IRI = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] second operand (mpfr_t) */ + mpfr_init2 (MPFI_FUN_ARG (*this, 3, mpfr), 1024); + /* [4] first operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 4, mpfi), 1024); + + /* init methods */ + this->set_prec = set_prec_iri; + this->read_line = read_line_iri; + this->check_line = check_line_iri; + this->random = random_iri; + this->clear = clear_iri; +} diff --git a/tests/type_is.c b/tests/type_is.c new file mode 100644 index 0000000..0c23074 --- /dev/null +++ b/tests/type_is.c @@ -0,0 +1,134 @@ +/* type_is.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, long). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern char * pathname; +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_is (mpfi_function_ptr this, FILE* fp) +{ + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + test_line_number = line_number; + /* [0] initial value */ + read_mpfi (fp, got); + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, expected); + /* [3] integral operand */ + read_si (fp, &(MPFI_FUN_ARG (*this, 3, si))); + + /* data validation */ + if (mpfi_get_prec (got) != mpfi_get_prec (expected)) { + printf ("Error in data file %s line %lu\nThe precisions of intervals " + "are different.\n", pathname, test_line_number); + exit (1); + } +} + +void +check_line_is (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IS_fun f_IS = MPFI_FUN_GET (*this, IS); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + long op = MPFI_FUN_ARG (*this, 3, si); + + inex = f_IS (got, op); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop = %ld", test_line_number, op); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } +} + +void +set_prec_is (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); +} + +void +clear_is (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (long), needs no deallocation */ + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IS (mpfi_function_ptr this, IS_fun mpfi_function, + NULL_fun mpfr_function) +{ + this->type = IS; + this->func.IS = mpfi_function; + this->mpfr_func.IS = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] operand (signed long), needs no initialization */ + + /* init methods */ + this->set_prec = set_prec_is; + this->read_line = read_line_is; + this->check_line = check_line_is; + this->random = NULL; + this->clear = clear_is; +} diff --git a/tests/type_isi.c b/tests/type_isi.c new file mode 100644 index 0000000..b2702a9 --- /dev/null +++ b/tests/type_isi.c @@ -0,0 +1,200 @@ +/* type_isi.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, long, mpfi_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_isi (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] signed integral operand */ + read_si (fp, &(MPFI_FUN_ARG (*this, 3, si))); + /* [4] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 4, mpfi)); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ + +void +check_line_isi (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + ISI_fun f_ISI = MPFI_FUN_GET (*this, ISI); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + long op1 = MPFI_FUN_ARG (*this, 3, si); + mpfi_ptr op2 = MPFI_FUN_ARG (*this, 4, mpfi); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_ISI (got, op1, op2); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = %ld\nop2 = ", test_line_number, op1); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op2)) { + mpfi_set (got, op2); + + inex = f_ISI (got, op1, got); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = %ld\nop2 = ", test_line_number, op1); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of a random point chosen in the given interval is in the + image of this interval. */ +void +random_isi (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + ISI_fun f_ISI = MPFI_FUN_GET (*this, ISI); + RSR_fun f_RSR = MPFI_FUN_MPFR_FUNCTION (*this, ISI); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpfi_ptr a = MPFI_FUN_ARG (*this, 4, mpfi); + long si; + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + + si = random_si (); + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + mpfi_alea (x, a); + f_ISI (b, si, a); + f_RSR (y, si, x, MPFI_RNDD); + if (!mpfr_nan_p (y) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (y, b)) { + printf ("Error: the interval b, image of (n, a), does not contain the " + "point y, image of (n, x) where x is in a.\nn = %ld\na = ", si); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_isi (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 4, mpfi), prec); +} + +void +clear_isi (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (signed long), needs no deallocation */ + /* [4] operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 4, mpfi)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_ISI (mpfi_function_ptr this, ISI_fun mpfi_function, + RSR_fun mpfr_function) +{ + this->type = ISI; + this->func.ISI = mpfi_function; + this->mpfr_func.ISI = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] first operand (signed long), needs no initialization */ + /* [4] second operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 4, mpfi), 1024); + + /* init methods */ + this->set_prec = set_prec_isi; + this->read_line = read_line_isi; + this->check_line = check_line_isi; + this->random = random_isi; + this->clear = clear_isi; +} diff --git a/tests/type_iu.c b/tests/type_iu.c new file mode 100644 index 0000000..1264ead --- /dev/null +++ b/tests/type_iu.c @@ -0,0 +1,134 @@ +/* type_iu.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, unsigned long). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern char * pathname; +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iu (mpfi_function_ptr this, FILE* fp) +{ + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + test_line_number = line_number; + /* [0] initial value */ + read_mpfi (fp, got); + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, expected); + /* [3] unsigned integral operand */ + read_ui (fp, &(MPFI_FUN_ARG (*this, 3, ui))); + + /* data validation */ + if (mpfi_get_prec (got) != mpfi_get_prec (expected)) { + printf ("Error in data file %s line %lu\nThe precisions of intervals " + "are different.\n", pathname, test_line_number); + exit (1); + } +} + +void +check_line_iu (mpfi_function_ptr function) +{ + int inex; + + /* rename operands for better readability */ + IU_fun f_IU = MPFI_FUN_GET (*function, IU); + mpfi_ptr got = MPFI_FUN_ARG (*function, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*function, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*function, 2, mpfi); + unsigned long op = MPFI_FUN_ARG (*function, 3, ui); + + inex = f_IU (got, op); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop = %lu", test_line_number, op); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } +} + +void +set_prec_iu (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); +} + +void +clear_iu (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (unsigned long), needs no deallocation */ + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IU (mpfi_function_ptr this, IU_fun mpfi_function, + NULL_fun mpfr_function) +{ + this->type = IU; + this->func.IU = mpfi_function; + this->mpfr_func.IU = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] operand (unsigned long), needs no initialization */ + + /* init methods */ + this->set_prec = set_prec_iu; + this->read_line = read_line_iu; + this->check_line = check_line_iu; + this->random = NULL; + this->clear = clear_iu; +} diff --git a/tests/type_iui.c b/tests/type_iui.c new file mode 100644 index 0000000..f43198f --- /dev/null +++ b/tests/type_iui.c @@ -0,0 +1,200 @@ +/* type_iui.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, unsigned long, mpfi_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iui (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] unsigned integral operand */ + read_ui (fp, &(MPFI_FUN_ARG (*this, 3, ui))); + /* [4] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 4, mpfi)); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ + +void +check_line_iui (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IUI_fun f_IUI = MPFI_FUN_GET (*this, IUI); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + unsigned long op1 = MPFI_FUN_ARG (*this, 3, ui); + mpfi_ptr op2 = MPFI_FUN_ARG (*this, 4, mpfi); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_IUI (got, op1, op2); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = %lu\nop2 = ", test_line_number, op1); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op2)) { + mpfi_set (got, op2); + + inex = f_IUI (got, op1, got); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = %lu\nop2 = ", test_line_number, op1); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of a random point chosen in the given interval is in the + image of this interval. */ +void +random_iui (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + IUI_fun f_IUI = MPFI_FUN_GET (*this, IUI); + RUR_fun f_RUR = MPFI_FUN_MPFR_FUNCTION (*this, IUI); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + unsigned long ui; + mpfi_ptr a = MPFI_FUN_ARG (*this, 4, mpfi); + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + + ui = random_ui (); + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + mpfi_alea (x, a); + f_IUI (b, ui, a); + f_RUR (y, ui, x, MPFI_RNDD); + if (!mpfr_nan_p (y) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (y, b)) { + printf ("Error: the interval b, image of (n, a), does not contain the " + "point y, image of (n, x) where x is in a.\nn = %lu\na = ", ui); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_iui (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 4, mpfi), prec); +} + +void +clear_iui (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] first operand (unsigned long), needs no deallocation */ + /* [4] second operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 4, mpfi)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IUI (mpfi_function_ptr this, IUI_fun mpfi_function, + RUR_fun mpfr_function) +{ + this->type = IUI; + this->func.IUI = mpfi_function; + this->mpfr_func.IUI = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] first operand (unsigned long), needs no initialization */ + /* [4] second operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 4, mpfi), 1024); + + /* init methods */ + this->set_prec = set_prec_iui; + this->read_line = read_line_iui; + this->check_line = check_line_iui; + this->random = random_iui; + this->clear = clear_iui; +} diff --git a/tests/type_iz.c b/tests/type_iz.c new file mode 100644 index 0000000..a1294cc --- /dev/null +++ b/tests/type_iz.c @@ -0,0 +1,137 @@ +/* type_iz.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpz_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern char * pathname; +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_iz (mpfi_function_ptr this, FILE* fp) +{ + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + test_line_number = line_number; + /* [0] initial value */ + read_mpfi (fp, got); + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, expected); + /* [3] integral operand */ + read_mpz (fp, MPFI_FUN_ARG (*this, 3, mpz)); + + /* data validation */ + if (mpfi_get_prec (got) != mpfi_get_prec (expected)) { + printf ("Error in data file %s line %lu\nThe precisions of intervals " + "are different.\n", pathname, test_line_number); + exit (1); + } +} + +void +check_line_iz (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IZ_fun f_IZ = MPFI_FUN_GET (*this, IZ); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpz_ptr op = MPFI_FUN_ARG (*this, 3, mpz); + + inex = f_IZ (got, op); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop = ", test_line_number); + mpz_out_str (stdout, 16, op); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } +} + +void +set_prec_iz (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); +} + +void +clear_iz (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (mpz_t) */ + mpz_clear (MPFI_FUN_ARG (*this, 3, mpz)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IZ (mpfi_function_ptr this, IZ_fun mpfi_function, + NULL_fun mpfr_function) +{ + this->type = IZ; + this->func.IZ = mpfi_function; + this->mpfr_func.IZ = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] operand (mpz_t) */ + mpz_init (MPFI_FUN_ARG (*this, 3, mpz)); + + /* init methods */ + this->set_prec = set_prec_iz; + this->read_line = read_line_iz; + this->check_line = check_line_iz; + this->random = NULL; + this->clear = clear_iz; +} diff --git a/tests/type_izi.c b/tests/type_izi.c new file mode 100644 index 0000000..9087c03 --- /dev/null +++ b/tests/type_izi.c @@ -0,0 +1,209 @@ +/* type_izi.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, mpz_t, mpfi_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern unsigned long line_number; /* current line */ +static unsigned long test_line_number; /* start line of current test */ + +void +read_line_izi (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] mpz_t operand */ + read_mpz (fp, MPFI_FUN_ARG (*this, 3, mpz)); + /* [4] mpfi_t operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 4, mpfi)); +} + +/* check function against data at different precisions and test if an + input variable can be reused as output */ + +void +check_line_izi (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + IZI_fun f_IZI = MPFI_FUN_GET (*this, IZI); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + mpz_ptr op1 = MPFI_FUN_ARG (*this, 3, mpz); + mpfi_ptr op2 = MPFI_FUN_ARG (*this, 4, mpfi); + + mpfi_set_prec (got, mpfi_get_prec (expected)); + + inex = f_IZI (got, op1, op2); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop1 = ", test_line_number); + mpz_out_str (stdout, 16, op1); + printf ("\nop2 = "); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + + /* reuse input variable as output */ + if (mpfi_get_prec (got) == mpfi_get_prec (op2)) { + mpfi_set (got, op2); + + inex = f_IZI (got, op1, got); + + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Error when reusing first input argument as output (line %lu)." + "\nop1 = ", test_line_number); + mpz_out_str (stdout, 16, op1); + printf ("\nop2 = "); + mpfi_out_str (stdout, 16, 0, op2); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", + inex, expected_inex); + + exit (1); + } + } +} + +/* Check if the image of a random point chosen in the given interval is in the + image of this interval. */ +void +random_izi (mpfi_function_ptr this) +{ + /* rename operands for better readability */ + IZI_fun f_IZI = MPFI_FUN_GET (*this, IZI); + RZR_fun f_RZR = MPFI_FUN_MPFR_FUNCTION (*this, IZI); + mpfi_ptr b = MPFI_FUN_ARG (*this, 2, mpfi); + mpz_ptr z = MPFI_FUN_ARG (*this, 3, mpz); + mpfi_ptr a = MPFI_FUN_ARG (*this, 4, mpfi); + /* reuse endpoint as mpfr_t */ + mpfi_ptr i = MPFI_FUN_ARG (*this, 0, mpfi); + mpfr_ptr x = &(i->left); + mpfr_ptr y = &(i->right); + unsigned long n = mpfi_get_prec (a) + 17; + + random_interval (a); + if (this->random_domain != NULL) { + /* restrict the range of random interval to speed up tests */ + this->random_domain (a); + } + random_mpz (z, n); + mpfi_alea (x, a); + f_IZI (b, z, a); + f_RZR (y, z, x, MPFI_RNDD); + if (!mpfr_nan_p (y) && !MPFI_NAN_P (b) && !mpfi_is_inside_fr (y, b)) { + printf ("Error: the image b of (n, a) does not contain the image y " + "of (n, x) where x is in a.\nn= "); + mpz_out_str (stdout, 10, z); + printf ("\na = "); + mpfi_out_str (stdout, 10, 0, a); + printf ("\nb = "); + mpfi_out_str (stdout, 10, 0, b); + printf ("\nx = "); + mpfr_out_str (stdout, 10, 0, x, MPFI_RNDU); + printf ("\ny = "); + mpfr_out_str (stdout, 10, 0, y, MPFI_RNDU); + putchar ('\n'); + + exit (1); + } +} + +void +set_prec_izi (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 4, mpfi), prec); +} + +void +clear_izi (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (mpz_t) */ + mpz_clear (MPFI_FUN_ARG (*this, 3, mpz)); + /* [4] operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 4, mpfi)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_IZI (mpfi_function_ptr this, IZI_fun mpfi_function, + RZR_fun mpfr_function) +{ + this->type = IZI; + this->func.IZI = mpfi_function; + this->mpfr_func.IZI = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (5 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] first operand (mpz_t) */ + mpz_init (MPFI_FUN_ARG (*this, 3, mpz)); + /* [4] second operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 4, mpfi), 1024); + + /* init methods */ + this->set_prec = set_prec_izi; + this->read_line = read_line_izi; + this->check_line = check_line_izi; + this->random = random_izi; + this->clear = clear_izi; +} diff --git a/tests/type_js.c b/tests/type_js.c new file mode 100644 index 0000000..1e8f274 --- /dev/null +++ b/tests/type_js.c @@ -0,0 +1,131 @@ +/* type_js.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, intmax_t). + +Copyright 2018, + AriC project, Inria Grenoble - Rhone-Alpes, France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern char * pathname; +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_js (mpfi_function_ptr this, FILE* fp) +{ + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + test_line_number = line_number; + /* [0] initial value */ + read_mpfi (fp, got); + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, expected); + /* [3] integral operand */ + read_sj (fp, &(MPFI_FUN_ARG (*this, 3, si))); + + /* data validation */ + if (mpfi_get_prec (got) != mpfi_get_prec (expected)) { + printf ("Error in data file %s line %lu\nThe precisions of intervals " + "are different.\n", pathname, test_line_number); + exit (1); + } +} + +void +check_line_js (mpfi_function_ptr this) +{ + int inex; + + /* rename operands for better readability */ + JS_fun f_JS = MPFI_FUN_GET (*this, JS); + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*this, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + intmax_t op = MPFI_FUN_ARG (*this, 3, sj); + + inex = f_JS (got, op); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop = %ld", test_line_number, op); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } +} + +void +set_prec_js (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); +} + +void +clear_js (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (intmax_t), needs no deallocation */ + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_JS (mpfi_function_ptr this, JS_fun mpfi_function, + NULL_fun mpfr_function) +{ + this->type = JS; + this->func.JS = mpfi_function; + this->mpfr_func.JS = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] operand (signed huge), needs no initialization */ + + /* init methods */ + this->set_prec = set_prec_js; + this->read_line = read_line_js; + this->check_line = check_line_js; + this->random = NULL; + this->clear = clear_js; +} diff --git a/tests/type_ju.c b/tests/type_ju.c new file mode 100644 index 0000000..9aa14e0 --- /dev/null +++ b/tests/type_ju.c @@ -0,0 +1,131 @@ +/* type_ju.c -- Test functions associated with functions of the type + mpfi_f (mpfi_t, unsigned huge). + +Copyright 2018, + AriC project, Inria Grenoble - Rhone-Alpes, France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern char * pathname; +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_ju (mpfi_function_ptr this, FILE* fp) +{ + mpfi_ptr got = MPFI_FUN_ARG (*this, 0, mpfi); + mpfi_ptr expected = MPFI_FUN_ARG (*this, 2, mpfi); + + test_line_number = line_number; + /* [0] initial value */ + read_mpfi (fp, got); + /* [1] return value */ + read_exactness (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value */ + read_mpfi (fp, expected); + /* [3] unsigned huge integral operand */ + read_uj (fp, &(MPFI_FUN_ARG (*this, 3, uj))); + + /* data validation */ + if (mpfi_get_prec (got) != mpfi_get_prec (expected)) { + printf ("Error in data file %s line %lu\nThe precisions of intervals " + "are different.\n", pathname, test_line_number); + exit (1); + } +} + +void +check_line_ju (mpfi_function_ptr function) +{ + int inex; + + /* rename operands for better readability */ + JU_fun f_JU = MPFI_FUN_GET (*function, JU); + mpfi_ptr got = MPFI_FUN_ARG (*function, 0, mpfi); + int expected_inex = MPFI_FUN_ARG (*function, 1, i); + mpfi_ptr expected = MPFI_FUN_ARG (*function, 2, mpfi); + uintmax_t op = MPFI_FUN_ARG (*function, 3, uj); + + inex = f_JU (got, op); + if (inex != expected_inex || !same_value (got, expected)) { + printf ("Failed line %lu.\nop = %lu", test_line_number, op); + printf ("\ngot = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nexpected = "); + mpfi_out_str (stdout, 16, 0, expected); + putchar ('\n'); + if (inex != expected_inex) + printf ("inexact flag: got = %u, expected = %u\n", inex, expected_inex); + + exit (1); + } +} + +void +set_prec_ju (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfi_set_prec (MPFI_FUN_ARG (*this, 0, mpfi), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 2, mpfi), prec); +} + +void +clear_ju (mpfi_function_ptr this) +{ + /* [0] initial value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 0, mpfi)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 2, mpfi)); + /* [3] operand (unsigned huge), needs no deallocation */ + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_JU (mpfi_function_ptr this, JU_fun mpfi_function, + NULL_fun mpfr_function) +{ + this->type = JU; + this->func.JU = mpfi_function; + this->mpfr_func.JU = mpfr_function; + this->random_domain = NULL; + + /* init operands */ + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] initial value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 0, mpfi), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 2, mpfi), 1024); + /* [3] operand (unsigned huge), needs no initialization */ + + /* init methods */ + this->set_prec = set_prec_ju; + this->read_line = read_line_ju; + this->check_line = check_line_ju; + this->random = NULL; + this->clear = clear_ju; +} diff --git a/tests/type_ri.c b/tests/type_ri.c new file mode 100644 index 0000000..6e05f9d --- /dev/null +++ b/tests/type_ri.c @@ -0,0 +1,130 @@ +/* type_ri.c -- Test functions associated with functions of the type + mpfi_f (mpfr_t, mpfi_t). + +Copyright 2010, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +extern char * pathname; +extern unsigned long line_number; +static unsigned long test_line_number; /* start line of a test */ + +void +read_line_ri (mpfi_function_ptr this, FILE* fp) +{ + test_line_number = line_number; + /* [1] return value */ + read_sign (fp, &(MPFI_FUN_ARG (*this, 1, i))); + /* [2] expected value (mpfr_t)*/ + read_mpfr (fp, MPFI_FUN_ARG (*this, 2, mpfr)); + /* [3] operand */ + read_mpfi (fp, MPFI_FUN_ARG (*this, 3, mpfi)); +} + +void +check_line_ri (mpfi_function_ptr this) +{ + int ret; + + /* rename operands for better readability */ + RI_fun f_RI = MPFI_FUN_GET (*this, RI); + mpfr_ptr got = MPFI_FUN_ARG (*this, 0, mpfr); + int expected_ret = MPFI_FUN_ARG (*this, 1, i); + mpfr_ptr expected = MPFI_FUN_ARG (*this, 2, mpfr); + mpfi_ptr op = MPFI_FUN_ARG (*this, 3, mpfi); + + mpfr_set_prec (got, mpfr_get_prec (expected)); + ret = f_RI (got, op); + if ((ret != expected_ret && ret * expected_ret <= 0) + || !same_mpfr_value (got, expected)) { + printf ("Failed line %lu.\nop = ", test_line_number); + mpfi_out_str (stdout, 16, 0, op); + printf ("\ngot = "); + mpfr_out_str (stdout, 16, 0, got, MPFI_RNDD); + printf ("\nexpected = "); + mpfr_out_str (stdout, 16, 0, expected, MPFI_RNDD); + putchar ('\n'); + if (ret != expected_ret || ret * expected_ret < 0) { + printf ("return value: got = %d, %s expected\n", ret, + expected_ret < 0 ? "negative" + : expected_ret > 0 ? "positive" : "zero"); + } + + exit (1); + } +} + +void +set_prec_ri (mpfi_function_ptr this, mpfr_prec_t prec) +{ + mpfr_set_prec (MPFI_FUN_ARG (*this, 0, mpfr), prec); + mpfr_set_prec (MPFI_FUN_ARG (*this, 2, mpfr), prec); + mpfi_set_prec (MPFI_FUN_ARG (*this, 3, mpfi), prec); +} + +void +clear_ri (mpfi_function_ptr this) +{ + /* [0] result (mpfr_t) */ + mpfr_clear (MPFI_FUN_ARG (*this, 0, mpfr)); + /* [1] return value (int), needs no deallocation */ + /* [2] expected value (mpfr_t) */ + mpfr_clear (MPFI_FUN_ARG (*this, 2, mpfr)); + /* [3] operand (mpfi_t) */ + mpfi_clear (MPFI_FUN_ARG (*this, 3, mpfi)); + + free (MPFI_FUN_ARGS (*this)); + MPFI_FUN_ARGS (*this) = NULL; +} + +/* In operands array, variables are in the same order as for data in + '.dat' files plus one additional variable before them. */ +void +mpfi_fun_init_RI (mpfi_function_ptr this, RI_fun mpfi_function, + NULL_fun mpfr_function) +{ + this->type = RI; + this->func.RI = mpfi_function; + this->mpfr_func.RI = mpfr_function; + this->random_domain = NULL; + + MPFI_FUN_ARGS (*this) = + (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t)); + + /* [0] result (mpfr_t) */ + mpfr_init2 (MPFI_FUN_ARG (*this, 0, mpfr), 1024); + /* [1] return value (int), needs no initialization */ + /* [2] expected value (mpfr_t) */ + mpfr_init2 (MPFI_FUN_ARG (*this, 2, mpfr), 1024); + /* [3] operand (mpfi_t) */ + mpfi_init2 (MPFI_FUN_ARG (*this, 3, mpfi), 1024); + + /* init methods */ + this->set_prec = set_prec_ri; + this->read_line = read_line_ri; + this->check_line = check_line_ri; + this->random = NULL; + this->clear = clear_ri; +} diff --git a/tests/tz_div.c b/tests/tz_div.c new file mode 100644 index 0000000..74b42c5 --- /dev/null +++ b/tests/tz_div.c @@ -0,0 +1,119 @@ +/* tz_div.c -- Test mpfi_z_div. + +Copyright 2010, 2011, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" +#include "mpfi_config.h" + +void +check_overflow (void) +{ + mpfi_t interval; + mpfi_t got; + mpz_t z; + int inex; + + mpz_init (z); + mpfi_init2 (interval, 53); + mpfi_init2 (got, 53); + + /* right overflow: 1024 / [epsilon, 1] = [1024, +oo] */ + mpz_set_ui (z, 1024); + mpfr_set_ui (&(interval->left), 0, MPFI_RNDD); + mpfr_nextabove (&(interval->left)); /* tiny left endpoint x0 */ + mpfr_set_ui (&(interval->right), 1, MPFI_RNDU); + + inex = mpfi_z_div (got, z, interval); + if (MPFI_LEFT_IS_INEXACT (inex) || mpfr_cmp_z (&(got->left), z) != 0 + || !MPFI_RIGHT_IS_INEXACT (inex) || !mpfr_inf_p (&(got->right))) { + printf ("Error: mpfi_z_div (rop, z, op) does not correctly handle " + "overflow.\n z = "); + mpz_out_str (stdout, 10, z); + printf ("\n op = "); + mpfi_out_str (stdout, 10, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + /* left overflow: 1024.0 / [-1, -epsilon] = [-oo, -1024] */ + mpfi_neg (interval, interval); + + inex = mpfi_z_div (got, z, interval); + if (!MPFI_LEFT_IS_INEXACT (inex) + || !mpfr_inf_p (&(got->left)) + || MPFI_RIGHT_IS_INEXACT (inex) + || mpfr_cmp_si (&(got->right), -1024) != 0) { + printf ("Error: mpfi_z_div (rop, z, op) does not correctly handle " + "overflow.\n z = "); + mpz_out_str (stdout, 10, z); + printf ("\n op = "); + mpfi_out_str (stdout, 10, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 10, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + mpz_clear (z); + mpfi_clear (interval); + mpfi_clear (got); +} + +#ifndef HAVE_MPFR_Z_DIV +/* fake non-existing function */ +int +mpfr_z_div (mpfr_ptr x, mpz_srcptr z, mpfr_srcptr y, mpfr_rnd_t rnd) +{ + int ret; + mpfr_t zz; + + mpfr_init2 (zz, mpz_sizeinbase (z, 2)); + mpfr_set_z (zz, z, MPFI_RNDD); /* exact */ + ret = mpfr_div (x, zz, y, rnd); + mpfr_clear (zz); + + return ret; +} +#endif /*HAVE_MPFR_Z_DIV */ + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_z_div; + + mpfi_fun_init_IZI (&i_z_div, mpfi_z_div, mpfr_z_div); + test_start (); + + check_data (&i_z_div, "z_div.dat"); + check_random (&i_z_div, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_z_div); + + return 0; +} diff --git a/tests/tz_sub.c b/tests/tz_sub.c new file mode 100644 index 0000000..4171181 --- /dev/null +++ b/tests/tz_sub.c @@ -0,0 +1,122 @@ +/* tz_sub.c -- Test mpfi_z_sub. + +Copyright 2010, 2011, + Spaces project, Inria Lorraine + and Salsa project, INRIA Rocquencourt, + and Arenaire project, Inria Rhone-Alpes, France + and Lab. ANO, USTL (Univ. of Lille), France + + +This file is part of the MPFI Library. + +The MPFI Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFI Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFI Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include "mpfi-tests.h" + +void +check_overflow () +{ + mpfi_t interval; + mpfi_t got; + mpz_t z; + int inex; + + mpfi_init2 (interval, 53); + mpfi_init2 (got, 53); + mpz_init (z); + + /* right overflow: 1023 - [-Max, 0] = [1023, +oo] */ + mpz_set_ui (z, 1023); + mpfr_set_inf (&(interval->left), -1); + mpfr_nextabove (&(interval->left)); + mpfr_set_ui (&(interval->right), 0, MPFI_RNDU); + + inex = mpfi_z_sub (got, z, interval); + + if (MPFI_LEFT_IS_INEXACT (inex) || mpfr_cmp_z (&(got->left), z) != 0 + || !MPFI_RIGHT_IS_INEXACT (inex) || !mpfr_inf_p (&(got->right))) { + printf ("Error: mpfi_fr_sub (rop, z, op) does not correctly handle " + "overflow.\n z = "); + mpz_out_str (stdout, 16, z); + printf ("\nop = "); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + /* left overflow: -1023 - [0, Max] = [-oo, -1023] */ + mpz_neg (z, z); + mpfi_neg (interval, interval); + + inex = mpfi_z_sub (got, z, interval); + + if (!MPFI_LEFT_IS_INEXACT (inex) + || !mpfr_inf_p (&(got->left)) + || MPFI_RIGHT_IS_INEXACT (inex) + || mpfr_cmp_si (&(got->right), -1023) != 0) { + printf ("Error: mpfi_fr_sub (rop, z, op) does not correctly handle " + "overflow.\n z = "); + mpz_out_str (stdout, 16, z); + printf ("\nop = "); + mpfi_out_str (stdout, 16, 0, interval); + printf ("\nrop = "); + mpfi_out_str (stdout, 16, 0, got); + printf ("\nreturn value = %d\n", inex); + exit (1); + } + + mpz_clear (z); + mpfi_clear (interval); + mpfi_clear (got); +} + +#ifndef HAVE_MPFR_Z_SUB +/* fake non-existing function */ +int +mpfr_z_sub (mpfr_ptr x, mpz_srcptr z, mpfr_srcptr y, mpfr_rnd_t rnd) +{ + int ret; + + /* invert rounding mode */ + if (rnd == MPFI_RNDU) + rnd = MPFI_RNDD; + else if (rnd == MPFI_RNDD) + rnd = MPFI_RNDU; + ret = mpfr_sub_z (x, y, z, rnd); + mpfr_neg (x, x, MPFI_RNDU); + return -ret; +} +#endif /* HAVE_MPFR_Z_SUB */ + +int +main (int argc, char **argv) +{ + struct mpfi_function_t i_z_sub; + + mpfi_fun_init_IZI (&i_z_sub, mpfi_z_sub, mpfr_z_sub); + test_start (); + + check_data (&i_z_sub, "z_sub.dat"); + check_random (&i_z_sub, 2, 1000, 10); + check_overflow (); + + test_end (); + mpfi_fun_clear (&i_z_sub); + + return 0; +} diff --git a/tests/ui_div.dat b/tests/ui_div.dat new file mode 100644 index 0000000..343deff --- /dev/null +++ b/tests/ui_div.dat @@ -0,0 +1,81 @@ +# data file for mpfi_ui_div +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: first parameter value +# 6: precision of second parameter +# 7: left endpoint value of second parameter +# 8: right endpoint value of second parameter + +# special values +0 53 nan nan 0 53 nan nan +0 53 nan nan 1 53 nan nan +0 53 nan nan 0 53 nan -inf +0 53 nan nan 3 53 nan -inf +0 53 nan nan 0 53 nan -7 +0 53 nan nan 7 53 nan -7 +0 53 nan nan 0 53 nan -0 +0 53 nan nan 1 53 nan -0 +0 53 nan nan 0 53 nan 1 +0 53 nan nan 3 53 nan 1 +0 53 nan nan 0 53 nan +inf +0 53 nan nan 6 53 nan +inf +0 53 +0 -0 0 53 -inf -inf +0 53 +0 -0 2 53 -inf -inf +0 53 +0 -0 0 53 -inf -1 +0 53 -4 -0 4 53 -inf -1 + +1 53 -0x12492492492493p-53 -0 + 4 + 53 -inf -7 + +0 53 +0 -0 0 53 -inf -0 +0 53 -inf -0 8 53 -inf -0 +0 53 -inf +inf 0 53 -inf +8 +0 53 -inf +inf 1 53 -inf +8 +0 53 -inf +inf 0 53 -inf +inf +0 53 -inf +inf 3 53 -inf +inf +0 53 nan nan 0 53 -inf nan +0 53 nan nan 6 53 -inf nan + +2 53 -inf -0x12492492492492p-53 + 4 + 53 -7 -0 + +0 53 +0 -0 0 53 +0 -0 +0 53 -inf +inf 1 53 +0 -0 +0 53 +0 -0 0 53 +0 +8 +0 53 0.5 +inf 4 53 +0 +8 + +1 53 0x12492492492492p-53 +inf + 4 + 53 +0 7 + +0 53 +0 -0 0 53 +0 +inf +0 53 +0 +inf 7 53 +0 +inf +0 53 +0 -0 0 53 +inf +inf +0 53 +0 -0 1 53 +inf +inf +0 53 nan nan 0 53 +inf nan +0 53 nan nan 1 53 +inf nan + +# regular values +0 53 -inf +inf + 32 + 53 -32 17 + +0 53 2 5 + 30 + 53 6 15 +1 53 0x11249249249249p-51 5 + 30 + 53 6 14 +2 53 2 0x1124924924924ap-50 + 30 + 53 7 15 +3 53 0x10888888888888p-51 0x14aaaaaaaaaaabp-50 + 31 + 53 6 15 diff --git a/tests/ui_sub.dat b/tests/ui_sub.dat new file mode 100644 index 0000000..4c1daaf --- /dev/null +++ b/tests/ui_sub.dat @@ -0,0 +1,71 @@ +# data file for mpfi_ui_sub +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: first parameter value +# 6: precision of second parameter +# 7: left endpoint value of second parameter +# 8: right endpoint value of second parameter + +# special values +0 53 nan nan 0 53 nan nan +0 53 nan nan 1 53 nan nan +0 53 +inf nan 0 53 nan -inf +0 53 +inf nan 3 53 nan -inf +0 53 7 nan 0 53 nan -7 +0 53 14 nan 7 53 nan -7 +0 53 +0 nan 0 53 nan -0 +0 53 15 nan 15 53 nan -0 +0 53 -1 nan 0 53 nan 1 +0 53 30 nan 31 53 nan 1 +0 53 -inf nan 0 53 nan +inf +0 53 -inf nan 63 53 nan +inf +0 53 +inf +inf 0 53 -inf -inf +0 53 +inf +inf 2 53 -inf -inf +0 53 7 +inf 0 53 -inf -7 +0 53 11 +inf 4 53 -inf -7 + +1 53 0x1p+70 +inf + 1 + 53 -inf -0x1p+70 + +0 53 +0 +inf 0 53 -inf -0 +0 53 8 +inf 8 53 -inf -0 +0 53 -8 +inf 0 53 -inf 8 +0 53 8 +inf 16 53 -inf 8 +0 53 -inf +inf 0 53 -inf +inf +0 53 -inf +inf +32 53 -inf +inf +0 53 nan +inf 0 53 -inf nan +0 53 nan +inf +64 53 -inf nan +0 53 +0 -0 0 53 +0 -0 +0 53 1 1 1 53 +0 -0 +0 53 -8 -0 0 53 +0 8 +0 53 -5 3 3 53 +0 8 +0 53 -inf -0 0 53 +0 +inf +0 53 -inf 7 7 53 +0 +inf +0 53 -inf -inf 0 53 +inf +inf +0 53 -inf -inf 1 53 +inf +inf +0 53 nan -inf 0 53 +inf nan +0 53 nan -inf 1 53 +inf nan + +# regular values +0 53 49 64 32 53 -32 -17 +0 53 +0 15 32 53 17 32 +0 53 -15 -0 17 53 17 32 + +0 53 0x153456789abcdfp-48 0x123456789abce2 + 3 + 53 -0x123456789abcdf -0x123456789abcdfp-48 +1 53 0x3123456789abcdp-52 0x123456789abce2 + 3 + 53 -0x123456789abcdf -0x123456789abcdfp-56 +2 53 1 0x10123456789abdp-44 + 256 + 53 -0x123456789abcdfp-52 0xff +3 53 0xfff 0x1001 + 0x1001 + 53 0x1p-550 0x1fffffffffffffp-52 diff --git a/tests/union.dat b/tests/union.dat new file mode 100644 index 0000000..405f2ab --- /dev/null +++ b/tests/union.dat @@ -0,0 +1,49 @@ +# data file for mpfi_union +# +# for a description of the fields: see add.dat + +# special values +0 53 nan nan 53 nan nan 53 -inf -7 +0 53 nan nan 53 nan nan 53 -8 +1 +0 53 nan nan 53 nan nan 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 nan +0 53 nan nan 53 nan nan 53 +5 +inf +0 53 nan nan 53 nan nan 53 +inf +inf +0 53 nan nan 53 nan nan 53 nan -0 +0 53 nan nan 53 nan -0 53 -inf -7 +0 53 nan nan 53 nan -0 53 -8 +1 +0 53 nan nan 53 nan +inf 53 +0 +inf +0 53 nan nan 53 nan nan 53 +0 +7 +0 53 nan nan 53 nan -inf 53 +5 +inf +0 53 nan nan 53 nan -7 53 +inf +inf +0 53 nan nan 53 nan +1 53 nan -0 +0 53 -inf -inf 53 -inf -inf 53 -inf -inf +0 53 -inf +8 53 -inf -7 53 -1 +8 +0 53 -inf +inf 53 -inf -0 53 +8 +inf +0 53 -inf +inf 53 -inf -0 53 +inf +inf +0 53 -inf +8 53 -inf +8 53 +0 +8 +0 53 -inf +inf 53 -inf +inf 53 +0 +8 +0 53 -inf -0 53 +0 -0 53 -inf -7 +0 53 -7 +8 53 +0 +8 53 -7 -0 +0 53 +0 +8 53 +0 -0 53 +0 +8 +0 53 +0 +inf 53 +0 +inf 53 +0 +8 +0 53 +0 +inf 53 +0 -0 53 +8 +inf +0 53 nan nan 53 +0 +8 53 +inf nan +0 53 -inf +inf 53 +0 -0 53 -inf +inf +0 53 -7 +8 53 +0 +8 53 -7 +8 +0 53 +0 -0 53 +0 -0 53 +0 -0 +0 53 +0 +inf 53 +0 +inf 53 +0 +8 +0 53 nan nan 53 +0 nan 53 +8 +inf +0 53 +0 +inf 53 +0 +8 53 +inf +inf +0 53 -inf +inf 53 +inf +inf 53 -inf +3 +0 53 +0 +inf 53 +inf +inf 53 +0 +inf +0 53 nan nan 53 +inf +inf 53 +3 nan +0 53 nan nan 53 +inf nan 53 -inf -7 +0 53 nan nan 53 +inf nan 53 +inf +inf +0 53 nan nan 53 +inf nan 53 -3 +7 + +# regular values +0 53 -0x0d 0x90 53 0x12 0x90 53 -0x0d 0x34 +1 12 -0x8.f0p-8 0xa0 53 0x0d 0x34 53 -0x8.ef7p-8 0xa0 +2 12 -0x2fp+12 0x1.f3p+24 53 -0x2fp+12 -0x9p-32 53 -0x12 0x1.f2ffffffp+24 +3 12 -0x1.a12p-4 0x4.e78p-4 53 0x00 0x0.037 53 -0x1.a100001p-4 0x4.e7249961p-4 diff --git a/tests/z_div.dat b/tests/z_div.dat new file mode 100644 index 0000000..10085c7 --- /dev/null +++ b/tests/z_div.dat @@ -0,0 +1,112 @@ +# data file for mpfi_z_div +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: first parameter value +# 6: precision of second parameter +# 7: left endpoint value of second parameter +# 8: right endpoint value of second parameter + +# special values +0 53 nan nan -1 53 nan nan +0 53 nan nan 0 53 nan nan +0 53 nan nan 1 53 nan nan +0 53 nan nan -3 53 nan -inf +0 53 nan nan 0 53 nan -inf +0 53 nan nan 3 53 nan -inf +0 53 nan nan -7 53 nan -7 +0 53 nan nan 0 53 nan -7 +0 53 nan nan 7 53 nan -7 +0 53 nan nan -1 53 nan -0 +0 53 nan nan 0 53 nan -0 +0 53 nan nan 1 53 nan -0 +0 53 nan nan -3 53 nan 1 +0 53 nan nan 0 53 nan 1 +0 53 nan nan 3 53 nan 1 +0 53 nan nan -6 53 nan +inf +0 53 nan nan 0 53 nan +inf +0 53 nan nan 6 53 nan +inf +0 53 +0 -0 -2 53 -inf -inf +0 53 +0 -0 0 53 -inf -inf +0 53 +0 -0 2 53 -inf -inf +0 53 +0 4 -4 53 -inf -1 +0 53 +0 -0 0 53 -inf -1 +0 53 -4 -0 4 53 -inf -1 + +2 53 +0 0x12492492492493p-53 + -4 + 53 -inf -7 +1 53 -0x12492492492493p-53 -0 + 4 + 53 -inf -7 + +0 53 +0 +inf -8 53 -inf -0 +0 53 +0 -0 0 53 -inf -0 +0 53 -inf -0 8 53 -inf -0 +0 53 -inf +inf -1 53 -inf +8 +0 53 -inf +inf 0 53 -inf +8 +0 53 -inf +inf 1 53 -inf +8 +0 53 -inf +inf -3 53 -inf +inf +0 53 -inf +inf 0 53 -inf +inf +0 53 -inf +inf 3 53 -inf +inf +0 53 nan nan -6 53 -inf nan +0 53 nan nan 0 53 -inf nan +0 53 nan nan 6 53 -inf nan +0 53 -inf +inf -1 53 +0 -0 +0 53 +0 -0 0 53 +0 -0 +0 53 -inf +inf 1 53 +0 -0 +0 53 -inf -0.5 -4 53 +0 +8 +0 53 +0 -0 0 53 +0 +8 +0 53 0.5 +inf 4 53 +0 +8 + +2 53 -inf -0x12492492492492p-53 + -4 + 53 +0 7 +1 53 0x12492492492492p-53 +inf + 4 + 53 +0 7 + +0 53 -inf -0 -7 53 +0 +inf +0 53 +0 -0 0 53 +0 +inf +0 53 +0 +inf 7 53 +0 +inf +0 53 +0 -0 -1 53 +inf +inf +0 53 +0 -0 0 53 +inf +inf +0 53 +0 -0 1 53 +inf +inf +0 53 nan nan -1 53 +inf nan +0 53 nan nan 0 53 +inf nan +0 53 nan nan 1 53 +inf nan + +# regular values +0 53 -inf +inf + -32 + 53 -32 17 + +0 53 2 5 + 30 + 53 6 15 +1 53 0x11249249249249p-51 5 + 30 + 53 6 14 +2 53 2 0x1124924924924ap-50 + 30 + 53 7 15 +3 53 0x10888888888888p-51 0x14aaaaaaaaaaabp-50 + 31 + 53 6 15 + +0 53 -5 -2 + -30 + 53 6 15 +1 53 -0x1124924924924ap-50 -2 + 30 + 53 -15 -7 +2 53 -5 -0x11249249249249p-51 + -30 + 53 6 14 +3 53 -0x14aaaaaaaaaaabp-50 -0x10888888888888p-51 + 31 + 53 -15 -6 diff --git a/tests/z_sub.dat b/tests/z_sub.dat new file mode 100644 index 0000000..ea3aa20 --- /dev/null +++ b/tests/z_sub.dat @@ -0,0 +1,101 @@ +# data file for mpfi_z_sub +# +# column fields: +# 1: inexact flag (returned value) +# 2: precision of result +# 3: left endpoint value of result +# 4: right endpoint value of result +# +# 5: first parameter value +# 6: precision of second parameter +# 7: left endpoint value of second parameter +# 8: right endpoint value of second parameter + +# special values +0 53 nan nan -1 53 nan nan +0 53 nan nan 0 53 nan nan +0 53 nan nan 1 53 nan nan +0 53 +inf nan -3 53 nan -inf +0 53 +inf nan 0 53 nan -inf +0 53 +inf nan 3 53 nan -inf +0 53 +0 nan -7 53 nan -7 +0 53 7 nan 0 53 nan -7 +0 53 14 nan 7 53 nan -7 +0 53 -15 nan -15 53 nan -0 +0 53 +0 nan 0 53 nan -0 +0 53 15 nan 15 53 nan -0 +0 53 -32 nan -31 53 nan 1 +0 53 -1 nan 0 53 nan 1 +0 53 30 nan 31 53 nan 1 +0 53 -inf nan -63 53 nan +inf +0 53 -inf nan 0 53 nan +inf +0 53 -inf nan 63 53 nan +inf +0 53 +inf +inf -2 53 -inf -inf +0 53 +inf +inf 0 53 -inf -inf +0 53 +inf +inf 2 53 -inf -inf +0 53 3 +inf -4 53 -inf -7 +0 53 7 +inf 0 53 -inf -7 +0 53 11 +inf 4 53 -inf -7 + +1 53 0x1p+70 +inf + 1 + 53 -inf -0x1p+70 + +0 53 -8 +inf -8 53 -inf -0 +0 53 +0 +inf 0 53 -inf -0 +0 53 8 +inf 8 53 -inf -0 +0 53 -24 +inf -16 53 -inf 8 +0 53 -8 +inf 0 53 -inf 8 +0 53 8 +inf 16 53 -inf 8 +0 53 -inf +inf -32 53 -inf +inf +0 53 -inf +inf 0 53 -inf +inf +0 53 -inf +inf 32 53 -inf +inf +0 53 nan +inf -64 53 -inf nan +0 53 nan +inf 0 53 -inf nan +0 53 nan +inf 64 53 -inf nan +0 53 -1 -1 -1 53 +0 -0 +0 53 +0 -0 0 53 +0 -0 +0 53 1 1 1 53 +0 -0 +0 53 -11 -3 -3 53 +0 8 +0 53 -8 -0 0 53 +0 8 +0 53 -5 3 3 53 +0 8 +0 53 -inf -7 -7 53 +0 +inf +0 53 -inf -0 0 53 +0 +inf +0 53 -inf 7 7 53 +0 +inf +0 53 -inf -inf -1 53 +inf +inf +0 53 -inf -inf 0 53 +inf +inf +0 53 -inf -inf 1 53 +inf +inf +0 53 nan -inf -1 53 +inf nan +0 53 nan -inf 0 53 +inf nan +0 53 nan -inf 1 53 +inf nan + +# regular values +0 53 -64 -49 -32 53 17 32 +0 53 +0 +15 32 53 17 32 +0 53 -15 -0 17 53 17 32 + +0 53 0x153456789abcdfp-48 0x123456789abce2 + 3 + 53 -0x123456789abcdf -0x123456789abcdfp-48 +1 53 0x3123456789abcdp-52 0x123456789abce2 + 3 + 53 -0x123456789abcdf -0x123456789abcdfp-56 +2 53 1 0x10123456789abdp-44 + 256 + 53 -0x123456789abcdfp-52 0xff +3 53 0xfff 0x1001 + 0x1001 + 53 0x1p-550 0x1fffffffffffffp-52 + +0 53 0xf3456789abcdfp-48 0x123456789abcdc + -3 + 53 -0x123456789abcdf -0x123456789abcdfp-48 +1 53 -0x2edcba98765433p-52 0x123456789abcdc + -3 + 53 -0x123456789abcdf -0x123456789abcdfp-56 +2 53 -0x1ff -0xfedcba9876543p-44 + -256 + 53 -0x123456789abcdfp-52 0xff +3 53 -0x1003 -0x1001 + -0x1001 + 53 0x1p-550 0x1fffffffffffffp-52