assert!
This commit is contained in:
parent
c1a808a807
commit
0fd38d2888
1 changed files with 9 additions and 7 deletions
|
@ -294,10 +294,12 @@ function enter_matrix() {
|
|||
|
||||
try {
|
||||
entries = JSON.parse(atob(matrix))
|
||||
assert(Array.isArray(entries))
|
||||
assert(entries.length == 2 * dim * dim)
|
||||
if (!Array.isArray(entries)) { throw new Error("Bad object") }
|
||||
if (entries.length != 2 * dim * dim) { throw new Error("Bad length") }
|
||||
for (let i = 0; i < 2 * dim * dim; i++) {
|
||||
assert(!isNaN(entries[i]) && -3 < entries[i] && entries[i] < 3)
|
||||
if (isNaN(entries[i]) || -3 > entries[i] || entries[i] > 3) {
|
||||
throw new Error("Bad entries")
|
||||
}
|
||||
}
|
||||
|
||||
matrix_entries = entries
|
||||
|
@ -358,10 +360,10 @@ function input_update(e) {
|
|||
const i = row * dim * 2 + col * 2;
|
||||
try {
|
||||
let [real, imag] = input.value.split('+');
|
||||
real = Number(real);
|
||||
imag = Number(imag.replace(/i$/, ''));
|
||||
assert(!isNaN(real) && -3 < real && real < 3);
|
||||
assert(!isNaN(imag) && -3 < imag && imag < 3);
|
||||
real = Number(real)
|
||||
imag = Number(imag.replace(/i$/, ''))
|
||||
if (isNaN(real) || -3 > real || real > 3) { throw new Error("Bad real part") }
|
||||
if (isNaN(imag) || -3 > imag || imag > 3) { throw new Error("Bad imaginary part") }
|
||||
matrix_entries[i] = real;
|
||||
matrix_entries[i+1] = imag;
|
||||
p_draw()
|
||||
|
|
Loading…
Add table
Reference in a new issue