diff options
author | Kevin B Kenny <kennykb@acm.org> | 2006-12-01 19:59:59 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2006-12-01 19:59:59 (GMT) |
commit | 339ca1b05809a2057811f8afa91f753e7482dc0f (patch) | |
tree | 583e2aa907472a929b1df844211858394e6f224a /tests/expr.test | |
parent | 987906704f34c52aac4787e16dcbbc9d41ddbd48 (diff) | |
download | tcl-339ca1b05809a2057811f8afa91f753e7482dc0f.zip tcl-339ca1b05809a2057811f8afa91f753e7482dc0f.tar.gz tcl-339ca1b05809a2057811f8afa91f753e7482dc0f.tar.bz2 |
TIP#299 IMPLEMENTATION
Diffstat (limited to 'tests/expr.test')
-rw-r--r-- | tests/expr.test | 93 |
1 files changed, 92 insertions, 1 deletions
diff --git a/tests/expr.test b/tests/expr.test index 7064f17..51b66bd 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -10,7 +10,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: expr.test,v 1.65 2006/11/05 03:33:57 dgp Exp $ +# RCS: @(#) $Id: expr.test,v 1.66 2006/12/01 20:00:00 kennykb Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2.1 @@ -6556,6 +6556,97 @@ test expr-46.19 {round() handling of long/bignum boundary} { expr {round(double(0x7fffffffffffffff))} } 9223372036854775808 +test expr-47.1 {isqrt() - arg count} { + list [catch {expr {isqrt(1,2)}} result] $result +} {1 {too many arguments for math function "isqrt"}} + +test expr-47.2 {isqrt() - non-number} { + list [catch {expr {isqrt({rubbish})}} result] $result +} {1 {expected number but got "rubbish"}} + +test expr-47.3 {isqrt() - NaN} ieeeFloatingPoint { + list [catch {expr {isqrt(NaN)}} result] $result +} {1 {floating point value is Not a Number}} + +test expr-47.4 {isqrt() of negative floating point number} { + list [catch {expr {isqrt(-1.0)}} result] $result +} {1 {square root of negative argument}} + +test expr-47.5 {isqrt() of floating point zero} { + expr isqrt(0.0) +} 0 + +test expr-47.6 {isqrt() of exact floating point numbers} { + set trouble {} + for {set i 0} {$i < 16} {incr i} { + set root [expr {1 << $i}] + set rm1 [expr {$root - 1}] + set arg [expr {pow(2., (2 * $i))}] + if {isqrt($arg-1) != $rm1} { + append trouble "i = " $i ": isqrt( " $arg "-1) != " $rm1 "\n" + } + if {isqrt($arg) != $root} { + append trouble "i = " $i ": isqrt( " $arg ") != " $root "\n" + } + if {isqrt($arg+1) != $root} { + append trouble "i = " $i ": isqrt( " $arg "+1) != " $root "\n" + } + } + set trouble +} {} + +test expr-47.7 {isqrt() of exact floating point numbers} ieeeFloatingPoint { + set trouble {} + for {set i 17} {$i < 27} {incr i} { + set root [expr {1 << $i}] + set rm1 [expr {$root - 1}] + set arg [expr {pow(2., (2 * $i))}] + if {isqrt($arg-1.0) != $rm1} { + append trouble "i = " $i ": isqrt( " $arg "-1) != " $rm1 "\n" + } + if {isqrt($arg) != $root} { + append trouble "i = " $i ": isqrt( " $arg ") != " $root "\n" + } + if {isqrt($arg+1.0) != $root} { + append trouble "i = " $i ": isqrt( " $arg "+1) != " $root "\n" + } + } + set trouble +} {} + +test expr-47.8 {isqrt of inexact floating point number} ieeeFloatingPoint { + expr isqrt(2[string repeat 0 34]) +} 141421356237309504 + +test expr-47.9 {isqrt of negative int} { + list [catch {expr isqrt(-1)} result] $result +} {1 {square root of negative argument}} + +test expr-47.10 {isqrt of negative bignum} { + list [catch {expr isqrt(-1[string repeat 0 1000])} result] $result +} {1 {square root of negative argument}} + +test expr-47.11 {isqrt of zero} { + expr {isqrt(0)} +} 0 + +test expr-47.12 {isqrt of various sizes of integer} { + for {set i 0} {$i < 3000} {incr i} { + set root [expr {1 << $i}] + set rm1 [expr {$root - 1}] + set arg [expr {1 << (2 * $i)}] + if {isqrt($arg-1) != $rm1} { + append trouble "i = " $i ": isqrt( " $arg "-1) != " $rm1 "\n" + } + if {isqrt($arg) != $root} { + append trouble "i = " $i ": isqrt( " $arg ") != " $root "\n" + } + if {isqrt($arg+1) != $root} { + append trouble "i = " $i ": isqrt( " $arg "+1) != " $root "\n" + } + } + set trouble +} {} # cleanup if {[info exists a]} { |