#
# fmath.test
#
# Tests for the following floating point math compatibility procs:
#   acos, asin, atan,  cos,  sin,  tan,   cosh, sinh, tanh, 
#   exp,  log,  log10, sqrt, fabs, floor, ceil, fmod, pow.
#---------------------------------------------------------------------------
# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies.  Karl Lehenbauer and
# Mark Diekhans make no representations about the suitability of this
# software for any purpose.  It is provided "as is" without express or
# implied warranty.
#------------------------------------------------------------------------------
# $Id: fmath.test,v 1.1.1.1 1999/06/28 20:35:25 damon Exp $
#------------------------------------------------------------------------------
#

if [cequal [info procs Test] {}] {source testlib.tcl}
eval $SAVED_UNKNOWN


set F_E	        2.71828
set F_LN10	2.30258
set F_PI	3.14159265358979
set F_PI_180    0.0174533
set F_PI_4      0.785398
set F_PI_2      1.5708
set F_SQRT2	1.41421

# Check that a floating point value is reasonably within range.  If so, return
# 1, if not, return a message.

proc fchecknum {got expect} {
    global ModuleName

    set lowExpect [expr {$expect * 0.9999}]
    set hiExpect  [expr {$expect * 1.0001}]

    if {($got < $lowExpect) || ($got > $hiExpect)} {
      return [format {wanted something close to %s, got %s} $expect $got]
    }
    return 1
}

Test fmath-1.1 {acos tests} {
    fchecknum [acos 0] 1.5708
} 0 1
Test fmath-1.2 {acos tests} {
    fchecknum [acos $F_PI_180-.5] 2.07436
} 0 1
Test fmath-1.3 {acos tests} {
    fchecknum [acos $F_PI_4] 0.667457
} 0 1
Test fmath-1.4 {acos tests} {
    fchecknum [acos .25*.25] 1.50826
} 0 1


Test fmath-1.5 {asin tests} {
    fchecknum [asin 1.3-.4] 1.11977
} 0 1

Test fmath-1.6 {atan tests} {
    fchecknum [atan 1.0-.25] 0.643501
} 0 1

Test fmath-1.7 {sin tests} {
    fchecknum [sin 1.0-.1] 0.783327
} 0 1

Test fmath-1.8 {tan tests} {
    fchecknum [tan .01*10] 0.100335
} 0 1

Test fmath-1.9 {cosh tests} {
    fchecknum [cosh 1.2] 1.81066
} 0 1

Test fmath-1.10 {sinh tests} {
    fchecknum [sinh .25+10] 14141.3
} 0 1

Test fmath-1.11 {tanh tests} {
    fchecknum [tanh 1.5/2] 0.635149
} 0 1

Test fmath-1.12 {exp tests} {
    fchecknum [exp 1.4] 4.0552
} 0 1

Test fmath-1.13 {log tests} {
    fchecknum [log (110%3)*8] 2.77259
} 0 1

Test fmath-1.14 {log10 tests} {
    fchecknum [log10 0.5*10] 0.69897
} 0 1

Test fmath-1.15 {sqrt tests} {
    fchecknum [sqrt 1.2*2] 1.54919
} 0 1

Test fmath-1.16 {fabs tests} {
    fchecknum [fabs 1.2-10.5] 9.3
} 0 1

Test fmath-1.17 {floor tests} {
    fchecknum [floor 1.2*10.3] 12
} 0 1

Test fmath-1.18 {ceil tests} {
    fchecknum [ceil 1.5*2.6] 4
} 0 1

Test fmath-1.19 {fmod tests} {
    fchecknum [fmod 1.2*3 1.0/.25] 3.6
} 0 1

Test fmath-1.20 {pow tests} {
    fchecknum [pow 13.6*.78 1.2] 17.0122
} 0 1

Test fmath-1.21 {math error tests} {
    pow 10000 100000
} 1 {floating-point value too large to represent}

rename unknown {}




