home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / tclx7_31.z / tclx7_31 / tcldev / tclX7.3a-p1 / tests / fmath.test < prev    next >
Encoding:
Text File  |  1994-01-23  |  3.1 KB  |  131 lines

  1. #
  2. # fmath.test
  3. #
  4. # Tests for the following floating point math compatibility procs:
  5. #   acos, asin, atan,  cos,  sin,  tan,   cosh, sinh, tanh, 
  6. #   exp,  log,  log10, sqrt, fabs, floor, ceil, fmod, pow.
  7. #---------------------------------------------------------------------------
  8. # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
  9. #
  10. # Permission to use, copy, modify, and distribute this software and its
  11. # documentation for any purpose and without fee is hereby granted, provided
  12. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  13. # Mark Diekhans make no representations about the suitability of this
  14. # software for any purpose.  It is provided "as is" without express or
  15. # implied warranty.
  16. #------------------------------------------------------------------------------
  17. # $Id: fmath.test,v 3.0 1993/11/19 06:57:23 markd Rel $
  18. #------------------------------------------------------------------------------
  19. #
  20.  
  21. if {[info procs test] != "test"} then {source testlib.tcl}
  22. eval $SAVED_UNKNOWN
  23.  
  24. set F_E            2.71828
  25. set F_LN10    2.30258
  26. set F_PI    3.14159265358979
  27. set F_PI_180    0.0174533
  28. set F_PI_4      0.785398
  29. set F_PI_2      1.5708
  30. set F_SQRT2    1.41421
  31.  
  32. # Check that a floating point value is reasonably within range.  If so, return
  33. # 1, if not, return a message.
  34.  
  35. proc fchecknum {got expect} {
  36.     global ModuleName
  37.  
  38.     set lowExpect [expr {$expect * 0.9999}]
  39.     set hiExpect  [expr {$expect * 1.0001}]
  40.  
  41.     if {($got < $lowExpect) || ($got > $hiExpect)} {
  42.       return [format {wanted something close to %s, got %s} $expect $got]
  43.     }
  44.     return 1
  45. }
  46.  
  47. Test fmath-1.1 {acos tests} {
  48.     fchecknum [acos 0] 1.5708
  49. } 0 1
  50. Test fmath-1.2 {acos tests} {
  51.     fchecknum [acos $F_PI_180-.5] 2.07436
  52. } 0 1
  53. Test fmath-1.3 {acos tests} {
  54.     fchecknum [acos $F_PI_4] 0.667457
  55. } 0 1
  56. Test fmath-1.4 {acos tests} {
  57.     fchecknum [acos .25*.25] 1.50826
  58. } 0 1
  59.  
  60.  
  61. Test fmath-1.5 {asin tests} {
  62.     fchecknum [asin 1.3-.4] 1.11977
  63. } 0 1
  64.  
  65. Test fmath-1.6 {atan tests} {
  66.     fchecknum [atan 1.0-.25] 0.643501
  67. } 0 1
  68.  
  69. Test fmath-1.7 {sin tests} {
  70.     fchecknum [sin 1.0-.1] 0.783327
  71. } 0 1
  72.  
  73. Test fmath-1.8 {tan tests} {
  74.     fchecknum [tan .01*10] 0.100335
  75. } 0 1
  76.  
  77. Test fmath-1.9 {cosh tests} {
  78.     fchecknum [cosh 1.2] 1.81066
  79. } 0 1
  80.  
  81. Test fmath-1.10 {sinh tests} {
  82.     fchecknum [sinh .25+10] 14141.3
  83. } 0 1
  84.  
  85. Test fmath-1.11 {tanh tests} {
  86.     fchecknum [tanh 1.5/2] 0.635149
  87. } 0 1
  88.  
  89. Test fmath-1.12 {exp tests} {
  90.     fchecknum [exp 1.4] 4.0552
  91. } 0 1
  92.  
  93. Test fmath-1.13 {log tests} {
  94.     fchecknum [log (110%3)*8] 2.77259
  95. } 0 1
  96.  
  97. Test fmath-1.14 {log10 tests} {
  98.     fchecknum [log10 0.5*10] 0.69897
  99. } 0 1
  100.  
  101. Test fmath-1.15 {sqrt tests} {
  102.     fchecknum [sqrt 1.2*2] 1.54919
  103. } 0 1
  104.  
  105. Test fmath-1.16 {fabs tests} {
  106.     fchecknum [fabs 1.2-10.5] 9.3
  107. } 0 1
  108.  
  109. Test fmath-1.17 {floor tests} {
  110.     fchecknum [floor 1.2*10.3] 12
  111. } 0 1
  112.  
  113. Test fmath-1.18 {ceil tests} {
  114.     fchecknum [ceil 1.5*2.6] 4
  115. } 0 1
  116.  
  117. Test fmath-1.19 {fmod tests} {
  118.     fchecknum [fmod 1.2*3 1.0/.25] 3.6
  119. } 0 1
  120.  
  121. Test fmath-1.20 {pow tests} {
  122.     fchecknum [pow 13.6*.78 1.2] 17.0122
  123. } 0 1
  124.  
  125. Test fmath-1.21 {math error tests} {
  126.     pow 10000 100000
  127. } 1 {floating-point value too large to represent}
  128.  
  129. rename unknown {}
  130.  
  131.