diff options
author | Kevin B Kenny <kennykb@acm.org> | 2005-08-29 16:18:59 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2005-08-29 16:18:59 (GMT) |
commit | ef4b48b4a556b3bc1ecac4ba3f1414cf3b7d4bd1 (patch) | |
tree | 88a7ae9ad11d90393c4e10c805865f8b091b8818 /tests/expr.test | |
parent | 6b46682cfeecee8430f13996041c1347b9a20658 (diff) | |
download | tcl-ef4b48b4a556b3bc1ecac4ba3f1414cf3b7d4bd1.zip tcl-ef4b48b4a556b3bc1ecac4ba3f1414cf3b7d4bd1.tar.gz tcl-ef4b48b4a556b3bc1ecac4ba3f1414cf3b7d4bd1.tar.bz2 |
Bug 1275043
Diffstat (limited to 'tests/expr.test')
-rw-r--r-- | tests/expr.test | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/tests/expr.test b/tests/expr.test index 6089368..7b7c13b 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.40 2005/08/24 23:36:56 dkf Exp $ +# RCS: @(#) $Id: expr.test,v 1.41 2005/08/29 16:18:59 kennykb Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2.1 @@ -6239,6 +6239,80 @@ test expr-38.1 {abs of smallest 32-bit integer [Bug 1241572]} {wideIs64bit} { expr {abs(-2147483648)} } 2147483648 +set tcl_precision 17 + +test expr-39.1 {round() rounds to +-infinity} { + expr round(0.5) +} 1 +test expr-39.2 {round() rounds to +-infinity} { + expr round(1.5) +} 2 +test expr-39.3 {round() rounds to +-infinity} { + expr round(-0.5) +} -1 +test expr-39.4 {round() rounds to +-infinity} { + expr round(-1.5) +} -2 +test expr-39.5 {round() overflow} { + list [catch {expr round(9.2233720368547758e+018)} result] $result +} {1 {integer value too large to represent}} +test expr-39.6 {round() overflow} { + list [catch {expr round(-9.2233720368547758e+018)} result] $result +} {1 {integer value too large to represent}} +test expr-39.7 {round() bad value} { + set x trash + list [catch {expr {round($x)}} result] $result +} {1 {argument to math function didn't have numeric value}} +test expr-39.8 {round() already an integer} { + set x 123456789012 + incr x + expr round($x) +} 123456789013 +test expr-39.9 {round() boundary case - 1/2 - 1 ulp} { + set x 0.25 + set bit 0.125 + while 1 { + set newx [expr { $x + $bit }] + if { $newx == $x || $newx == 0.5 } break + set x $newx + set bit [expr { $bit / 2.0 }] + } + expr round($x) +} 0 +test expr-39.10 {round() boundary case - 1/2 + 1 ulp} { + set x 0.75 + set bit 0.125 + while 1 { + set newx [expr { $x - $bit }] + if { $newx == $x || $newx == 0.5 } break + set x $newx + set bit [expr { $bit / 2.0 }] + } + expr round($x) +} 1 +test expr-39.11 {round() boundary case - -1/2 - 1 ulp} { + set x -0.75 + set bit 0.125 + while 1 { + set newx [expr { $x + $bit }] + if { $newx == $x || $newx == -0.5 } break + set x $newx + set bit [expr { $bit / 2.0 }] + } + expr round($x) +} -1 +test expr-39.10 {round() boundary case - -1/2 + 1 ulp} { + set x -0.25 + set bit 0.125 + while 1 { + set newx [expr { $x - $bit }] + if { $newx == $x || $newx == -0.5 } break + set x $newx + set bit [expr { $bit / 2.0 }] + } + expr round($x) +} 0 + # cleanup if {[info exists a]} { unset a |