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