June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,51 @@
LOGICAL A,B !These are allocated the same storage
INTEGER IA,IB !As the default integer size.
EQUIVALENCE (IA,A),(IB,B) !So, this will cause no overlaps.
WRITE (6,*) "Boolean tests via integers..."
DO 199 IA = 0,1 !Two states for A.
DO 199 IB = 0,1 !Two states for B.
IF (IA) 666,99,109 !Not four ways, just three.
99 IF (IB) 666,100,101 !Negative values are surely wrong.
100 WRITE (6,*) "FF",IA,IB
GO TO 199
101 WRITE (6,*) "FT",IA,IB
GO TO 199
109 IF (IB) 666,110,111 !A second test.
110 WRITE (6,*) "TF",IA,IB
GO TO 199
111 WRITE (6,*) "TT",IA,IB
199 CONTINUE !Both loops finish here.
WRITE (6,*) "Boolean tests via integers and computed GO TO..."
DO 299 IA = 0,1 !Two states for A.
DO 299 IB = 0,1 !Two states for B.
GO TO (200,201,210,211) 1 + IA*2 + IB !Counting starts with one.
200 WRITE (6,*) "FF",IA,IB
GO TO 299
201 WRITE (6,*) "FT",IA,IB
GO TO 299
210 WRITE (6,*) "TF",IA,IB
GO TO 299
211 WRITE (6,*) "TT",IA,IB
299 CONTINUE !Both loops finish here.
300 WRITE (6,301)
301 FORMAT (/,"Boolean tests via LOGICAL variables...",/
1 " AB IA IB (IA*2 + IB)")
A = .TRUE. !Syncopation.
B = .TRUE. !Via the .NOT., the first pair will be FF.
DO I = 0,1 !Step through two states.
A = .NOT.A !Thus generate F then T.
DO J = 0,1 !Step through the second two states.
B = .NOT.B !Thus generate FF, FT, TF, TT.
WRITE (6,302) A,B,IA,IB,IA*2 + IB !But with strange values.
302 FORMAT (1X,2L1,2I6,I8) !Show both types.
END DO !Next value for B.
END DO !Next value for A.
GO TO 999
666 WRITE (6,*) "Huh?"
999 CONTINUE
END

View file

@ -0,0 +1,6 @@
INTEGER FUNCTION IF2(A,B) !Combine two LOGICAL variables.
LOGICAL A,B !These.
IF2 = 0 !Wasted effort if A is true.
IF (A) IF2 = 2 !But it avoids IF ... THEN ... ELSE ... END IF blather.
IF (B) IF2 = IF2 + 1 !This relies on IF2 being a variable. (Standard in F90+)
END FUNCTION IF2 !Thus produce a four-way result.

View file

@ -0,0 +1,6 @@
SELECT CASE(IF2(A,B))
CASE(B"00"); WRITE (6,*) "Both false."
CASE(B"01"); WRITE (6,*) "B only."
CASE(B"10"); WRITE (6,*) "A only."
CASE(B"11"); WRITE (6,*) "Both true."
END SELECT