Skip to content

Commit

Permalink
expr.test: amend to [98006f00ac471be5] - tests simplification and ded…
Browse files Browse the repository at this point in the history
…uplication, big matrix for isunordered removed (unneeded), more input cases to cover FP classification (wide, bignum, etc)
  • Loading branch information
sebres committed Dec 28, 2024
1 parent 67688d1 commit 4b9c302
Showing 1 changed file with 63 additions and 83 deletions.
146 changes: 63 additions & 83 deletions tests/expr.test
Original file line number Diff line number Diff line change
Expand Up @@ -7277,71 +7277,58 @@ foreach func {isfinite isinf isnan isnormal issubnormal} {
} -match glob -result *
}

test expr-54.0 {float classification: isfinite} {expr {isfinite(1.0)}} 1
test expr-54.1 {float classification: isfinite} {expr {isfinite(-1.0)}} 1
test expr-54.2 {float classification: isfinite} {expr {isfinite(0.0)}} 1
test expr-54.3 {float classification: isfinite} {expr {isfinite(-0.0)}} 1
test expr-54.4 {float classification: isfinite} {expr {isfinite(1/Inf)}} 1
test expr-54.5 {float classification: isfinite} {expr {isfinite(-1/Inf)}} 1
test expr-54.6 {float classification: isfinite} {expr {isfinite(1e-314)}} 1
test expr-54.7 {float classification: isfinite} {expr {isfinite(inf)}} 0
test expr-54.8 {float classification: isfinite} {expr {isfinite(-inf)}} 0
test expr-54.9 {float classification: isfinite} {expr {isfinite(NaN)}} 0

test expr-55.0 {float classification: isinf} {expr {isinf(1.0)}} 0
test expr-55.1 {float classification: isinf} {expr {isinf(-1.0)}} 0
test expr-55.2 {float classification: isinf} {expr {isinf(0.0)}} 0
test expr-55.3 {float classification: isinf} {expr {isinf(-0.0)}} 0
test expr-55.4 {float classification: isinf} {expr {isinf(1/Inf)}} 0
test expr-55.5 {float classification: isinf} {expr {isinf(-1/Inf)}} 0
test expr-55.6 {float classification: isinf} {expr {isinf(1e-314)}} 0
test expr-55.7 {float classification: isinf} {expr {isinf(inf)}} 1
test expr-55.8 {float classification: isinf} {expr {isinf(-inf)}} 1
test expr-55.9 {float classification: isinf} {expr {isinf(NaN)}} 0

test expr-56.0 {float classification: isnan} {expr {isnan(1.0)}} 0
test expr-56.1 {float classification: isnan} {expr {isnan(-1.0)}} 0
test expr-56.2 {float classification: isnan} {expr {isnan(0.0)}} 0
test expr-56.3 {float classification: isnan} {expr {isnan(-0.0)}} 0
test expr-56.4 {float classification: isnan} {expr {isnan(1/Inf)}} 0
test expr-56.5 {float classification: isnan} {expr {isnan(-1/Inf)}} 0
test expr-56.6 {float classification: isnan} {expr {isnan(1e-314)}} 0
test expr-56.7 {float classification: isnan} {expr {isnan(inf)}} 0
test expr-56.8 {float classification: isnan} {expr {isnan(-inf)}} 0
test expr-56.9 {float classification: isnan} {expr {isnan(NaN)}} 1

test expr-57.0 {float classification: isnormal} {expr {isnormal(1.0)}} 1
test expr-57.1 {float classification: isnormal} {expr {isnormal(-1.0)}} 1
test expr-57.2 {float classification: isnormal} {expr {isnormal(0.0)}} 0
test expr-57.3 {float classification: isnormal} {expr {isnormal(-0.0)}} 0
test expr-57.4 {float classification: isnormal} {expr {isnormal(1/Inf)}} 0
test expr-57.5 {float classification: isnormal} {expr {isnormal(-1/Inf)}} 0
test expr-57.6 {float classification: isnormal} {expr {isnormal(1e-314)}} 0
test expr-57.7 {float classification: isnormal} {expr {isnormal(inf)}} 0
test expr-57.8 {float classification: isnormal} {expr {isnormal(-inf)}} 0
test expr-57.9 {float classification: isnormal} {expr {isnormal(NaN)}} 0

test expr-58.0 {float classification: issubnormal} {expr {issubnormal(1.0)}} 0
test expr-58.1 {float classification: issubnormal} {expr {issubnormal(-1.0)}} 0
test expr-58.2 {float classification: issubnormal} {expr {issubnormal(0.0)}} 0
test expr-58.3 {float classification: issubnormal} {expr {issubnormal(-0.0)}} 0
test expr-58.4 {float classification: issubnormal} {expr {issubnormal(1/Inf)}} 0
test expr-58.5 {float classification: issubnormal} {expr {issubnormal(-1/Inf)}} 0
test expr-58.6 {float classification: issubnormal} {expr {issubnormal(1e-314)}} 1
test expr-58.7 {float classification: issubnormal} {expr {issubnormal(inf)}} 0
test expr-58.8 {float classification: issubnormal} {expr {issubnormal(-inf)}} 0
test expr-58.9 {float classification: issubnormal} {expr {issubnormal(NaN)}} 0
foreach {v r} {
1 normal
-1 normal
0x7fffffffffffffff normal
-0x7fffffffffffffff normal
0xffffffffffffffffff normal
-0xffffffffffffffffff normal
1.0 normal
-1.0 normal
0 zero
-0 zero
0.0 zero
-0.0 zero
1/Inf zero
-1/Inf zero
1e-314 subnormal
1e5555 infinite
1e308**1e10 infinite
Inf infinite
-1e5555 infinite
-1e308**(1e10+1) infinite
-Inf infinite
NaN nan
} {
if {[regexp {[/\*]} $v]} { set v [expr $v] }
test expr-58.1($v)=$r "float classification: fpclassify($v) eq $r" {
fpclassify $v
} $r
test expr-58.2($v) "float classification: isfinite($v)" {
expr {isfinite($v)}
} [expr {$r ni {"infinite" "nan"}}]
test expr-58.3($v) "float classification: isinf($v)" {
expr {isinf($v)}
} [expr {$r eq "infinite"}]
test expr-58.4($v) "float classification: isnan($v)" {
expr {isnan($v)}
} [expr {$r eq "nan"}]
test expr-58.5($v) "float classification: isnormal($v)" {
expr {isnormal($v)}
} [expr {$r eq "normal"}]
test expr-58.6($v) "float classification: issubnormal($v)" {
expr {issubnormal($v)}
} [expr {$r eq "subnormal"}]
test expr-58.7($v) "float classification: isunordered(0 and $v)" {
expr {isunordered(0,$v) + isunordered($v,0)}
} [expr {$r eq "nan" ? 2 : 0}]
test expr-58.9($v) "float classification: isunordered(NaN and $v)" {
expr {isunordered(NaN,$v) + isunordered($v,NaN)}
} 2
}
unset -nocomplain v r

test expr-59.0 {float classification: fpclassify} {fpclassify 1.0} normal
test expr-59.1 {float classification: fpclassify} {fpclassify -1.0} normal
test expr-59.2 {float classification: fpclassify} {fpclassify 0.0} zero
test expr-59.3 {float classification: fpclassify} {fpclassify -0.0} zero
test expr-59.4 {float classification: fpclassify} {fpclassify [expr 1/Inf]} zero
test expr-59.5 {float classification: fpclassify} {fpclassify [expr -1/Inf]} zero
test expr-59.6 {float classification: fpclassify} {fpclassify 1e-314} subnormal
test expr-59.7 {float classification: fpclassify} {fpclassify inf} infinite
test expr-59.8 {float classification: fpclassify} {fpclassify -inf} infinite
test expr-59.9 {float classification: fpclassify} {fpclassify NaN} nan
test expr-59.10 {float classification: fpclassify} -returnCodes error -body {
fpclassify
} -result {wrong # args: should be "fpclassify floatValue"}
Expand All @@ -7367,31 +7354,24 @@ test expr-60.4 {float classification: basic arg handling} -body {
test expr-60.5 {float classification: basic arg handling} -body {
expr {isunordered("gorp", 1.0)}
} -returnCodes error -result {expected number but got "gorp"}
test expr-60.6 {float classification: basic arg handling} -body {
expr {isunordered(0x123, 1.0)}
} -match glob -result *
test expr-60.6a {float classification: basic arg handling, large bigint -> double and wide} -body {
expr "isunordered(0x[string repeat f 100], 0x7fffffffffffffff)"
} -result 0
test expr-60.6b {float classification: basic arg handling, large bigint -> double Inf and wide} -body {
expr "isunordered(0x[string repeat f 1000], 0x7fffffffffffffff)"
} -result 0
test expr-60.7 {float classification: basic arg handling} -body {
expr {isunordered(1.0, true)}
} -returnCodes error -result {expected number but got "true"}
test expr-60.8 {float classification: basic arg handling} -body {
expr {isunordered(1.0, "gorp")}
} -returnCodes error -result {expected number but got "gorp"}
test expr-60.9 {float classification: basic arg handling} -body {
expr {isunordered(1.0, 0x123)}
} -match glob -result *

# Big matrix of comparisons, but it's just a binary isinf()
set values {1 -1 1.0 -1.0 0.0 -0.0 1e-314 Inf -Inf NaN}
set results {0 0 0 0 0 0 0 0 0 1}
set ctr 0
foreach v1 $values r1 $results {
foreach v2 $values r2 $results {
test expr-61.[incr ctr] "float classification: isunordered($v1,$v2)" {
expr {isunordered($v1, $v2)}
} [expr {$r1 || $r2}]
}
}
unset -nocomplain values results ctr
test expr-60.9a {float classification: basic arg handling, wide and large bigint -> double} -body {
expr "isunordered(0x7fffffffffffffff, 0x[string repeat f 100])"
} -result 0
test expr-60.9b {float classification: basic arg handling, wide and large bigint -> double Inf} -body {
expr "isunordered(0x7fffffffffffffff, 0x[string repeat f 1000])"
} -result 0

test expr-62.1 {TIP 582: comments} -body {
expr {1 # + 2}
Expand Down

0 comments on commit 4b9c302

Please sign in to comment.