multiprecision.scm 20 KB

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