1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#
# 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.3 2005/11/17 23:55:21 hobbs Exp $
#------------------------------------------------------------------------------
#
if {[cequal [info procs Test] {}]} {
source [file join [file dirname [info script]] testlib.tcl]
}
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
if {$tcl_version > 8.4} {
Test fmath-1.21-8.5 {math error tests} {
pow 10000 100000
} 0 Inf
} else {
Test fmath-1.21 {math error tests} {
pow 10000 100000
} 1 {floating-point value too large to represent}
}
# cleanup
::tcltest::cleanupTests
return
|