-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update numeric cast syntax; add tests
- Loading branch information
Showing
4 changed files
with
100 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@main = x & @tu0 ~ (* x) | ||
|
||
// casting to u24 | ||
@tu0 = (* {n x}) & @tu1 ~ (* x) & 0 ~ $([u24] n) // 0 | ||
@tu1 = (* {n x}) & @tu2 ~ (* x) & 1234 ~ $([u24] n) // 1234 | ||
@tu2 = (* {n x}) & @tu3 ~ (* x) & +4321 ~ $([u24] n) // 4321 | ||
@tu3 = (* {n x}) & @tu4 ~ (* x) & -5678 ~ $([u24] n) // 16771538 (reinterprets bits) | ||
@tu4 = (* {n x}) & @tu5 ~ (* x) & 2.8 ~ $([u24] n) // 2 (rounds to zero) | ||
@tu5 = (* {n x}) & @tu6 ~ (* x) & -12.5 ~ $([u24] n) // 0 (saturates) | ||
@tu6 = (* {n x}) & @tu7 ~ (* x) & 16777216.0 ~ $([u24] n) // 16777215 (saturates) | ||
@tu7 = (* {n x}) & @tu8 ~ (* x) & +inf ~ $([u24] n) // 16777215 (saturates) | ||
@tu8 = (* {n x}) & @tu9 ~ (* x) & -inf ~ $([u24] n) // 0 (saturates) | ||
@tu9 = (* {n x}) & @ti0 ~ (* x) & +NaN ~ $([u24] n) // 0 | ||
|
||
// casting to i24 | ||
@ti0 = (* {n x}) & @ti1 ~ (* x) & 0 ~ $([i24] n) // +0 | ||
@ti1 = (* {n x}) & @ti2 ~ (* x) & 1234 ~ $([i24] n) // +1234 | ||
@ti2 = (* {n x}) & @ti3 ~ (* x) & +4321 ~ $([i24] n) // +4321 | ||
@ti3 = (* {n x}) & @ti4 ~ (* x) & -5678 ~ $([i24] n) // -5678 | ||
@ti4 = (* {n x}) & @ti5 ~ (* x) & 2.8 ~ $([i24] n) // +2 (rounds to zero) | ||
@ti5 = (* {n x}) & @ti6 ~ (* x) & -12.7 ~ $([i24] n) // -12 (rounds to zero) | ||
@ti6 = (* {n x}) & @ti7 ~ (* x) & 8388610.0 ~ $([i24] n) // +8388607 (saturates) | ||
@ti7 = (* {n x}) & @ti8 ~ (* x) & -8388610.0 ~ $([i24] n) // -8388608 (saturates) | ||
@ti8 = (* {n x}) & @ti9 ~ (* x) & +inf ~ $([i24] n) // +8388607 (saturates) | ||
@ti9 = (* {n x}) & @ti10 ~ (* x) & -inf ~ $([i24] n) // -8388608 (saturates) | ||
@ti10 = (* {n x}) & @tf0 ~ (* x) & +NaN ~ $([i24] n) // +0 | ||
|
||
// casting to f24 | ||
@tf0 = (* {n x}) & @tf1 ~ (* x) & +NaN ~ $([f24] n) // +NaN | ||
@tf1 = (* {n x}) & @tf2 ~ (* x) & +inf ~ $([f24] n) // +inf | ||
@tf2 = (* {n x}) & @tf3 ~ (* x) & -inf ~ $([f24] n) // -inf | ||
@tf3 = (* {n x}) & @tf4 ~ (* x) & 2.15 ~ $([f24] n) // 2.15 | ||
@tf4 = (* {n x}) & @tf5 ~ (* x) & -2.15 ~ $([f24] n) // -2.15 | ||
@tf5 = (* {n x}) & @tf6 ~ (* x) & 0.15 ~ $([f24] n) // 0.15 | ||
@tf6 = (* {n x}) & @tf7 ~ (* x) & -1234 ~ $([f24] n) // -1234.0 | ||
@tf7 = (* {n x}) & @tf8 ~ (* x) & +1234 ~ $([f24] n) // +1234.0 | ||
@tf8 = (* {n x}) & @tf9 ~ (* x) & 123456 ~ $([f24] n) // 123456.0 | ||
@tf9 = (* {n x}) & @tp0 ~ (* x) & 16775982 ~ $([f24] n) // 16775936.0 | ||
|
||
// printing | ||
@tp0 = (* {n x}) & @tp1 ~ (* x) & n ~ [u24] // [u24] | ||
@tp1 = (* {n x}) & @tp2 ~ (* x) & n ~ [i24] // [i24] | ||
@tp2 = (* {n x}) & @t ~ (* x) & n ~ [f24] // [f24] | ||
|
||
@t = * |
20 changes: 20 additions & 0 deletions
20
tests/snapshots/pre_reduce_run@tests::programs::numeric_casts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
source: tests/tests.rs | ||
expression: output | ||
input_file: tests/programs/numeric_casts.hvm | ||
--- | ||
{0 {1234 {4321 {16771538 {2 {0 {16777215 {16777215 {0 {0 {+0 {+1234 {+4321 {-5678 {+2 {-12 {+8388607 {-8388608 {+8388607 {-8388608 {+0 {+NaN {+inf {-inf {2.1500244 {-2.1500244 {0.15000153 {-1234.0 {1234.0 {123456.0 {16775936.0 {[u24] {[i24] {[f24] *}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} | ||
pre-reduce: | ||
RWTS : 167 | ||
- ANNI : 33 | ||
- COMM : 1 | ||
- ERAS : 34 | ||
- DREF : 68 | ||
- OPER : 31 | ||
run: | ||
RWTS : 75 | ||
- ANNI : 1 | ||
- COMM : 0 | ||
- ERAS : 1 | ||
- DREF : 73 | ||
- OPER : 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
source: tests/tests.rs | ||
expression: output | ||
input_file: tests/programs/numeric_casts.hvm | ||
--- | ||
{0 {1234 {4321 {16771538 {2 {0 {16777215 {16777215 {0 {0 {+0 {+1234 {+4321 {-5678 {+2 {-12 {+8388607 {-8388608 {+8388607 {-8388608 {+0 {+NaN {+inf {-inf {2.1500244 {-2.1500244 {0.15000153 {-1234.0 {1234.0 {123456.0 {16775936.0 {[u24] {[i24] {[f24] *}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} | ||
RWTS : 207 | ||
- ANNI : 34 | ||
- COMM : 1 | ||
- ERAS : 35 | ||
- DREF : 106 | ||
- OPER : 31 |