Merge branch 'master' into core-updates-frozen
[jackhill/guix/guix.git] / gnu / packages / multiprecision.scm
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>
11 ;;;
12 ;;; This file is part of GNU Guix.
13 ;;;
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.
18 ;;;
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.
23 ;;;
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/>.
26
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))
38
39 (define-public gmp
40 (package
41 (name "gmp")
42 (version "6.2.1")
43 (source (origin
44 (method url-fetch)
45 (uri
46 (string-append "mirror://gnu/gmp/gmp-"
47 version ".tar.xz"))
48 (sha256
49 (base32
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"))
55 (arguments
56 `(#:parallel-tests? #f ; mpz/reuse fails otherwise
57 #:configure-flags
58 '(;; Build a "fat binary", with routines for several
59 ;; sub-architectures.
60 "--enable-fat"
61 "--enable-cxx"
62 ,@(cond ((target-mingw?)
63 ;; Static and shared cannot be built in one go:
64 ;; they produce different headers. We need shared.
65 `("--disable-static"
66 "--enable-shared"))
67 (else '())))
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.
72 ,@(if (target-mingw?)
73 `(#:phases
74 (modify-phases %standard-phases
75 (add-before 'configure 'setenv
76 (lambda _
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++"
81 ":" gcc "/include"
82 ":" libc "/include"))
83 (format #t "environment variable `CROSS_CPLUS_INCLUDE_PATH' set to `~a'\n"
84 (getenv "CROSS_CPLUS_INCLUDE_PATH"))
85 #t)))))
86 '())))
87 (synopsis "Multiple-precision arithmetic library")
88 (description
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.")
94 (license lgpl3+)
95 (home-page "https://gmplib.org/")))
96
97 (define-public gmp-6.0
98 ;; We keep this one around to bootstrap GCC, to work around a compilation
99 ;; issue on ARM. See
100 ;; <https://gmplib.org/list-archives/gmp-bugs/2015-December/003848.html>.
101 (package
102 (inherit gmp)
103 (version "6.0.0a")
104 (source (origin
105 (method url-fetch)
106 (uri (string-append "mirror://gnu/gmp/gmp-"
107 version ".tar.xz"))
108 (sha256
109 (base32
110 "0r5pp27cy7ch3dg5v0rsny8bib1zfvrza6027g2mp5f6v8pd6mli"))
111 (patches (search-patches "gmp-arm-asm-nothumb.patch"
112 "gmp-faulty-test.patch"))))))
113
114 (define-public mpfr
115 (package
116 (name "mpfr")
117 (version "4.1.0")
118 (source (origin
119 (method url-fetch)
120 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
121 ".tar.xz"))
122 (sha256 (base32
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")
128 (description
129 "GNU@tie{}@acronym{MPFR, Multiple Precision Floating-Point Reliably} is a C
130 library for performing multiple-precision, floating-point computations with
131 correct rounding.")
132 (license lgpl3+)
133 (home-page "https://www.mpfr.org/")))
134
135 (define-public mpc
136 (package
137 (name "mpc")
138 (version "1.2.1")
139 (source (origin
140 (method url-fetch)
141 (uri (string-append
142 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
143 (sha256
144 (base32
145 "0n846hqfqvmsmim7qdlms0qr86f1hck19p12nq3g3z2x74n3sl0p"))))
146 (build-system gnu-build-system)
147 (outputs '("out" "debug"))
148 (propagated-inputs `(("gmp" ,gmp) ; <mpc.h> refers to both
149 ("mpfr" ,mpfr)))
150 (synopsis "C library for arbitrary-precision complex arithmetic")
151 (description
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.")
155 (license lgpl3+)
156 (home-page "http://www.multiprecision.org/mpc/")))
157
158 (define-public mpfi
159 (package
160 (name "mpfi")
161 (version "1.5.4")
162 (source
163 (origin
164 (method url-fetch)
165 (uri (string-append "https://gforge.inria.fr/frs/download.php"
166 "/latestfile/181/mpfi-" version ".tgz"))
167 (sha256
168 (base32 "0mismr1ll3wp788dq2n22s5irm0dziy75byyfdwz22kjbmckhf9v"))))
169 (build-system gnu-build-system)
170 (arguments
171 `(#:tests? #f ;tests are broken in this release
172 #:configure-flags '("--enable-static=no")))
173 (native-inputs
174 `(("automake" ,automake)
175 ("autoreconf" ,autoconf)
176 ("libtool" ,libtool)
177 ("texinfo" ,texinfo)))
178 (propagated-inputs
179 `(("gmp" ,gmp) ; <mpfi.h> refers to both
180 ("mpfr" ,mpfr)))
181 (home-page "https://gforge.inria.fr/projects/mpfi/")
182 (synopsis "C library for arbitrary-precision interval arithmetic")
183 (description
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.
189
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.")
193 (license lgpl2.1+)))
194
195 (define-public irram
196 (package
197 (name "irram")
198 (version "2013_01")
199 (source
200 (origin
201 (method url-fetch)
202 (uri (string-append "http://irram.uni-trier.de/irram-files/iRRAM_"
203 version ".tar.bz2"))
204 (sha256
205 (base32 "1cdmvb4hsa161rfdjqyhd9sb3fcr43p3a6nsj7cb4kn9f94qmjpj"))))
206 (build-system gnu-build-system)
207 (propagated-inputs `(("gmp" ,gmp) ; <mpfi.h> refers to both
208 ("mpfr" ,mpfr)))
209 (arguments
210 `(#:parallel-build? #f))
211 (synopsis "C++ package for real arithmetic based on the Real-RAM concept")
212 (description
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.")
219 (license lgpl2.0+)
220 (home-page "http://irram.uni-trier.de/")))
221
222 (define-public qd
223 (package
224 (name "qd")
225 (version "2.3.22")
226 (source
227 (origin
228 (method url-fetch)
229 (uri (string-append "https://crd-legacy.lbl.gov/~dhbailey/mpdist/qd-"
230 version ".tar.gz"))
231 (sha256
232 (base32 "1lq609rsp6zpg7zda75lyxzzk1fabzp4jn88j7xfk84mdgjgzh9h"))))
233 (build-system gnu-build-system)
234 (native-inputs
235 `(("gfortran" ,gfortran)))
236 (arguments
237 `(#:configure-flags `("--disable-enable_fma" ;weird :/
238 "--enable-shared"
239 ,,@(if (string-prefix? "aarch64"
240 (or (%current-target-system)
241 (%current-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.")
258 (license bsd-3)))
259
260 (define-public cln
261 (package
262 (name "cln")
263 (version "1.3.6")
264 (source
265 (origin
266 (method url-fetch)
267 (uri (string-append "https://www.ginac.de/CLN/cln-"
268 version ".tar.bz2"))
269 (sha256
270 (base32 "0jlq9l4hphk7qqlgqj9ihjp4m3rwjbhk6q4v00lsbgbri07574pl"))))
271 (build-system gnu-build-system)
272 (arguments
273 `(#:configure-flags (list "--disable-static")))
274 (inputs
275 `(("gmp" ,gmp)))
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.")
281 (license gpl2+)))
282
283 (define-public tomsfastmath
284 (package
285 (name "tomsfastmath")
286 (version "0.13.1")
287 (synopsis "Large integer arithmetic library")
288 (source (origin
289 (method url-fetch)
290 (uri (string-append "https://github.com/libtom/tomsfastmath/"
291 "releases/download/v" version "/"
292 "tfm-" version ".tar.xz"))
293 (sha256
294 (base32
295 "0f0pmiaskh89sp0q933pafxb914shpaj5ad8sb5rzk1wv8d7mja7"))))
296 (build-system gnu-build-system)
297 (native-inputs
298 `(("libtool" ,libtool)))
299 (arguments
300 `(#:make-flags (list "-f" "makefile.shared"
301 (string-append "LIBPATH=" %output "/lib")
302 (string-append "INCPATH=" %output "/include")
303 "GROUP=root" "USER=root"
304 "CC=gcc")
305 #:phases
306 (modify-phases %standard-phases
307 (delete 'configure) ; no configuration
308 (replace 'check
309 (lambda* (#:key make-flags #:allow-other-keys)
310 (apply invoke "make"
311 "stest" "test_standalone"
312 make-flags)
313 (invoke "./stest")
314 (invoke "./test")))
315 (add-before 'install 'install-nogroup
316 (lambda _
317 ;; Let permissions inherit from the current process.
318 (substitute* "makefile.shared"
319 (("-g \\$\\(GROUP\\) -o \\$\\(USER\\)") ""))
320 #t))
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)
326 #t)))
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"
332 (lambda (port)
333 (format port "~
334 Name: TomsFastMath
335 Description: ~a
336 Version: ~a
337 Libs: -L~a/lib -ltfm~%"
338 ,synopsis ,version out)))
339 (install-file "tomsfastmath.pc" pc-dir)
340 #t))))))
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
344 multiplies.")
345 (license public-domain)))
346
347 (define-public libtomcrypt
348 (package
349 (name "libtomcrypt")
350 (version "1.18.2")
351 (outputs '("out" "static"))
352 (source
353 (origin
354 (method url-fetch)
355 (uri (string-append "https://github.com/libtom/libtomcrypt"
356 "/releases/download/v" version
357 "/crypt-" version ".tar.xz"))
358 (sha256
359 (base32
360 "113vfrgapyv72lalhd3nkw7jnks8az0gcb5wqn9hj19nhcxlrbcn"))
361 (modules '((guix build utils)))
362 (snippet
363 '(begin
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"))
368 #t))))
369 (build-system gnu-build-system)
370 (arguments
371 `(#:phases
372 (modify-phases %standard-phases
373 (delete 'configure) ; no configure
374 (add-after 'unpack 'prepare-build
375 (lambda _
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"))
383 #t))
384 (add-after 'build 'build-static
385 (lambda* (#:key make-flags #:allow-other-keys)
386 (apply invoke "make" "-f" "makefile.unix" make-flags)))
387 (replace 'check
388 (lambda* (#:key test-target make-flags #:allow-other-keys)
389 (apply invoke "make" "-f" "makefile.unix" test-target make-flags)
390 (invoke "./test")))
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"))
401 #t))))
402 #:test-target "test"
403 #:make-flags
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)))))
410 (native-inputs
411 `(("libtool" ,libtool)))
412 (inputs
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)))
422
423 (define-public libtommath
424 (package
425 (name "libtommath")
426 (version "1.2.0")
427 (outputs '("out" "static"))
428 (source
429 (origin
430 (method url-fetch)
431 (uri (string-append "https://github.com/libtom/libtommath/releases/"
432 "download/v" version "/ltm-" version ".tar.xz"))
433 (sha256
434 (base32
435 "1c8q1qy88cjhdjlk3g24mra94h34c1ldvkjz0n2988c0yvn5xixp"))))
436 (build-system gnu-build-system)
437 (arguments
438 '(#:phases
439 (modify-phases %standard-phases
440 (delete 'configure) ; no configure
441 (add-after 'unpack 'prepare-build
442 (lambda _
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")
447 #t))
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"))
452 #t))
453 (replace 'check
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"))))))
462 #:test-target "test"
463 #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
464 "CC=gcc")))
465 (native-inputs
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)))
474
475 (define-public libtommath-1.1
476 (package
477 (inherit libtommath)
478 (version "1.1.0")
479 (source
480 (origin
481 (method url-fetch)
482 (uri (string-append "https://github.com/libtom/libtommath/releases/"
483 "download/v" version "/ltm-" version ".tar.xz"))
484 (sha256
485 (base32
486 "1bbyagqzfdbg37k1n08nsqzdf44z8zsnjjinqbsyj7rxg246qilh"))
487 (patches (search-patches "libtommath-fix-linkage.patch"))))
488 (arguments
489 (substitute-keyword-arguments (package-arguments libtommath)
490 ((#:phases phases)
491 `(modify-phases ,phases
492 (add-after 'unpack 'patch-coreutils-call
493 (lambda _
494 ;; Don't pull in coreutils.
495 (substitute* "makefile_include.mk"
496 (("arch") "uname -m"))
497 #t))))
498 ((#:test-target _) "test_standalone")))))
499
500 (define-public libtommath-1.0
501 (package
502 (inherit libtommath-1.1)
503 (version "1.0.1")
504 (outputs '("out"))
505 (source
506 (origin
507 (method url-fetch)
508 (uri (string-append "https://github.com/libtom/libtommath/releases/"
509 "download/v" version "/ltm-" version ".tar.xz"))
510 (sha256
511 (base32
512 "0sbccdwbkfc680id2fi0x067j23biqcjqilwkk7y9339knrjy0s7"))))
513 (arguments
514 (substitute-keyword-arguments (package-arguments libtommath-1.1)
515 ((#:phases phases)
516 `(modify-phases ,phases
517 (delete 'install-static-library)))))))