inexact.scm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ;;; R7RS compatibility libraries
  2. ;;; Copyright (C) 2019 Free Software Foundation, Inc.
  3. ;;;
  4. ;;; This library is free software: you can redistribute it and/or modify
  5. ;;; it under the terms of the GNU Lesser General Public License as
  6. ;;; published by the Free Software Foundation, either version 3 of the
  7. ;;; License, or (at your option) any later version.
  8. ;;;
  9. ;;; This library is distributed in the hope that it will be useful, but
  10. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;;; Lesser General Public License for more details.
  13. ;;;
  14. ;;; You should have received a copy of the GNU Lesser General Public
  15. ;;; License along with this program. If not, see
  16. ;;; <http://www.gnu.org/licenses/>.
  17. ;;; Based on code from https://gitlab.com/akku/akku-scm, written
  18. ;;; 2018-2019 by Göran Weinholt <goran@weinholt.se>, as well as
  19. ;;; https://github.com/okuoku/yuni, written 2014-2018 by OKUMURA Yuki
  20. ;;; <mjt@cltn.org>. This code was originally released under the
  21. ;;; following terms:
  22. ;;;
  23. ;;; To the extent possible under law, the author(s) have dedicated
  24. ;;; all copyright and related and neighboring rights to this
  25. ;;; software to the public domain worldwide. This software is
  26. ;;; distributed without any warranty.
  27. ;;;
  28. ;;; See <http://creativecommons.org/publicdomain/zero/1.0/>, for a
  29. ;;; copy of the CC0 Public Domain Dedication.
  30. (define-module (scheme inexact)
  31. #:re-export ((exact->inexact . inexact)
  32. (inexact->exact . exact)
  33. acos asin atan cos exp sin sqrt tan)
  34. #:export ((r7:finite? . finite?)
  35. (r7:infinite? . infinite?)
  36. (r7:nan? . nan?)
  37. (r7:log . log)))
  38. (define (r7:finite? z)
  39. (if (complex? z)
  40. (and (finite? (real-part z))
  41. (finite? (imag-part z)))
  42. (finite? z)))
  43. (define (r7:infinite? z)
  44. (if (complex? z)
  45. (or (inf? (real-part z))
  46. (inf? (imag-part z)))
  47. (inf? z)))
  48. (define (r7:nan? z)
  49. (if (complex? z)
  50. (or (nan? (real-part z))
  51. (nan? (imag-part z)))
  52. (nan? z)))
  53. (define r7:log
  54. (case-lambda
  55. ((x) (log x))
  56. ((x y) (/ (log x) (log y)))))