;; -*-theme-d-*-

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

;; Expected results: translation and running OK


(define-proper-program (tests test659)


  (import (standard-library core)
	  (standard-library basic-math)
	  (standard-library real-math)
	  (standard-library console-io))


  (define-simple-proc approx-equal?
      (((r1 <real>) (r2 <real>)) <boolean> (pure))
    (< (r-abs (- r1 r2)) 1e-12))

  (define main
    (lambda (() <none> nonpure)
      (let ((value (r-expt 1.5 2.5)))
	(console-display
	 '(r-expt 1.5 2.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 2.7556759606310752)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-sqrt 1.5)))
	(console-display
	 '(r-sqrt 1.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 1.22474487139159)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (i-sqrt 4)))
	(console-display
	 '(i-sqrt 4))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (equal? value 2)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (i-sqrt 5)))
	(console-display
	 '(i-sqrt 5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     (match-type value
	       ((i <integer>) (integer->real i))
	       ((r <real>) r))
	       2.23606797749979)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-sin 1.5)))
	(console-display
	 '(r-sin 1.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 0.997494986604054)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-cos 1.5)))
	(console-display
	 '(r-cos 1.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 0.0707372016677029)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-tan 1.5)))
	(console-display
	 '(r-tan 1.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 14.1014199471717)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-asin 0.5)))
	(console-display
	 '(r-asin 0.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 0.523598775598299)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-acos 0.5)))
	(console-display
	 '(r-acos 0.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 1.0471975511966)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-atan 0.5)))
	(console-display
	 '(r-atan 0.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 0.463647609000806)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-exp 2.5)))
	(console-display
	 '(r-exp 2.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 12.1824939607035)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-log 2.5)))
	(console-display
	 '(r-log 2.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 0.916290731874155)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-log10 2.5)))
	(console-display
	 '(r-log10 2.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 0.397940008672038)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-sinh 2.5)))
	(console-display
	 '(r-sinh 2.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 6.05020448103979)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-cosh 2.5)))
	(console-display
	 '(r-cosh 2.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 6.13228947966369)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-tanh 2.5)))
	(console-display
	 '(r-tanh 2.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 0.98661429815143)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-asinh 0.6)))
	(console-display
	 '(r-asinh 0.6))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 0.568824898732248)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-acosh 1.5)))
	(console-display
	 '(r-acosh 1.5))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 0.962423650119207)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-atanh 0.6)))
	(console-display
	 '(r-atanh 0.6))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 0.693147180559945)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (r-atan2 2.0 1.0)))
	(console-display
	 '(r-atan2 2.0 1.0))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal? value 1.1071487177940904)
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (console-newline))))
