;; -*-theme-d-*-

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

  (import (standard-library core)
	  (standard-library math)
	  (standard-library console-io)
	  (tests numerical-test-env))

  (define-simple-proc main (() <none> nonpure)
    (report-test (sqrt 4) 2)
    (report-test (sqrt 5) 2.23606797749979)
    (report-test (sqrt -1) (complex 0 1))
    (report-test (sqrt (rational 3 5)) 0.7745966692414834)
    (report-test (sqrt (rational 9 4)) (rational 3 2))
    (report-test (sqrt (rational -9 4)) (complex 0.0 1.5))
    (report-test (sqrt 1.5) 1.224744871391589)
    (report-test (sqrt -1.5) (complex 0.0 1.224744871391589))
    (report-test (sqrt (complex 1.5 2.5))
		 (complex 1.4858458781822983 0.8412716408576514))
    (console-newline)

    (report-test (sin 0) 0)
    (report-test (sin 1) 0.8414709848078965)
    (report-test (sin (rational 0 1)) 0)
    (report-test (sin (rational 3 2)) 0.9974949866040544)
    (report-test (sin (complex -1.5 -0.2))
		 (complex -1.0175114747314913 -0.014241945414718512))
    (console-newline)

    (report-test (cos 0) 1)
    (report-test (cos 1) 0.5403023058681398)
    (report-test (cos (rational 0 1)) 1)
    (report-test (cos (rational -4 5)) 0.6967067093471654)
    (report-test (cos 5.6) 0.7755658785102496)
    (report-test (cos (complex 3.1 -1.6))
		 (complex -2.5752353517513407 0.0987776891493616))
    (console-newline)

    (report-test (tan 0) 0)
    (report-test (tan 1) 1.5574077246549023)
    (report-test (tan (rational 0 1)) 0)
    (report-test (tan (rational -8 5)) 34.232532735557314)
    (report-test (tan 5.62) -0.7812215204782494)
    (report-test (tan (complex -1.7 1.6))
		 (complex 0.022574605405217284 1.0818063977492944))
    (console-newline)

    (report-test (asin 0) 0)
    (report-test (asin 1) 1.5707963267948966)
    (report-test (asin -1) -1.5707963267948966)
    (report-test (asin 10) (complex 1.5707963267948966 -2.993222846126381))
    (report-test (asin (rational 0 1)) 0)
    (report-test (asin (rational -2 3)) -0.7297276562269663)
    ;; The following result is taken from Octave.
    ;; Guile-2.2.2 returns the conjugate.
    (report-test (asin (rational -3 2))
		 (complex -1.570796326794897 0.962423650119207))
    (report-test (asin 0.7) 0.775397496610753)
    (report-test (asin 2.5) (complex 1.5707963267948966 -1.5667992369724109))
    (report-test (asin (complex -1.0 1.0))
		 (complex -0.6662394324925153 1.0612750619050355))
    (console-newline)

    (report-test (acos 0) 1.5707963267948966)
    (report-test (acos 1) 0)
    (report-test (acos -1) 3.141592653589793)
    (report-test (acos 10) (complex 0.0 2.993222846126381))
    (report-test (acos (rational 1 1)) 0)
    (report-test (acos (rational 1 2)) 1.0471975511965979)
    ;; The following result is taken from Octave.
    ;; Guile-2.2.2 returns the conjugate.
    (report-test (acos (rational -3 2))
		 (complex 3.141592653589793 -0.962423650119207))
    (report-test (acos 0.6) 0.9272952180016123)
    (report-test (acos 2.5) (complex 0.0 1.5667992369724109))
    (report-test (acos (complex -1.0 2.0))
		 (complex 1.9978749131873725 -1.5285709194809975))
    (console-newline)

    (report-test (atan 0) 0)
    (report-test (atan 1) 0.7853981633974483)
    (report-test (atan (rational 0 1)) 0)
    (report-test (atan (rational 2 3)) 0.5880026035475675)
    (report-test (atan 10.5) 1.4758446204521403)
    (report-test (atan (complex 0.0 2.0))
		 (complex 1.5707963267948966 0.5493061443340549))
    (console-newline)

    (report-test (exp 0) 1)
    (report-test (exp 1) 2.718281828459045)
    (report-test (exp (rational 0 1)) 1)
    (report-test (exp (rational -1 2)) 0.6065306597126334)
    (report-test (exp 0.4) 1.4918246976412703)
    (report-test (exp (complex 3.0 -1.9))
		 (complex -6.493444532118245 -19.00694535166129))
    (console-newline)

    (console-display "(log 0): ")
    (guard-without-result
     (exc (else (console-display "exception ")
		(console-display exc)
		(console-newline)))
     (console-display (log 0))
     (console-newline))
    (report-test (log 1) 0)
    (report-test (log 2) 0.6931471805599453)
    (report-test (log -2) (complex 0.6931471805599453 3.141592653589793))
    (console-display "(log (rational 0 1)): ")
    (guard-without-result
     (exc (else (console-display "exception ")
		(console-display exc)
		(console-newline)))
     (console-display (log (rational 0 1)))
     (console-newline))
    (report-test (log (rational 1 1)) 0)
    (report-test (log (rational 3 2)) 0.4054651081081644)
    (report-test (log (rational -9 4))
		 (complex 0.8109302162163288 3.141592653589793))
    (report-test (log 0.0) (neg-inf))
    (report-test (log 0.5) -0.6931471805599453)
    (report-test (log -2.5) (complex 0.9162907318741551 3.141592653589793))
    (report-test (log (complex -1.5 4.0))
		 (complex 1.45208254001425 1.9295669970654687))
    (console-newline)

    (console-display "(log10 0): ")
    (guard-without-result
     (exc (else (console-display "exception ")
		(console-display exc)
		(console-newline)))
     (console-display (log10 0))
     (console-newline))
    (report-test (log10 1) 0)
    (report-test (log10 2) 0.3010299956639812)
    (report-test (log10 -2) (complex 0.3010299956639812 1.3643763538418412))
    (console-display "(log10 (rational 0 1)): ")
    (guard-without-result
     (exc (else (console-display "exception ")
		(console-display exc)
		(console-newline)))
     (console-display (log10 (rational 0 1)))
     (console-newline))
    (report-test (log10 (rational 1 1)) 0)
    (report-test (log10 (rational 3 2)) 0.17609125905568124)
    (report-test (log10 (rational -9 4))
		 (complex 0.3521825181113625 1.3643763538418412))
    (report-test (log10 0.0) (neg-inf))
    (report-test (log10 0.5) -0.3010299956639812)
    (report-test (log10 -2.5) (complex 0.3979400086720376 1.3643763538418412))
    (report-test (log10 (complex -1.5 4.0))
		 (complex 0.6306314343962467 0.8380002992881612))
    (report-test (log10 1000) 3)
    (report-test (log10 (rational 1 1000)) -3)
    (report-test (log10 (make <rational> 2 20)) -1)
    (console-newline)

    (report-test (sinh 0) 0)
    (report-test (sinh 1) 1.1752011936438014)
    (report-test (sinh (rational 0 1)) 0)
    (report-test (sinh (rational 2 3)) 0.7171584610110419)
    (report-test (sinh 6.5) 332.5700648025844)
    (report-test (sinh (complex 2.1 -2.2))
		 (complex -2.3668671862005364 -3.350662294578905))
    (console-newline)

    (report-test (cosh 0) 1)
    (report-test (cosh 1) 1.5430806348152437)
    (report-test (cosh (rational 0 1)) 1)
    (report-test (cosh (rational 4 5)) 1.3374349463048447)
    (report-test (cosh -2.3) 5.037220649268761)
    (report-test (cosh (complex 1.2 0.5))
		 (complex 1.5889997514735912 0.7236743233207111))
    (console-newline)

    (report-test (tanh 0) 0)
    (report-test (tanh 1) 0.7615941559557649)
    (report-test (tanh (rational 0 1)) 0)
    (report-test (tanh (rational -6 7)) -0.6947826703147378)
    (report-test (tanh 0.1) 0.09966799462495582)
    (report-test (tanh (complex 0.2 1.2))
		 (complex 1.1951639075532274 1.9653917058120067))
    (console-newline)

    (report-test (asinh 0) 0)
    (report-test (asinh 1) 0.881373587019543)
    (report-test (asinh (rational 0 1)) 0)
    (report-test (asinh (rational -1 2)) -0.48121182505960347)
    (report-test (asinh 1.9) 1.3979983651114345)
    (report-test (asinh (complex 1.0 -3.0))
		 (complex 1.8241987021938828 -1.2330952175293441))
    (console-newline)

    (report-test (acosh 1) 0)
    (report-test (acosh 2) 1.3169578969248166)
    (report-test (acosh 0) (complex 0.0  1.5707963267948966))
    (report-test (acosh (rational 1 1)) 0)
    (report-test (acosh (rational 10 9)) 0.46714530810326216)
    (report-test (acosh (rational -10 9))
		 (complex -0.4671453081032618 3.141592653589793))
    (report-test (acosh 2.3) 1.4750447812414251)
    (report-test (acosh 0.0) (complex 0.0 1.5707963267948966))
    (report-test (acosh (complex 1.0 -1.3))
		 (complex 1.2209548994261807 -0.9971645921863111))
    (console-newline)

    (report-test (atanh 0) 0)
    (report-test (atanh 1) (inf))
    (report-test (atanh -1) (neg-inf))
    ;; The following result for atanh is computed with Octave.
    ;; guile-2.0 and guile-2.2.2 return a value from a different branch.
    (report-test (atanh 2) (complex 0.549306144334055 -1.570796326794897))
    (report-test (atanh (rational 0 1)) 0)
    (report-test (atanh (rational -1 7)) -0.14384103622589045)
    (report-test (atanh (rational -11 3))
		 (complex -0.27980789396771133 1.5707963267948966))
    (report-test (atanh 0.33) 0.3428282544153939) 
    ;; The following result for atanh is computed with Octave.
    ;; guile-2.0 and guile-2.2.2 return a value from a different branch.
    (report-test (atanh 2.5) (complex 0.423648930193602 -1.570796326794897))
    (report-test (atanh (complex 0.9 -0.7))
		 (complex 0.5260335385675519 -0.8909448300088216))
    (console-newline)

    (report-test (atan2 0 5) 0)
    (report-test (atan2 1 1) 0.7853981633974483)
    (report-test (atan2 0 (rational 3 2)) 0)
    (report-test (atan2 1 (rational 3 4)) 0.9272952180016122)
    (report-test (atan2 1 1.0) 0.7853981633974483)
    (report-test (atan2 (rational 0 1) 5) 0)
    (report-test (atan2 (rational 1 6) 2) 0.08314123188844122)
    (report-test (atan2 (rational 0 1) (rational 5 2)) 0)
    (report-test (atan2 (rational 1 6) (rational -3 2)) 3.0309354324158977)
    (report-test (atan2 (rational 1 7) 0.6) 0.23374318086890142)
    (report-test (atan2 1.0 1) 0.7853981633974483)
    (report-test (atan2 1.0 (rational 5 8)) 1.0121970114513341)
    (report-test (atan2 -0.8 -0.7) -2.289626326416521))) 
