Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: F-PC Forth Tutorial Message-ID: <929.UUL1.3#5129@willett.UUCP> Date: 9 May 90 03:44:59 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 105 Date: 05-06-90 (23:28) Number: 3 (Echo) To: JACK BROWN Refer#: NONE From: PAUL BRANNON Read: NO Subj: L. 3, P. 4 EXERCISES Status: PUBLIC MESSAGE \ exercise 3.9 single number display operator table using BINARY : bitable ( n -- ) cr 1 spaces ." unsigned " ." signed " ." unsigned " ." signed " ." unsigned " ." signed " cr 1 spaces ." decimal " ." decimal " ." binary " ." binary " ." hex " ." hex " 20 0 do cr decimal dup 10 u.r dup 10 .r binary dup 18 u.r dup 10 .r hex dup 10 u.r dup 10 .r 1 + loop drop decimal cr ; -9 bitable unsigned signed unsigned signed unsigned signed decimal decimal binary binary hex hex 65527 -9 1111111111110111 -1001 FFF7 -9 65528 -8 1111111111111000 -1000 FFF8 -8 65529 -7 1111111111111001 -111 FFF9 -7 65530 -6 1111111111111010 -110 FFFA -6 65531 -5 1111111111111011 -101 FFFB -5 65532 -4 1111111111111100 -100 FFFC -4 65533 -3 1111111111111101 -11 FFFD -3 65534 -2 1111111111111110 -10 FFFE -2 65535 -1 1111111111111111 -1 FFFF -1 0 0 0 0 0 0 1 1 1 1 1 1 2 2 10 10 2 2 3 3 11 11 3 3 4 4 100 100 4 4 5 5 101 101 5 5 6 6 110 110 6 6 7 7 111 111 7 7 8 8 1000 1000 8 8 9 9 1001 1001 9 9 10 10 1010 1010 A A \ exercise 3.10, true and false data sets : true_set ( -- ) cr 4 4 = u.b cr 4 5 <> u.b cr 4 5 < u.b cr 4 3 > u.b cr 0 0= u.b cr 4 0<> u.b cr -4 0< u.b cr 4 0> u.b cr true true and u.b cr true false or u.b cr false not u.b cr ; : false_set ( -- ) cr 4 5 = u.b cr 4 4 <> u.b cr 4 3 < u.b cr 4 5 > u.b cr 2 0= u.b cr 0 0<> u.b cr 4 0< u.b cr -4 0> u.b cr false true and u.b cr false false or u.b cr true not u.b cr ; \ Compute area of a circle to three decimal places (character printing) : CIRCLE_AREA ( r -- ) DUP * 355 113 */MOD ." Area = " 5 .r ASCII . EMIT 5 0 DO 10 * 113 /MOD 48 + emit LOOP DROP ; : TEST_CIRC ( -- ) 11 1 DO CR I CIRCLE_AREA LOOP ; \ > an even better solution than 1 .R is 48 + EMIT \ > Can you explain why this will work?? \ This turns the numerical digit into an ASCII character. That's a \ pretty good solution. Below is output for modified CIRCLE_AREA test_circ Area = 3.14159 Area = 12.56637 Area = 28.27433 Area = 50.26548 Area = 78.53982 Area = 113.09734 Area = 153.93805 Area = 201.06194 Area = 254.46902 Area = 314.15929 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'