; TEST INTEGER AND FLOAT

message("This script does lots of mad things with numbers and variables. It should terminate with NO further messages, in about 12 to 30 seconds...")

; set all values
; note we set ints with float value, it'll be corrected for us...
set A to  1.1
set B to  2.2
set C to  3.3
set D to  4.4
set E to  5.5
set F to  6.6
set G to  7.7
set H to  8.8
set I to  9.9
set J to 10.10
set K to 11.11
set L to 12.12
set M to 13.13
set N to 14.14
set O to 15.15
set P to 16.16
set Q to 17.17
set R to 18.18
set S to 19.19
set T to 20.20
set U to 21.21
set V to 22.22
set W to 23.23
set X to 24.24
set Y to 25.25
set Z to 26.26


; check they were set correctly
; note we check ints with float value, it'll be corrected for us...
if (A !  1.1)  message("variable A is incorrect!")
if (B !  2.2)  message("variable B is incorrect!")
if (C !  3.3)  message("variable C is incorrect!")
if (D !  4.4)  message("variable D is incorrect!")
if (E !  5.5)  message("variable E is incorrect!")
if (F !  6.6)  message("variable F is incorrect!")
if (G !  7.7)  message("variable G is incorrect!")
if (H !  8.8)  message("variable H is incorrect!")
if (I !  9.9)  message("variable I is incorrect!")
if (J ! 10.10) message("variable J is incorrect!")
if (K ! 11.11) message("variable K is incorrect!")
if (L ! 12.12) message("variable L is incorrect!")
if (M ! 13.13) message("variable M is incorrect!")
if (N ! 14.14) message("variable N is incorrect!")
if (O ! 15.15) message("variable O is incorrect!")
if (P ! 16.16) message("variable P is incorrect!")
if (Q ! 17.17) message("variable Q is incorrect!")
if (R ! 18.18) message("variable R is incorrect!")
if (S ! 19.19) message("variable S is incorrect!")
if (T ! 20.20) message("variable T is incorrect!")
if (U ! 21.21) message("variable U is incorrect!")
if (V ! 22.22) message("variable V is incorrect!")
if (W ! 23.23) message("variable W is incorrect!")
if (X ! 24.24) message("variable X is incorrect!")
if (Y ! 25.25) message("variable Y is incorrect!")
if (Z ! 26.26) message("variable Z is incorrect!")

lvar()


; now we'll do some integer maths

; addition
set A to 100

add(A, 23)
if (A ! 123) message("Integer addition (1) test failed")

A++
if (A ! 124) message("Integer addition (2) test failed")

; subtraction
sub(A, 23)
if (A ! 101) message("Integer subtraction (1) test failed")

A--
if (A ! 100) message("Integer subtraction (2) test failed")

; multiplication
mul(B, A, 2)
if (B ! 200) message("Integer multiplication test failed")

; division
div(A, B, 2)
if (A ! 100) message("Integer division test failed")

; logical AND
set A to 16
set B to 4
and(C, A, B)
if (C ! 0) message("Integer AND test failed")

; logical EOR
eor(C, A, B)
if (C ! 20) message("Integer EOR test (1) failed")
; retest, 'cos for A=16 and B=4, EOR and OR give same results
eor(C, A, A)
if (C ! 0) message("Integer EOR test (2) failed")

; logical NOT (also tests parsing of negative numbers!)
not(C, A)
if (C ! -17) message("Integer NOT test failed")

; logical OR
or(C, A, B)
if (C ! 20) message("Integer EOR test (1) failed")

; logical LSR
lsr(C, A, B)
if (C ! 1) message("Integer LSR test failed")

; logical LSL
lsl(C, A, B)
if (C ! 256) message("Integer LSL test failed")


; float maths

; addition
set Q to 100.1

add(Q, 23.3)
if (Q ! 123.4) message("Float addition (1) test failed")

Q++
if (Q ! 124.4) message("Float addition (2) test failed")

; subtraction
sub(Q, 23.3)
if (Q ! 101.1) message("Float subtraction (1) test failed")

Q--
if (Q ! 100.1) message("Float subtraction (2) test failed")

; multiplication
mul(R, Q, 2)
if (R ! 200.2) message("Float multiplication test failed")

; division
div(Q, R, 2)
if (Q ! 100.1) message("Float division test failed")

; logical AND
set Q to 16.16
set R to 4.4
and(S, Q, R)
if (S ! 0) message("Float AND test failed")

; logical EOR
eor(S, Q, R)
if (S ! 20) message("Float EOR test (1) failed")
; retest, 'cos for A=(int)16 and B=(int)4, EOR and OR give same results
eor(S, Q, Q)
if (S ! 0) message("Float EOR test (2) failed")

; logical NOT (also tests parsing of negative numbers!)
not(S, Q)
if (S ! -17) message("Float NOT test failed")

; logical OR
or(S, Q, R)
if (S ! 20) message("Float EOR test (1) failed")

; logical LSR
lsr(S, Q, R)
if (S ! 1) message("Float LSR test failed")

; logical LSL
lsl(S, Q, R)
if (S ! 256) message("Float LSL test failed")


; number assignment tests
set A to 1
if (A ! 1) message("come on... 'set A to 1' will work, okay!?!? :-)")

set A to 123.456
if (A ! 123) message("float->int not working correctly")
if (A ! 123.456) message("float-int for ifparse not working correctly")

set A to &12
if (A ! 18) message("hex->denary not working correctly")
if (A ! &12) message("hex->denary for ifparse not working correctly")
if (A ! %10010) message("bin->denary for ifparse not working correctly")
set A to %00010010
if (A ! 18) message("bin->denary not working correctly")

set A to -1
if (A ! -1) message("denary negative assignment or ifparse failure")

set A to -&17F
if (A ! -&17F) message("hex negative assignment or ifparse failure")

set A to -%10101010
if (A ! -%10101010) message("bin negative assignment or ifparse failure")

set A to %10001001101001100111000110011001
if (A ! %10001001101001100111000110011001) message("long bin (32bit) assignment or ifparse failure")


; multi-mode maths - note the accuracy that BASIC uses, we MUST be as accurate outselves
set B to 17
set C to 6
div(Q, B, C)
if (Q ! 2.833333333) message("17/6 wasn't 2.833333333")


; all done, dump the output again and then exit.
lvar()

terminate()
