gnu: emacs-svg-icon: Fix grammar.
[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 ;;;
11 ;;; This file is part of GNU Guix.
12 ;;;
13 ;;; GNU Guix is free software; you can redistribute it and/or modify it
14 ;;; under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 3 of the License, or (at
16 ;;; your option) any later version.
17 ;;;
18 ;;; GNU Guix is distributed in the hope that it will be useful, but
19 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;;; GNU General Public License for more details.
22 ;;;
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
25
26 (define-module (gnu packages multiprecision)
27 #:use-module (guix licenses)
28 #:use-module (gnu packages)
29 #:use-module (gnu packages autotools)
30 #:use-module (gnu packages m4)
31 #:use-module (gnu packages gcc)
32 #:use-module (gnu packages texinfo)
33 #:use-module (guix packages)
34 #:use-module (guix download)
35 #:use-module (guix utils)
36 #:use-module (guix build-system gnu))
37
38 (define-public gmp
39 (package
40 (name "gmp")
41 (version "6.2.0")
42 (source (origin
43 (method url-fetch)
44 (uri
45 (string-append "mirror://gnu/gmp/gmp-"
46 version ".tar.xz"))
47 (sha256
48 (base32
49 "09hmg8k63mbfrx1x3yy6y1yzbbq85kw5avbibhcgrg9z3ganr3i5"))
50 (patches (search-patches "gmp-faulty-test.patch"))))
51 (build-system gnu-build-system)
52 (native-inputs `(("m4" ,m4)))
53 (outputs '("out" "debug"))
54 (arguments
55 `(#:parallel-tests? #f ; mpz/reuse fails otherwise
56 #:configure-flags
57 '(;; Build a "fat binary", with routines for several
58 ;; sub-architectures.
59 "--enable-fat"
60 "--enable-cxx"
61 ,@(cond ((target-mingw?)
62 ;; Static and shared cannot be built in one go:
63 ;; they produce different headers. We need shared.
64 `("--disable-static"
65 "--enable-shared"))
66 (else '())))
67 ;; Remove after core-updates merge.
68 ;; Workaround for gcc-7 transition breakage, -system and cross-build,
69 ;; Note: See <http://bugs.gnu.org/22186> for why not 'CPATH'.
70 ;; Note: See <http://bugs.gnu.org/30756> for why not 'C_INCLUDE_PATH' & co.
71 ,@(if (target-mingw?)
72 `(#:phases
73 (modify-phases %standard-phases
74 (add-before 'configure 'setenv
75 (lambda _
76 (let ((gcc (assoc-ref %build-inputs "cross-gcc"))
77 (libc (assoc-ref %build-inputs "cross-libc")))
78 (setenv "CROSS_CPLUS_INCLUDE_PATH"
79 (string-append gcc "/include/c++"
80 ":" gcc "/include"
81 ":" libc "/include"))
82 (format #t "environment variable `CROSS_CPLUS_INCLUDE_PATH' set to `~a'\n"
83 (getenv "CROSS_CPLUS_INCLUDE_PATH"))
84 #t)))))
85 '())))
86 (synopsis "Multiple-precision arithmetic library")
87 (description
88 "The @acronym{GMP, the GNU Multiple Precision Arithmetic} library performs
89 arbitrary-precision arithmetic on signed integers, rational numbers and floating
90 point numbers. The precision is only limited by the available memory.
91 The library is highly optimized, with a design focus on execution speed.
92 It is aimed at use in, for example, cryptography and computational algebra.")
93 (license lgpl3+)
94 (home-page "https://gmplib.org/")))
95
96 (define-public gmp-6.0
97 ;; We keep this one around to bootstrap GCC, to work around a compilation
98 ;; issue on ARM. See
99 ;; <https://gmplib.org/list-archives/gmp-bugs/2015-December/003848.html>.
100 (package
101 (inherit gmp)
102 (version "6.0.0a")
103 (source (origin
104 (method url-fetch)
105 (uri (string-append "mirror://gnu/gmp/gmp-"
106 version ".tar.xz"))
107 (sha256
108 (base32
109 "0r5pp27cy7ch3dg5v0rsny8bib1zfvrza6027g2mp5f6v8pd6mli"))
110 (patches (search-patches "gmp-arm-asm-nothumb.patch"
111 "gmp-faulty-test.patch"))))))
112
113 (define-public mpfr
114 (package
115 (name "mpfr")
116 (version "4.0.2")
117 (source (origin
118 (method url-fetch)
119 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
120 ".tar.xz"))
121 (sha256 (base32
122 "12m3amcavhpqygc499s3fzqlb8f2j2rr7fkqsm10xbjfc04fffqx"))))
123 (build-system gnu-build-system)
124 (outputs '("out" "debug"))
125 (propagated-inputs `(("gmp" ,gmp))) ; <mpfr.h> refers to <gmp.h>
126 (synopsis "C library for arbitrary-precision floating-point arithmetic")
127 (description
128 "GNU@tie{}@acronym{MPFR, Multiple Precision Floating-Point Reliably} is a C
129 library for performing multiple-precision, floating-point computations with
130 correct rounding.")
131 (license lgpl3+)
132 (home-page "https://www.mpfr.org/")))
133
134 (define-public mpc
135 (package
136 (name "mpc")
137 (version "1.1.0")
138 (source (origin
139 (method url-fetch)
140 (uri (string-append
141 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
142 (sha256
143 (base32
144 "0biwnhjm3rx3hc0rfpvyniky4lpzsvdcwhmcn7f0h4iw2hwcb1b9"))))
145 (build-system gnu-build-system)
146 (outputs '("out" "debug"))
147 (propagated-inputs `(("gmp" ,gmp) ; <mpc.h> refers to both
148 ("mpfr" ,mpfr)))
149 (synopsis "C library for arbitrary-precision complex arithmetic")
150 (description
151 "GNU@tie{}@acronym{MPC, Multiple Precision Complex library} is a C library
152 for performing arithmetic on complex numbers. It supports arbitrarily high
153 precision and correctly rounds the results.")
154 (license lgpl3+)
155 (home-page "http://www.multiprecision.org/mpc/")))
156
157 (define-public mpfi
158 (package
159 (name "mpfi")
160 (version "1.5.4")
161 (source
162 (origin
163 (method url-fetch)
164 (uri (string-append "https://gforge.inria.fr/frs/download.php"
165 "/latestfile/181/mpfi-" version ".tgz"))
166 (sha256
167 (base32 "0mismr1ll3wp788dq2n22s5irm0dziy75byyfdwz22kjbmckhf9v"))))
168 (build-system gnu-build-system)
169 (arguments
170 `(#:tests? #f ;tests are broken in this release
171 #:configure-flags '("--enable-static=no")))
172 (native-inputs
173 `(("automake" ,automake)
174 ("autoreconf" ,autoconf)
175 ("libtool" ,libtool)
176 ("texinfo" ,texinfo)))
177 (propagated-inputs
178 `(("gmp" ,gmp) ; <mpfi.h> refers to both
179 ("mpfr" ,mpfr)))
180 (home-page "https://gforge.inria.fr/projects/mpfi/")
181 (synopsis "C library for arbitrary-precision interval arithmetic")
182 (description
183 "@acronym{MPFI, Multiple Precision Floating-point Interval} is a portable C
184 library for arbitrary-precision interval arithmetic, with intervals represented
185 using MPFR reliable floating-point numbers. It's based on the @acronym{GMP, GNU
186 Multiple Precision Arithmetic} and GNU@tie{}@acronym{MPFR, Multiple Precision
187 Floating-Point Reliably} libraries.
188
189 The purpose of arbitrary-precision interval arithmetic is to get results that
190 are both guaranteed, thanks to interval computation, and accurate, thanks to
191 multiple-precision arithmetic.")
192 (license lgpl2.1+)))
193
194 (define-public irram
195 (package
196 (name "irram")
197 (version "2013_01")
198 (source
199 (origin
200 (method url-fetch)
201 (uri (string-append "http://irram.uni-trier.de/irram-files/iRRAM_"
202 version ".tar.bz2"))
203 (sha256
204 (base32 "1cdmvb4hsa161rfdjqyhd9sb3fcr43p3a6nsj7cb4kn9f94qmjpj"))))
205 (build-system gnu-build-system)
206 (propagated-inputs `(("gmp" ,gmp) ; <mpfi.h> refers to both
207 ("mpfr" ,mpfr)))
208 (arguments
209 `(#:parallel-build? #f))
210 (synopsis "C++ package for real arithmetic based on the Real-RAM concept")
211 (description
212 "@dfn{iRRAM} is a C++ package for error-free real arithmetic based on
213 the concept of a Real-RAM. Its capabilities range from ordinary arithmetic
214 over trigonometric functions to linear algebra and differential
215 equations. A program using iRRAM is coded in ordinary C++, but may use a
216 special class that behaves like real numbers without any
217 error. Additionally, iRRAM uses the concept of multi-valued functions.")
218 (license lgpl2.0+)
219 (home-page "http://irram.uni-trier.de/")))
220
221 (define-public qd
222 (package
223 (name "qd")
224 (version "2.3.22")
225 (source
226 (origin
227 (method url-fetch)
228 (uri (string-append "https://crd-legacy.lbl.gov/~dhbailey/mpdist/qd-"
229 version ".tar.gz"))
230 (sha256
231 (base32 "1lq609rsp6zpg7zda75lyxzzk1fabzp4jn88j7xfk84mdgjgzh9h"))))
232 (build-system gnu-build-system)
233 (native-inputs
234 `(("gfortran" ,gfortran)))
235 (arguments
236 `(#:configure-flags `("--disable-enable_fma" ;weird :/
237 "--enable-shared"
238 ,,@(if (string-prefix? "aarch64"
239 (or (%current-target-system)
240 (%current-system)))
241 ;; XXX: The qd_test test fails numerical
242 ;; accuracy checks for 'dd_real::exp()' on
243 ;; aarch64 with GCC 5.4 at -O2. Disabling
244 ;; expensive optimizations lets it pass.
245 '("CXXFLAGS=-O3 -fno-expensive-optimizations")
246 '("CXXFLAGS=-O3")))))
247 (home-page "https://www.davidhbailey.com/dhbsoftware/")
248 (synopsis "Double-double and quad-double library")
249 (description "This package supports both a double-double
250 datatype (approx. 32 decimal digits) and a quad-double datatype (approx. 64
251 decimal digits). The computational library is written in C++. Both C++ and
252 Fortran-90 high-level language interfaces are provided to permit one to
253 convert an existing C++ or Fortran-90 program to use the library with only
254 minor changes to the source code. In most cases only a few type statements
255 and (for Fortran-90 programs) read/write statements need to be changed. PSLQ
256 and numerical quadrature programs are included.")
257 (license bsd-3)))
258
259 (define-public tomsfastmath
260 (package
261 (name "tomsfastmath")
262 (version "0.13.1")
263 (synopsis "Large integer arithmetic library")
264 (source (origin
265 (method url-fetch)
266 (uri (string-append "https://github.com/libtom/tomsfastmath/"
267 "releases/download/v" version "/"
268 "tfm-" version ".tar.xz"))
269 (sha256
270 (base32
271 "0f0pmiaskh89sp0q933pafxb914shpaj5ad8sb5rzk1wv8d7mja7"))))
272 (build-system gnu-build-system)
273 (native-inputs
274 `(("libtool" ,libtool)))
275 (arguments
276 `(#:make-flags (list "-f" "makefile.shared"
277 (string-append "LIBPATH=" %output "/lib")
278 (string-append "INCPATH=" %output "/include")
279 "GROUP=root" "USER=root"
280 "CC=gcc")
281 #:phases
282 (modify-phases %standard-phases
283 (delete 'configure) ; no configuration
284 (replace 'check
285 (lambda* (#:key make-flags #:allow-other-keys)
286 (apply invoke "make"
287 "stest" "test_standalone"
288 make-flags)
289 (invoke "./stest")
290 (invoke "./test")))
291 (add-before 'install 'install-nogroup
292 (lambda _
293 ;; Let permissions inherit from the current process.
294 (substitute* "makefile.shared"
295 (("-g \\$\\(GROUP\\) -o \\$\\(USER\\)") ""))
296 #t))
297 (add-after 'install 'install-doc
298 (lambda* (#:key outputs #:allow-other-keys)
299 (let ((docdir (string-append (assoc-ref outputs "out")
300 "/share/doc/tomsfastmath")))
301 (install-file "doc/tfm.pdf" docdir)
302 #t)))
303 (add-after 'install 'install-pc
304 (lambda* (#:key outputs #:allow-other-keys)
305 (let* ((out (assoc-ref outputs "out"))
306 (pc-dir (string-append out "/lib/pkgconfig")))
307 (call-with-output-file "tomsfastmath.pc"
308 (lambda (port)
309 (format port "~
310 Name: TomsFastMath
311 Description: ~a
312 Version: ~a
313 Libs: -L~a/lib -ltfm~%"
314 ,synopsis ,version out)))
315 (install-file "tomsfastmath.pc" pc-dir)
316 #t))))))
317 (home-page "https://www.libtom.net/TomsFastMath/")
318 (description "TomsFastMath is a large integer library written in portable
319 ISO C. It is a port of LibTomMath with optional support for inline assembler
320 multiplies.")
321 (license public-domain)))
322
323 (define-public libtomcrypt
324 (package
325 (name "libtomcrypt")
326 (version "1.18.2")
327 (outputs '("out" "static"))
328 (source
329 (origin
330 (method url-fetch)
331 (uri (string-append "https://github.com/libtom/libtomcrypt"
332 "/releases/download/v" version
333 "/crypt-" version ".tar.xz"))
334 (sha256
335 (base32
336 "113vfrgapyv72lalhd3nkw7jnks8az0gcb5wqn9hj19nhcxlrbcn"))
337 (modules '((guix build utils)))
338 (snippet
339 '(begin
340 ;; Patch CVE-2019-17362
341 ;; https://github.com/libtom/libtomcrypt/commit/25c26a3b7a9ad8192ccc923e15cf62bf0108ef94
342 (substitute* "src/pk/asn1/der/utf8/der_decode_utf8_string.c"
343 (("z > 4") "z == 1 || z > 4"))
344 #t))))
345 (build-system gnu-build-system)
346 (arguments
347 `(#:phases
348 (modify-phases %standard-phases
349 (delete 'configure) ; no configure
350 (add-after 'unpack 'prepare-build
351 (lambda _
352 ;; We want the shared library by default so force it to be the
353 ;; default makefile target.
354 (delete-file "makefile")
355 (symlink "makefile.shared" "makefile")
356 ;; We link to libtommath, so we need to add it to the pc file
357 (substitute* "libtomcrypt.pc.in"
358 (("-ltomcrypt") "-ltomcrypt -ltommath"))
359 #t))
360 (add-after 'build 'build-static
361 (lambda* (#:key make-flags #:allow-other-keys)
362 (apply invoke "make" "-f" "makefile.unix" make-flags)))
363 (replace 'check
364 (lambda* (#:key test-target make-flags #:allow-other-keys)
365 (apply invoke "make" "-f" "makefile.unix" test-target make-flags)
366 (invoke "./test")))
367 (add-after 'install 'install-static-library
368 (lambda* (#:key outputs #:allow-other-keys)
369 (let ((out (assoc-ref outputs "out"))
370 (static (assoc-ref outputs "static")))
371 (mkdir-p (string-append static "/lib"))
372 (mkdir-p (string-append static "/include"))
373 (rename-file (string-append out "/lib/libtomcrypt.a")
374 (string-append static "/lib/libtomcrypt.a"))
375 (copy-recursively (string-append out "/include")
376 (string-append static "/include"))
377 #t))))
378 #:test-target "test"
379 #:make-flags
380 (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
381 "CFLAGS += -DLTM_DESC -DUSE_LTM"
382 (string-append "EXTRALIBS=" (assoc-ref %build-inputs "libtommath")
383 "/lib/libtommath.so")
384 (string-append "CC=" ,(cc-for-target)))))
385 (native-inputs
386 `(("libtool" ,libtool)))
387 (inputs
388 `(("libtommath" ,libtommath)))
389 (home-page "https://www.libtom.net/LibTomCrypt/")
390 (synopsis "Cryptographic toolkit")
391 (description "LibTomCrypt is a fairly comprehensive, modular and portable
392 cryptographic toolkit that provides developers with a vast array of well known
393 published block ciphers, one-way hash functions, chaining modes, pseudo-random
394 number generators, public key cryptography and a plethora of other routines.")
395 (properties `((lint-hidden-cve . ("CVE-2019-17362"))))
396 (license unlicense)))
397
398 (define-public libtommath
399 (package
400 (name "libtommath")
401 (version "1.2.0")
402 (outputs '("out" "static"))
403 (source
404 (origin
405 (method url-fetch)
406 (uri (string-append "https://github.com/libtom/libtommath/releases/"
407 "download/v" version "/ltm-" version ".tar.xz"))
408 (sha256
409 (base32
410 "1c8q1qy88cjhdjlk3g24mra94h34c1ldvkjz0n2988c0yvn5xixp"))))
411 (build-system gnu-build-system)
412 (arguments
413 '(#:phases
414 (modify-phases %standard-phases
415 (delete 'configure) ; no configure
416 (add-after 'unpack 'prepare-build
417 (lambda _
418 ;; We want the shared library by default so force it to be the
419 ;; default makefile target.
420 (delete-file "makefile")
421 (symlink "makefile.shared" "makefile")
422 #t))
423 (add-after 'install 'remove-static-library
424 (lambda* (#:key outputs #:allow-other-keys)
425 (delete-file (string-append (assoc-ref outputs "out")
426 "/lib/libtommath.a"))
427 #t))
428 (replace 'check
429 (lambda* (#:key test-target make-flags #:allow-other-keys)
430 (apply invoke "make" test-target make-flags)
431 (invoke "sh" "test")))
432 (add-after 'install 'install-static-library
433 (lambda* (#:key outputs #:allow-other-keys)
434 (invoke "make" "-f" "makefile.unix" "install"
435 (string-append "PREFIX=" (assoc-ref outputs "static"))
436 (string-append "CC=" (which "gcc"))))))
437 #:test-target "test"
438 #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out"))
439 "CC=gcc")))
440 (native-inputs
441 `(("libtool" ,libtool)))
442 (home-page "https://www.libtom.net/LibTomMath/")
443 (synopsis "Portable number theoretic multiple-precision integer library")
444 (description "LibTomMath is a portable number theoretic multiple-precision
445 integer library written entirely in C. It's designed to provide an API that is
446 simple to work with that provides fairly efficient routines that build out of
447 the box without configuration.")
448 (license unlicense)))
449
450 (define-public libtommath-1.1
451 (package
452 (inherit libtommath)
453 (version "1.1.0")
454 (source
455 (origin
456 (method url-fetch)
457 (uri (string-append "https://github.com/libtom/libtommath/releases/"
458 "download/v" version "/ltm-" version ".tar.xz"))
459 (sha256
460 (base32
461 "1bbyagqzfdbg37k1n08nsqzdf44z8zsnjjinqbsyj7rxg246qilh"))
462 (patches (search-patches "libtommath-fix-linkage.patch"))))
463 (arguments
464 (substitute-keyword-arguments (package-arguments libtommath)
465 ((#:phases phases)
466 `(modify-phases ,phases
467 (add-after 'unpack 'patch-coreutils-call
468 (lambda _
469 ;; Don't pull in coreutils.
470 (substitute* "makefile_include.mk"
471 (("arch") "uname -m"))
472 #t))))
473 ((#:test-target _) "test_standalone")))))
474
475 (define-public libtommath-1.0
476 (package
477 (inherit libtommath-1.1)
478 (version "1.0.1")
479 (outputs '("out"))
480 (source
481 (origin
482 (method url-fetch)
483 (uri (string-append "https://github.com/libtom/libtommath/releases/"
484 "download/v" version "/ltm-" version ".tar.xz"))
485 (sha256
486 (base32
487 "0sbccdwbkfc680id2fi0x067j23biqcjqilwkk7y9339knrjy0s7"))))
488 (arguments
489 (substitute-keyword-arguments (package-arguments libtommath-1.1)
490 ((#:phases phases)
491 `(modify-phases ,phases
492 (delete 'install-static-library)))))))