;; -*-theme-d-*-

;; Copyright (C) 2014  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 test240)


  (import (standard-library core)
	  (standard-library complex)
	  (standard-library math)
	  (standard-library console-io))


  (define-simple-proc approx-equal?
      (((cx1 <complex>) (cx2 <complex>)) <boolean> (pure))
    (< (abs (- cx1 cx2)) 1e-12))

  (define main
    (lambda (() <none> nonpure)

      (let ((value (expt (complex -0.5 2.0) (complex 1.5 -1.1))))
	(console-display
	  '(expt (complex -0.5 2.0) (complex 1.5 -1.1)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex -7.624391573800214 20.437942763133584))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (sqrt (complex -0.5 2.0))))
	(console-display
	  '(sqrt (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex 0.883615530875513 1.13171392427787))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (sin (complex -0.5 2.0))))
	(console-display
	  '(sin (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex -1.80369269553218 3.18286944833715))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (cos (complex -0.5 2.0))))
	(console-display
	  '(cos (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex 3.30163733291409 1.73880950447432))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (tan (complex -0.5 2.0))))
	(console-display
	  '(tan (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex -0.0302159873228776 0.979940849961738))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (asin (complex -0.5 2.0))))
	(console-display
	  '(asin (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex -0.221018635622884 1.46571535194729))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (acos (complex -0.5 2.0))))
	(console-display
	  '(acos (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
;;	     (complex 1.79181496241778 -1.46571535194729))
	     (complex 1.7918149624177804 -1.4657153519472903))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      ;; guile-2.0 has a bug in complex atan, which has been corrected in
      ;; guile-2.2 (?)
      (let ((value (atan (complex -0.5 2.0))))
	(console-display
	  '(atan (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex -1.421546861001807 0.500370000052531))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (exp (complex -0.5 2.0))))
	(console-display
	  '(exp (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex -0.252405815308264 0.551516768167581))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (log (complex -0.5 2.0))))
	(console-display
	  '(log (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex 0.723459491468163 1.81577498992176))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (log10 (complex -0.5 2.0))))
	(console-display
	  '(log10 (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex 0.314194465025156 0.788581058500953))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (sinh (complex -0.5 2.0))))
	(console-display
	  '(sinh (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex 0.21685216292079 1.02534738858399))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (cosh (complex -0.5 2.0))))
	(console-display
	  '(cosh (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex -0.469257978229053 -0.473830620416407))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (tanh (complex -0.5 2.0))))
	(console-display
	  '(tanh (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex -1.32128658377119 -0.850878121144938))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (asinh (complex -0.5 2.0))))
	(console-display
	  '(asinh (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex -1.36180090085785 1.29304207023718))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (acosh (complex -0.5 2.0))))
	(console-display
	  '(acosh (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex -1.46571535194729 -1.79181496241778))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (let ((value (atanh (complex -0.5 2.0))))
	(console-display
	  '(atanh (complex -0.5 2.0)))
	(console-display " = ")
	(console-display value)
	(console-display "  ")
	(if (approx-equal?
	     value
	     (complex -0.0964156202029962 1.12655644083482))
	    (console-display "OK")
	    (console-display "FAIL"))
	(console-newline))

      (console-newline))))
