;; -*-theme-d-*-

;; Copyright (C) 2018 Tommi Höynälänmaa
;; Distributed under GNU Lesser General Public License version 3,
;; see file doc/LGPL-3.


(define-body (standard-library posix-math)

  ;; We trust libthemedsupport so we can use unchecked-prim-proc here.

  (define r-y0
    (unchecked-prim-proc r-y0 (<real>) <real> pure))

  (define r-y1
    (unchecked-prim-proc r-y1 (<real>) <real> pure))

  (define r-yn
    (unchecked-prim-proc r-yn (<integer> <real>) <real> pure))

  (define r-j0
    (unchecked-prim-proc r-j0 (<real>) <real> pure))

  (define r-j1
    (unchecked-prim-proc r-j1 (<real>) <real> pure))

  (define r-jn
    (unchecked-prim-proc r-jn (<integer> <real>) <real> pure))

  (define-simple-method y0 (((r <real-number>)) <real> pure)
    (raise-simple 'y0:dispatch-error))

  (add-method y0 r-y0)

  (define-simple-method y0 (((rat <rational>)) <real> pure)
    (r-y0 (rational->real rat)))

  (define-simple-method y0 (((i <integer>)) <real> pure)
    (r-y0 (integer->real i)))

  (define-simple-method y1 (((r <real-number>)) <real> pure)
    (raise-simple 'y1:dispatch-error))

  (add-method y1 r-y1)

  (define-simple-method y1 (((rat <rational>)) <real> pure)
    (r-y1 (rational->real rat)))

  (define-simple-method y1 (((i <integer>)) <real> pure)
    (r-y1 (integer->real i)))

  (define-simple-method yn (((i <integer>) (r <real-number>)) <real> pure)
    (raise-simple 'yn:dispatch-error))

  (add-method yn r-yn)

  (define-simple-method yn (((i <integer>) (rat <rational>)) <real> pure)
    (r-yn i (rational->real rat)))

  (define-simple-method yn (((i1 <integer>) (i2 <integer>)) <real> pure)
    (r-yn i1 (integer->real i2)))

  (define-simple-method j0 (((r <real-number>)) <real> pure)
    (raise-simple 'j0:dispatch-error))

  (add-method j0 r-j0)

  (define-simple-method j0 (((rat <rational>)) <real> pure)
    (r-j0 (rational->real rat)))

  (define-simple-method j0 (((i <integer>)) <real> pure)
    (r-j0 (integer->real i)))

  (define-simple-method j1 (((r <real-number>)) <real> pure)
    (raise-simple 'j1:dispatch-error))

  (add-method j1 r-j1)

  (define-simple-method j1 (((rat <rational>)) <real> pure)
    (r-j1 (rational->real rat)))

  (define-simple-method j1 (((i <integer>)) <real> pure)
    (r-j1 (integer->real i)))

  (define-simple-method jn (((i <integer>) (r <real-number>)) <real> pure)
    (raise-simple 'jn:dispatch-error))

  (add-method jn r-jn)

  (define-simple-method jn (((i <integer>) (rat <rational>)) <real> pure)
    (r-jn i (rational->real rat)))

  (define-simple-method jn (((i1 <integer>) (i2 <integer>)) <real> pure)
    (r-jn i1 (integer->real i2))))
