/
niceSOFT
/
tcl
Обзор
Документация
Войти
/
niceSOFT
/
tcl
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
tests/mathfunc.test
379 строк
14 KB
dgp
Duplicate test name
18 июн 2026, 20:56
18 июн 2026, 20:56
2b40d76
Код
Авторство
О чём код?
# Commands covered: tcl::mathfunc::* # # This file contains a collection of tests for one or more of the Tcl # built-in commands. Sourcing this file into Tcl runs the tests and # generates output for errors. No output means no errors were found. # # Copyright © 2026 Donal K. Fellows. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. if {"::tcltest" ni [namespace children]} { package require tcltest 2.5 namespace import -force ::tcltest::* } ::tcltest::loadTestedCommands # Define a matching mode that compares only the first 15 significant figures. # Allows for 1ULP bugs in C runtimes; we aren't fixing those... customMatch approximate {apply {{expected actual} { string equal [format %.15g $expected] [format %.15g $actual] }}} # acosh tests test mathfunc-acosh.1 {acosh: no args} -body { tcl::mathfunc::acosh } -returnCodes error -result {not enough arguments for math function "acosh"} test mathfunc-acosh.2 {acosh: too many args} -body { tcl::mathfunc::acosh a b } -returnCodes error -result {too many arguments for math function "acosh"} test mathfunc-acosh.3 {acosh: out of bounds} -body { tcl::mathfunc::acosh -1 } -returnCodes error -result {domain error: argument not in valid range} test mathfunc-acosh.4 {acosh: valid result} { tcl::mathfunc::acosh 1 } 0.0 # asinh tests test mathfunc-asinh.1 {asinh: no args} -body { tcl::mathfunc::asinh } -returnCodes error -result {not enough arguments for math function "asinh"} test mathfunc-asinh.2 {asinh: too many args} -body { tcl::mathfunc::asinh a b } -returnCodes error -result {too many arguments for math function "asinh"} test mathfunc-asinh.3 {asinh: valid result} -body { tcl::mathfunc::asinh 1 } -match approximate -result 0.881373587019543 # atanh tests test mathfunc-atanh.1 {atanh: no args} -body { tcl::mathfunc::atanh } -returnCodes error -result {not enough arguments for math function "atanh"} test mathfunc-atanh.2 {atanh: too many args} -body { tcl::mathfunc::atanh a b } -returnCodes error -result {too many arguments for math function "atanh"} test mathfunc-atanh.3 {atanh: out of bounds} -body { tcl::mathfunc::atanh -2 } -returnCodes error -result {domain error: argument not in valid range} test mathfunc-atanh.4 {atanh: valid result} -body { tcl::mathfunc::atanh 0.5 } -match approximate -result 0.549306144334055 # cbrt tests test mathfunc-cbrt.1 {cbrt: no args} -body { tcl::mathfunc::cbrt } -returnCodes error -result {not enough arguments for math function "cbrt"} test mathfunc-cbrt.2 {cbrt: too many args} -body { tcl::mathfunc::cbrt a b } -returnCodes error -result {too many arguments for math function "cbrt"} test mathfunc-cbrt.3 {cbrt: valid result} -body { tcl::mathfunc::cbrt -27 } -match approximate -result -3.000000000000000 # copysign tests test mathfunc-copysign.1 {copysign: no args} -body { tcl::mathfunc::copysign } -returnCodes error -result {not enough arguments for math function "copysign"} test mathfunc-copysign.2 {copysign: too many args} -body { tcl::mathfunc::copysign a b c } -returnCodes error -result {too many arguments for math function "copysign"} test mathfunc-copysign.3 {copysign: valid result} { tcl::mathfunc::copysign 0 -1 } -0.0 # dim tests test mathfunc-dim.1 {dim: no args} -body { tcl::mathfunc::dim } -returnCodes error -result {not enough arguments for math function "dim"} test mathfunc-dim.2 {dim: too many args} -body { tcl::mathfunc::dim a b c } -returnCodes error -result {too many arguments for math function "dim"} test mathfunc-dim.3 {dim: valid result} { tcl::mathfunc::dim 2 1 } 1.0 test mathfunc-dim.4 {dim: valid result} { tcl::mathfunc::dim 1 2 } 0.0 # divmod tests test mathfunc-divmod.1 {divmod: no args} -body { divmod } -returnCodes error -result {wrong # args: should be "divmod dividend divisor"} test mathfunc-divmod.2 {divmod: too many args} -body { divmod a b c } -returnCodes error -result {wrong # args: should be "divmod dividend divisor"} test mathfunc-divmod.3 {divmod: invalid args} -body { divmod 1.5 0.5 } -returnCodes error -result {dividend must be an integer} test mathfunc-divmod.4 {divmod: invalid args} -body { divmod 15 0.5 } -returnCodes error -result {divisor must be an integer} test mathfunc-divmod.5 {divmod: invalid args} -body { divmod 15 0 } -returnCodes error -result {divide by zero} test mathfunc-divmod.6 {divmod: invalid args} -body { divmod 15151515151515151515151515151515151515151515151515151515 0 } -returnCodes error -result {divide by zero} test mathfunc-divmod.7 {divmod: valid args: integer} { divmod 15 4 } {3 3} test mathfunc-divmod.8 {divmod: valid args: integer} { divmod 155 -4 } {-39 -1} test mathfunc-divmod.9 {divmod: valid args: bignum} { divmod 15151515151515151515151515151515151515151515151515151515 \ 44444444444444444444444444444444444444444444444 } {340909090 40404040404040404040404040404040404040555555555} test mathfunc-divmod.10 {divmod: valid args: bignum} { divmod 15151515151515151515151515151515151515151515151515151515 \ -4444444444444444444444444444444444444444444444 } {-3409090910 -4040404040404040404040404040404040402525252525} # erf tests test mathfunc-erf.1 {erf: no args} -body { tcl::mathfunc::erf } -returnCodes error -result {not enough arguments for math function "erf"} test mathfunc-erf.2 {erf: too many args} -body { tcl::mathfunc::erf a b } -returnCodes error -result {too many arguments for math function "erf"} test mathfunc-erf.3 {erf: valid result} -body { tcl::mathfunc::erf 1 } -match approximate -result 0.842700792949715 # erfc tests test mathfunc-erfc.1 {erfc: no args} -body { tcl::mathfunc::erfc } -returnCodes error -result {not enough arguments for math function "erfc"} test mathfunc-erfc.2 {erfc: too many args} -body { tcl::mathfunc::erfc a b } -returnCodes error -result {too many arguments for math function "erfc"} test mathfunc-erfc.3 {erfc: valid result} -body { tcl::mathfunc::erfc 1 } -match approximate -result 0.157299207050285 # exp2 tests test mathfunc-exp2.1 {exp2: no args} -body { tcl::mathfunc::exp2 } -returnCodes error -result {not enough arguments for math function "exp2"} test mathfunc-exp2.2 {exp2: too many args} -body { tcl::mathfunc::exp2 a b } -returnCodes error -result {too many arguments for math function "exp2"} test mathfunc-exp2.3 {exp2: valid result} { tcl::mathfunc::exp2 1 } 2.0 # expm1 tests test mathfunc-expm1.1 {expm1: no args} -body { tcl::mathfunc::expm1 } -returnCodes error -result {not enough arguments for math function "expm1"} test mathfunc-expm1.2 {expm1: too many args} -body { tcl::mathfunc::expm1 a b } -returnCodes error -result {too many arguments for math function "expm1"} test mathfunc-expm1.3 {expm1: valid result} -body { tcl::mathfunc::expm1 1 } -match approximate -result 1.718281828459045 # fma tests test mathfunc-fma.1 {fma: no args} -body { tcl::mathfunc::fma } -returnCodes error -result {not enough arguments for math function "fma"} test mathfunc-fma.2 {fma: too many args} -body { tcl::mathfunc::fma a b c d } -returnCodes error -result {too many arguments for math function "fma"} test mathfunc-fma.3 {fma: valid result} { tcl::mathfunc::fma 2 3 5 } 11.0 # frexp tests test mathfunc-frexp.1 {frexp: no args} -body { frexp } -returnCodes error -result {wrong # args: should be "frexp floatValue"} test mathfunc-frexp.2 {frexp: too many args} -body { frexp a b } -returnCodes error -result {wrong # args: should be "frexp floatValue"} test mathfunc-frexp.3 {frexp: valid result} { frexp 1.5 } {0.75 1} # gamma tests test mathfunc-gamma.1 {gamma: no args} -body { tcl::mathfunc::gamma } -returnCodes error -result {not enough arguments for math function "gamma"} test mathfunc-gamma.2 {gamma: too many args} -body { tcl::mathfunc::gamma a b } -returnCodes error -result {too many arguments for math function "gamma"} test mathfunc-gamma.3 {gamma: valid result} -body { tcl::mathfunc::gamma 4.5 } -match approximate -result 11.631728396567450 # ldexp tests test mathfunc-ldexp.1 {ldexp: no args} -body { tcl::mathfunc::ldexp } -returnCodes error -result {not enough arguments for math function "ldexp"} test mathfunc-ldexp.2 {ldexp: too many args} -body { tcl::mathfunc::ldexp a b c } -returnCodes error -result {too many arguments for math function "ldexp"} test mathfunc-ldexp.3 {ldexp: valid result} { tcl::mathfunc::ldexp 0.75 1 } 1.5 # lgamma tests test mathfunc-lgamma.1 {lgamma: no args} -body { tcl::mathfunc::lgamma } -returnCodes error -result {not enough arguments for math function "lgamma"} test mathfunc-lgamma.2 {lgamma: too many args} -body { tcl::mathfunc::lgamma a b } -returnCodes error -result {too many arguments for math function "lgamma"} test mathfunc-lgamma.3 {lgamma: valid result} -body { tcl::mathfunc::lgamma 4.5 } -match approximate -result 2.453736570842442 # log1p tests test mathfunc-log1p.1 {log1p: no args} -body { tcl::mathfunc::log1p } -returnCodes error -result {not enough arguments for math function "log1p"} test mathfunc-log1p.2 {log1p: too many args} -body { tcl::mathfunc::log1p a b } -returnCodes error -result {too many arguments for math function "log1p"} test mathfunc-log1p.3 {log1p: invalid arg} -body { tcl::mathfunc::log1p -4 } -returnCodes error -result {domain error: argument not in valid range} test mathfunc-log1p.4 {log1p: valid result} -body { tcl::mathfunc::log1p 4.5 } -match approximate -result 1.704748092238425 # log2 tests test mathfunc-log2.1 {log2: no args} -body { tcl::mathfunc::log2 } -returnCodes error -result {not enough arguments for math function "log2"} test mathfunc-log2.2 {log2: too many args} -body { tcl::mathfunc::log2 a b } -returnCodes error -result {too many arguments for math function "log2"} test mathfunc-log2.3 {log2: invalid arg} -body { tcl::mathfunc::log2 -4 } -returnCodes error -result {domain error: argument not in valid range} test mathfunc-log2.4 {log2: valid result} { tcl::mathfunc::log2 8 } 3.0 # logb tests test mathfunc-logb.1 {logb: no args} -body { tcl::mathfunc::logb } -returnCodes error -result {not enough arguments for math function "logb"} test mathfunc-logb.2 {logb: too many args} -body { tcl::mathfunc::logb a b } -returnCodes error -result {too many arguments for math function "logb"} test mathfunc-logb.3 {logb: valid result} { tcl::mathfunc::logb 9 } 3.0 test mathfunc-logb.4 {logb: valid with negative} { tcl::mathfunc::logb -4 } 2.0 # modf tests test mathfunc-modf.1 {modf: no args} -body { modf } -returnCodes error -result {wrong # args: should be "modf floatValue"} test mathfunc-modf.2 {modf: no args} -body { modf a b } -returnCodes error -result {wrong # args: should be "modf floatValue"} test mathfunc-modf.3 {modf: valid result} { modf 1.5 } {1.0 0.5} # nextafter tests test mathfunc-nextafter.1 {nextafter: no args} -body { tcl::mathfunc::nextafter } -returnCodes error -result {not enough arguments for math function "nextafter"} test mathfunc-nextafter.2 {nextafter: too many args} -body { tcl::mathfunc::nextafter a b c } -returnCodes error -result {too many arguments for math function "nextafter"} test mathfunc-nextafter.3 {nextafter: valid result} { tcl::mathfunc::nextafter 123 inf } 123.00000000000001 # remainder tests test mathfunc-remainder.1 {remainder: no args} -body { tcl::mathfunc::remainder } -returnCodes error -result {not enough arguments for math function "remainder"} test mathfunc-remainder.2 {remainder: too many args} -body { tcl::mathfunc::remainder a b c } -returnCodes error -result {too many arguments for math function "remainder"} test mathfunc-remainder.3 {remainder: valid result} { tcl::mathfunc::remainder 12.5 1.5 } 0.5 # remquo tests test mathfunc-remquo.1 {remquo: no args} -body { remquo } -returnCodes error -result {wrong # args: should be "remquo dividend divisor"} test mathfunc-remquo.2 {remquo: too many args} -body { remquo a b c } -returnCodes error -result {wrong # args: should be "remquo dividend divisor"} test mathfunc-remquo.3 {remquo: valid result} { llength [remquo 12.5 1.5] } 2 test mathfunc-remquo.4 {remquo: valid result} { # Number of valid bits in second value is not defined lindex [remquo 12.5 1.5] 0 } 0.5 test mathfunc-remquo.5 {remquo: valid result} { # Number of valid bits in second value is not defined lindex [remquo 12.5 -1.5] 0 } 0.5 # signbit tests test mathfunc-signbit.1 {signbit: no args} -body { tcl::mathfunc::signbit } -returnCodes error -result {not enough arguments for math function "signbit"} test mathfunc-signbit.2 {signbit: too many args} -body { tcl::mathfunc::signbit a b } -returnCodes error -result {too many arguments for math function "signbit"} test mathfunc-signbit.3 {signbit: valid result: float} { tcl::mathfunc::signbit 123.456 } 0 test mathfunc-signbit.4 {signbit: valid result: float} { tcl::mathfunc::signbit -0.0 } 1 test mathfunc-signbit.5 {signbit: valid result: float} { tcl::mathfunc::signbit -inf } 1 test mathfunc-signbit.6 {signbit: valid result: int} { tcl::mathfunc::signbit 0 } 0 test mathfunc-signbit.7 {signbit: valid result: int} { tcl::mathfunc::signbit 123 } 0 test mathfunc-signbit.8 {signbit: valid result: int} { tcl::mathfunc::signbit -12 } 1 test mathfunc-signbit.9 {signbit: valid result: bignum} { tcl::mathfunc::signbit 1231231231231231231231231231231231231231231231231223 } 0 test mathfunc-signbit.10 {signbit: valid result: nan} -body { # Not defined which value is returned for this tcl::mathfunc::signbit NaN } -match glob -result {[01]} # trunc tests test mathfunc-trunc.1 {trunc: no args} -body { tcl::mathfunc::trunc } -returnCodes error -result {not enough arguments for math function "trunc"} test mathfunc-trunc.2 {trunc: too many args} -body { tcl::mathfunc::trunc a b } -returnCodes error -result {too many arguments for math function "trunc"} test mathfunc-trunc.3 {trunc: valid result} { tcl::mathfunc::trunc 12.5 } 12.0 test mathfunc-trunc.4 {trunc: valid result} { tcl::mathfunc::trunc -12.5 } -12.0 ::tcltest::cleanupTests return # Local Variables: # mode: tcl # End: