1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2015, 2018 Andreas Enge <andreas@enge.fr>
5 ;;; Copyright © 2016, 2020 Nicolas Goaziou <mail@nicolasgoaziou.fr>
6 ;;; Copyright © 2016, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
7 ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
8 ;;; Copyright © 2018 Eric Bavier <bavier@member.fsf.org>
9 ;;; Copyright © 2018, 2019, 2021 Efraim Flashner <efraim@flashner.co.il>
10 ;;; Copyright © 2021 Vinicius Monego <monego@posteo.net>
12 ;;; This file is part of GNU Guix.
14 ;;; GNU Guix is free software; you can redistribute it and/or modify it
15 ;;; under the terms of the GNU General Public License as published by
16 ;;; the Free Software Foundation; either version 3 of the License, or (at
17 ;;; your option) any later version.
19 ;;; GNU Guix is distributed in the hope that it will be useful, but
20 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;;; GNU General Public License for more details.
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
27 (define-module (gnu packages multiprecision)
28 #:use-module (guix licenses)
29 #:use-module (gnu packages)
30 #:use-module (gnu packages autotools)
31 #:use-module (gnu packages m4)
32 #:use-module (gnu packages gcc)
33 #:use-module (gnu packages texinfo)
34 #:use-module (guix packages)
35 #:use-module (guix download)
36 #:use-module (guix utils)
37 #:use-module (guix build-system gnu))
46 (string-append "mirror://gnu/gmp/gmp-"
50 "1wml97fdmpcynsbw9yl77rj29qibfp652d0w3222zlfx5j8jjj7x"))
51 (patches (search-patches "gmp-faulty-test.patch"))))
52 (build-system gnu-build-system)
53 (native-inputs `(("m4" ,m4)))
54 (outputs '("out" "debug"))
56 `(#:parallel-tests? #f ; mpz/reuse fails otherwise
58 '(;; Build a "fat binary", with routines for several
62 ,@(cond ((target-mingw?)
63 ;; Static and shared cannot be built in one go:
64 ;; they produce different headers. We need shared.
68 ;; Remove after core-updates merge.
69 ;; Workaround for gcc-7 transition breakage, -system and cross-build,
70 ;; Note: See <http://bugs.gnu.org/22186> for why not 'CPATH'.
71 ;; Note: See <http://bugs.gnu.org/30756> for why not 'C_INCLUDE_PATH' & co.
74 (modify-phases %standard-phases
75 (add-before 'configure 'setenv
77 (let ((gcc (assoc-ref %build-inputs "cross-gcc"))
78 (libc (assoc-ref %build-inputs "cross-libc")))
79 (setenv "CROSS_CPLUS_INCLUDE_PATH"
80 (string-append gcc "/include/c++"
83 (format #t "environment variable `CROSS_CPLUS_INCLUDE_PATH' set to `~a'\n"
84 (getenv "CROSS_CPLUS_INCLUDE_PATH"))
87 (synopsis "Multiple-precision arithmetic library")
89 "The @acronym{GMP, the GNU Multiple Precision Arithmetic} library performs
90 arbitrary-precision arithmetic on signed integers, rational numbers and floating
91 point numbers. The precision is only limited by the available memory.
92 The library is highly optimized, with a design focus on execution speed.
93 It is aimed at use in, for example, cryptography and computational algebra.")
95 (home-page "https://gmplib.org/")))
97 (define-public gmp-6.0
98 ;; We keep this one around to bootstrap GCC, to work around a compilation
100 ;; <https://gmplib.org/list-archives/gmp-bugs/2015-December/003848.html>.
106 (uri (string-append "mirror://gnu/gmp/gmp-"
110 "0r5pp27cy7ch3dg5v0rsny8bib1zfvrza6027g2mp5f6v8pd6mli"))
111 (patches (search-patches "gmp-arm-asm-nothumb.patch"
112 "gmp-faulty-test.patch"))))))
120 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
123 "0zwaanakrqjf84lfr5hfsdr7hncwv9wj0mchlr7cmxigfgqs760c"))))
124 (build-system gnu-build-system)
125 (outputs '("out" "debug"))
126 (propagated-inputs `(("gmp" ,gmp))) ; <mpfr.h> refers to <gmp.h>
127 (synopsis "C library for arbitrary-precision floating-point arithmetic")
129 "GNU@tie{}@acronym{MPFR, Multiple Precision Floating-Point Reliably} is a C
130 library for performing multiple-precision, floating-point computations with
133 (home-page "https://www.mpfr.org/")))
142 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
145 "0n846hqfqvmsmim7qdlms0qr86f1hck19p12nq3g3z2x74n3sl0p"))))
146 (build-system gnu-build-system)
147 (outputs '("out" "debug"))
148 (propagated-inputs `(("gmp" ,gmp) ; <mpc.h> refers to both
150 (synopsis "C library for arbitrary-precision complex arithmetic")
152 "GNU@tie{}@acronym{MPC, Multiple Precision Complex library} is a C library
153 for performing arithmetic on complex numbers. It supports arbitrarily high
154 precision and correctly rounds the results.")
156 (home-page "http://www.multiprecision.org/mpc/")))
165 (uri (string-append "https://gforge.inria.fr/frs/download.php"
166 "/latestfile/181/mpfi-" version ".tgz"))
168 (base32 "0mismr1ll3wp788dq2n22s5irm0dziy75byyfdwz22kjbmckhf9v"))))
169 (build-system gnu-build-system)
171 `(#:tests? #f ;tests are broken in this release
172 #:configure-flags '("--enable-static=no")))
174 `(("automake" ,automake)
175 ("autoreconf" ,autoconf)
177 ("texinfo" ,texinfo)))
179 `(("gmp" ,gmp) ; <mpfi.h> refers to both
181 (home-page "https://gforge.inria.fr/projects/mpfi/")
182 (synopsis "C library for arbitrary-precision interval arithmetic")
184 "@acronym{MPFI, Multiple Precision Floating-point Interval} is a portable C
185 library for arbitrary-precision interval arithmetic, with intervals represented
186 using MPFR reliable floating-point numbers. It's based on the @acronym{GMP, GNU
187 Multiple Precision Arithmetic} and GNU@tie{}@acronym{MPFR, Multiple Precision
188 Floating-Point Reliably} libraries.
190 The purpose of arbitrary-precision interval arithmetic is to get results that
191 are both guaranteed, thanks to interval computation, and accurate, thanks to
192 multiple-precision arithmetic.")
202 (uri (string-append "http://irram.uni-trier.de/irram-files/iRRAM_"
205 (base32 "1cdmvb4hsa161rfdjqyhd9sb3fcr43p3a6nsj7cb4kn9f94qmjpj"))))
206 (build-system gnu-build-system)
207 (propagated-inputs `(("gmp" ,gmp) ; <mpfi.h> refers to both
210 `(#:parallel-build? #f))
211 (synopsis "C++ package for real arithmetic based on the Real-RAM concept")
213 "@dfn{iRRAM} is a C++ package for error-free real arithmetic based on
214 the concept of a Real-RAM. Its capabilities range from ordinary arithmetic
215 over trigonometric functions to linear algebra and differential
216 equations. A program using iRRAM is coded in ordinary C++, but may use a
217 special class that behaves like real numbers without any
218 error. Additionally, iRRAM uses the concept of multi-valued functions.")
220 (home-page "http://irram.uni-trier.de/")))
229 (uri (string-append "https://crd-legacy.lbl.gov/~dhbailey/mpdist/qd-"
232 (base32 "1lq609rsp6zpg7zda75lyxzzk1fabzp4jn88j7xfk84mdgjgzh9h"))))
233 (build-system gnu-build-system)
235 `(("gfortran" ,gfortran)))
237 `(#:configure-flags `("--disable-enable_fma" ;weird :/
239 ,,@(if (string-prefix? "aarch64"
240 (or (%current-target-system)
242 ;; XXX: The qd_test test fails numerical
243 ;; accuracy checks for 'dd_real::exp()' on
244 ;; aarch64 with GCC 5.4 at -O2. Disabling
245 ;; expensive optimizations lets it pass.
246 '("CXXFLAGS=-O3 -fno-expensive-optimizations")
247 '("CXXFLAGS=-O3")))))
248 (home-page "https://www.davidhbailey.com/dhbsoftware/")
249 (synopsis "Double-double and quad-double library")
250 (description "This package supports both a double-double
251 datatype (approx. 32 decimal digits) and a quad-double datatype (approx. 64
252 decimal digits). The computational library is written in C++. Both C++ and
253 Fortran-90 high-level language interfaces are provided to permit one to
254 convert an existing C++ or Fortran-90 program to use the library with only
255 minor changes to the source code. In most cases only a few type statements
256 and (for Fortran-90 programs) read/write statements need to be changed. PSLQ
257 and numerical quadrature programs are included.")
267 (uri (string-append "https://www.ginac.de/CLN/cln-"
270 (base32 "0jlq9l4hphk7qqlgqj9ihjp4m3rwjbhk6q4v00lsbgbri07574pl"))))
271 (build-system gnu-build-system)
273 `(#:configure-flags (list "--disable-static")))
276 (home-page "https://www.ginac.de/CLN/")
277 (synopsis "Library for arbitrary precision computations")
278 (description "CLN is a C++ library for efficient computations with all
279 kinds of numbers in arbitrary precision. It provides a rich set of number
280 classes and elementary, logical and transcendental functions.")
283 (define-public tomsfastmath
285 (name "tomsfastmath")
287 (synopsis "Large integer arithmetic library")
290 (uri (string-append "https://github.com/libtom/tomsfastmath/"
291 "releases/download/v" version "/"
292 "tfm-" version ".tar.xz"))
295 "0f0pmiaskh89sp0q933pafxb914shpaj5ad8sb5rzk1wv8d7mja7"))))
296 (build-system gnu-build-system)
298 `(("libtool" ,libtool)))
300 `(#:make-flags (list "-f" "makefile.shared"
301 (string-append "LIBPATH=" %output "/lib")
302 (string-append "INCPATH=" %output "/include")
303 "GROUP=root" "USER=root"
306 (modify-phases %standard-phases
307 (delete 'configure) ; no configuration
309 (lambda* (#:key make-flags #:allow-other-keys)
311 "stest" "test_standalone"
315 (add-before 'install 'install-nogroup
317 ;; Let permissions inherit from the current process.
318 (substitute* "makefile.shared"
319 (("-g \\$\\(GROUP\\) -o \\$\\(USER\\)") ""))
321 (add-after 'install 'install-doc
322 (lambda* (#:key outputs #:allow-other-keys)
323 (let ((docdir (string-append (assoc-ref outputs "out")
324 "/share/doc/tomsfastmath")))
325 (install-file "doc/tfm.pdf" docdir)
327 (add-after 'install 'install-pc
328 (lambda* (#:key outputs #:allow-other-keys)
329 (let* ((out (assoc-ref outputs "out"))
330 (pc-dir (string-append out "/lib/pkgconfig")))
331 (call-with-output-file "tomsfastmath.pc"
337 Libs: -L~a/lib -ltfm~%"
338 ,synopsis ,version out)))
339 (install-file "tomsfastmath.pc" pc-dir)
341 (home-page "https://www.libtom.net/TomsFastMath/")
342 (description "TomsFastMath is a large integer library written in portable
343 ISO C. It is a port of LibTomMath with optional support for inline assembler
345 (license public-domain)))
347 (define-public libtomcrypt
351 (outputs '("out" "static"))
355 (uri (string-append "https://github.com/libtom/libtomcrypt"
356 "/releases/download/v" version
357 "/crypt-" version ".tar.xz"))
360 "113vfrgapyv72lalhd3nkw7jnks8az0gcb5wqn9hj19nhcxlrbcn"))
361 (modules '((guix build utils)))
364 ;; Patch CVE-2019-17362
365 ;; https://github.com/libtom/libtomcrypt/commit/25c26a3b7a9ad8192ccc923e15cf62bf0108ef94
366 (substitute* "src/pk/asn1/der/utf8/der_decode_utf8_string.c"
367 (("z > 4") "z == 1 || z > 4"))
369 (build-system gnu-build-system)
372 (modify-phases %standard-phases
373 (delete 'configure) ; no configure
374 (add-after 'unpack 'prepare-build
376 ;; We want the shared library by default so force it to be the
377 ;; default makefile target.
378 (delete-file "makefile")
379 (symlink "makefile.shared" "makefile")
380 ;; We link to libtommath, so we need to add it to the pc file
381 (substitute* "libtomcrypt.pc.in"
382 (("-ltomcrypt") "-ltomcrypt -ltommath"))
384 (add-after 'build 'build-static
385 (lambda* (#:key make-flags #:allow-other-keys)
386 (apply invoke "make" "-f" "makefile.unix" make-flags)))
388 (lambda* (#:key test-target make-flags #:allow-other-keys)
389 (apply invoke "make" "-f" "makefile.unix" test-target make-flags)
391 (add-after 'install 'install-static-library
392 (lambda* (#:key outputs #:allow-other-keys)
393 (let ((out (assoc-ref outputs "out"))
394 (static (assoc-ref outputs "static")))
395 (mkdir-p (string-append static "/lib"))
396 (mkdir-p (string-append static "/include"))
397 (rename-file (string-append out "/lib/libtomcrypt.a")
398 (string-append static "/lib/libtomcrypt.a"))
399 (copy-recursively (string-append out "/include")
400 (string-append static "/include"))
404 (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
405 "CFLAGS += -DLTM_DESC -DUSE_LTM"
406 (string-append "EXTRALIBS="
407 (search-input-file %build-inputs
408 "/lib/libtommath.so"))
409 (string-append "CC=" ,(cc-for-target)))))
411 `(("libtool" ,libtool)))
413 `(("libtommath" ,libtommath)))
414 (home-page "https://www.libtom.net/LibTomCrypt/")
415 (synopsis "Cryptographic toolkit")
416 (description "LibTomCrypt is a fairly comprehensive, modular and portable
417 cryptographic toolkit that provides developers with a vast array of well known
418 published block ciphers, one-way hash functions, chaining modes, pseudo-random
419 number generators, public key cryptography and a plethora of other routines.")
420 (properties `((lint-hidden-cve . ("CVE-2019-17362"))))
421 (license unlicense)))
423 (define-public libtommath
427 (outputs '("out" "static"))
431 (uri (string-append "https://github.com/libtom/libtommath/releases/"
432 "download/v" version "/ltm-" version ".tar.xz"))
435 "1c8q1qy88cjhdjlk3g24mra94h34c1ldvkjz0n2988c0yvn5xixp"))))
436 (build-system gnu-build-system)
439 (modify-phases %standard-phases
440 (delete 'configure) ; no configure
441 (add-after 'unpack 'prepare-build
443 ;; We want the shared library by default so force it to be the
444 ;; default makefile target.
445 (delete-file "makefile")
446 (symlink "makefile.shared" "makefile")
448 (add-after 'install 'remove-static-library
449 (lambda* (#:key outputs #:allow-other-keys)
450 (delete-file (string-append (assoc-ref outputs "out")
451 "/lib/libtommath.a"))
454 (lambda* (#:key test-target make-flags #:allow-other-keys)
455 (apply invoke "make" test-target make-flags)
456 (invoke "sh" "test")))
457 (add-after 'install 'install-static-library
458 (lambda* (#:key outputs #:allow-other-keys)
459 (invoke "make" "-f" "makefile.unix" "install"
460 (string-append "PREFIX=" (assoc-ref outputs "static"))
461 (string-append "CC=" (which "gcc"))))))
463 #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
466 `(("libtool" ,libtool)))
467 (home-page "https://www.libtom.net/LibTomMath/")
468 (synopsis "Portable number theoretic multiple-precision integer library")
469 (description "LibTomMath is a portable number theoretic multiple-precision
470 integer library written entirely in C. It's designed to provide an API that is
471 simple to work with that provides fairly efficient routines that build out of
472 the box without configuration.")
473 (license unlicense)))
475 (define-public libtommath-1.1
482 (uri (string-append "https://github.com/libtom/libtommath/releases/"
483 "download/v" version "/ltm-" version ".tar.xz"))
486 "1bbyagqzfdbg37k1n08nsqzdf44z8zsnjjinqbsyj7rxg246qilh"))
487 (patches (search-patches "libtommath-fix-linkage.patch"))))
489 (substitute-keyword-arguments (package-arguments libtommath)
491 `(modify-phases ,phases
492 (add-after 'unpack 'patch-coreutils-call
494 ;; Don't pull in coreutils.
495 (substitute* "makefile_include.mk"
496 (("arch") "uname -m"))
498 ((#:test-target _) "test_standalone")))))
500 (define-public libtommath-1.0
502 (inherit libtommath-1.1)
508 (uri (string-append "https://github.com/libtom/libtommath/releases/"
509 "download/v" version "/ltm-" version ".tar.xz"))
512 "0sbccdwbkfc680id2fi0x067j23biqcjqilwkk7y9339knrjy0s7"))))
514 (substitute-keyword-arguments (package-arguments libtommath-1.1)
516 `(modify-phases ,phases
517 (delete 'install-static-library)))))))