Home » Archimedes archive » Archimedes World » AW-1996-06-Disc 1.adf » !AcornAns_AcornAns » MathFns/c/main
MathFns/c/main
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Archimedes World » AW-1996-06-Disc 1.adf » !AcornAns_AcornAns |
Filename: | MathFns/c/main |
Read OK: | ✔ |
File size: | 13D3 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <math.h> #include "wimpt.h" #include "werr.h" #include "bbc.h" #include "os.h" #include "swis.h" #define one (1<<16) extern int rbbcinc(int r, int k); extern int div_frac16(int number, int divisor); extern int mul_frac16(int x, int a); extern int mul_frac16c(int x, int a); extern int sqrt_frac16(unsigned int x); extern int gauss16(void); extern void sgauss16(int seed); extern int cos16(int a); extern int sin16(int a); extern int exp16(int a); extern int ln16(int a); extern int pow16(int a, int b); extern int acs16(int a); extern int asn16(int a); typedef enum {multi, nonmulti} monitor; typedef enum {asn_fn, acs_fn, pow_fn, sin_fn, cos_fn, exp_fn, ln_fn} fn; monitor monitortype; int linesep; double xs, ys; char *fnname[] = {"2/pi.arcsin x", "2/pi.arccos x", "x ^ 0.375", "sin x.pi/2", "cos x.pi/2", "exp x", "ln x"}; double fnxl[] = {-1, -1, 0, -4, -4, -1, -1}; double fnxh[] = {1, 1, 1, 4, 4, 1.5, 8.4}; double fnyl[] = {-1, 0, 0, -1, -1, -0.8, -1.6}; double fnyh[] = {1, 2, 1, 1, 1, 4, 2.368}; monitor read_monitor_type(void) { int r2; os_swi3r(6, 161,133,0, 0,0,&r2); if ((r2/4 & 3) == 1) return multi; else return nonmulti; } void set_scales(int a, int b, int w, int h, double xl, double yl, double xh, double yh, BOOL axes, BOOL guides) { int u,v; xs = w/(xh-xl); ys = h/(yh-yl); u = a-(int)(xl*xs); v = b-(int)(yl*ys); bbc_origin(0, 0); bbc_gwindow(a, b, a+w, b+h); bbc_gcol(0, 2); if (axes) { bbc_move(a, v); bbc_drawby(w, 0); bbc_move(u, b); bbc_drawby(0, h); } if (guides) { bbc_move(a, v+(int)(ys/65536.0)); bbc_drawby(w, 0); bbc_move(a, v-(int)(ys/65536.0)); bbc_drawby(w, 0); bbc_gcol(0, 3); bbc_move(a, v+(int)(ys/131072.0)); bbc_drawby(w, 0); bbc_move(a, v-(int)(ys/131072.0)); bbc_drawby(w, 0); } bbc_origin(u, v); bbc_gcol(0, 7); } int fnvalue(int f, int x) { switch (f) { case asn_fn: return asn16(x); break; case acs_fn: return acs16(x); break; case pow_fn: return pow16(x, 24576); break; case sin_fn: return sin16(x); break; case cos_fn: return cos16(x); break; case exp_fn: return exp16(x); break; case ln_fn: return ln16(x); break; } return 0; } double fnerror(int f, int x) { switch (f) { case asn_fn: return asn16(x)/65536.0-asin(x/65536.0)/1.570796327; break; case acs_fn: return acs16(x)/65536.0-acos(x/65536.0)/1.570796327; break; case pow_fn: return pow16(x, 24576)/65536.0-pow(x/65536.0, 0.375); break; case sin_fn: return sin16(x)/65536.0-sin(1.570796327*x/65536.0); break; case cos_fn: return cos16(x)/65536.0-cos(1.570796327*x/65536.0); break; case exp_fn: return exp16(x)/65536.0-exp(x/65536.0); break; case ln_fn: return x<=0 ? 0.01 : ln16(x)/65536.0-log(x/65536.0); /*nb 0.01 is a bodge to produce no visible points on graph for x<=0 since fns not defined in that range*/ break; } return 0; } int main(void) { int x, xmax, xinc; fn function; char dummy; monitortype = read_monitor_type(); bbc_mode(monitortype==multi ? 20 : 12); linesep = monitortype==multi ? 20 : 40; for (function = asn_fn; function<=ln_fn; function++) { bbc_clg(); bbc_gcol(0, 2); bbc_vdu(5); bbc_move(64, 992); printf(fnname[function]); bbc_move(64, 480); printf("error (point falling tween inner lines implies less than 0.5*1/65536)"); set_scales(128+64,512+64,1024-128,512-128, fnxl[function], fnyl[function], fnxh[function], fnyh[function], TRUE, FALSE); xmax = (int)(fnxh[function]*one); xinc = (int)(one/xs); for (x=(int)(fnxl[function]*one); x<=xmax; x+=xinc) { bbc_plot(69, (int)(x*xs/one), (int)(fnvalue(function, x)*ys/one)); } set_scales(128+64,0+64,1024-128,512-128, fnxl[function], -1/32768.0, fnxh[function], 1/32768.0, FALSE, TRUE); xinc = xinc/4; for (x=(int)(fnxl[function]*one); x<=xmax; x+=xinc) { bbc_plot(69, (int)(x*xs/one), (int)(fnerror(function, x)*ys)); } bbc_origin(0,0); bbc_gwindow(0,0,1279,1023); bbc_move(1152, 131); printf("Press a"); bbc_move(1152, 131-linesep); printf("key ..."); bbc_vdu(4); /* { int time, sum; double xd, xmaxd, xincd, sumd; x = (int)(fnxl[acs_fn]*one); xmax = (int)(fnxh[acs_fn]*one); xinc = 4; sum=0; time=clock(); for (; x<=xmax; x+=xinc) { sum+=acs16(x); } time=clock()-time; printf("time %i, sum %i\n",time,sum); xd = fnxl[acs_fn]; xmaxd= xmax/65536.0; xincd= xinc/65536.0; sumd=0; time=clock(); for (; xd<=xmaxd; xd+=xincd) { sumd+=acos(xd); } time=clock()-time; printf("time %i, sum %e\n",time,sumd/1.570796327); } */ os_cli("fx 15 1"); bbc_cursor(0); dummy = bbc_get(); } return 0; }
00000000 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e |#include <stdio.| 00000010 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 |h>.#include <std| 00000020 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 |lib.h>.#include | 00000030 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 6c |<string.h>.#incl| 00000040 75 64 65 20 3c 74 69 6d 65 2e 68 3e 0a 23 69 6e |ude <time.h>.#in| 00000050 63 6c 75 64 65 20 3c 6d 61 74 68 2e 68 3e 0a 0a |clude <math.h>..| 00000060 23 69 6e 63 6c 75 64 65 20 22 77 69 6d 70 74 2e |#include "wimpt.| 00000070 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 77 65 72 |h".#include "wer| 00000080 72 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 62 |r.h".#include "b| 00000090 62 63 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 |bc.h".#include "| 000000a0 6f 73 2e 68 22 0a 0a 23 69 6e 63 6c 75 64 65 20 |os.h"..#include | 000000b0 22 73 77 69 73 2e 68 22 0a 0a 23 64 65 66 69 6e |"swis.h"..#defin| 000000c0 65 20 6f 6e 65 20 28 31 3c 3c 31 36 29 0a 0a 65 |e one (1<<16)..e| 000000d0 78 74 65 72 6e 20 69 6e 74 20 72 62 62 63 69 6e |xtern int rbbcin| 000000e0 63 28 69 6e 74 20 72 2c 20 69 6e 74 20 6b 29 3b |c(int r, int k);| 000000f0 0a 65 78 74 65 72 6e 20 69 6e 74 20 64 69 76 5f |.extern int div_| 00000100 66 72 61 63 31 36 28 69 6e 74 20 6e 75 6d 62 65 |frac16(int numbe| 00000110 72 2c 20 69 6e 74 20 64 69 76 69 73 6f 72 29 3b |r, int divisor);| 00000120 0a 65 78 74 65 72 6e 20 69 6e 74 20 6d 75 6c 5f |.extern int mul_| 00000130 66 72 61 63 31 36 28 69 6e 74 20 78 2c 20 69 6e |frac16(int x, in| 00000140 74 20 61 29 3b 0a 65 78 74 65 72 6e 20 69 6e 74 |t a);.extern int| 00000150 20 6d 75 6c 5f 66 72 61 63 31 36 63 28 69 6e 74 | mul_frac16c(int| 00000160 20 78 2c 20 69 6e 74 20 61 29 3b 0a 65 78 74 65 | x, int a);.exte| 00000170 72 6e 20 69 6e 74 20 73 71 72 74 5f 66 72 61 63 |rn int sqrt_frac| 00000180 31 36 28 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 |16(unsigned int | 00000190 78 29 3b 0a 65 78 74 65 72 6e 20 69 6e 74 20 67 |x);.extern int g| 000001a0 61 75 73 73 31 36 28 76 6f 69 64 29 3b 0a 65 78 |auss16(void);.ex| 000001b0 74 65 72 6e 20 76 6f 69 64 20 73 67 61 75 73 73 |tern void sgauss| 000001c0 31 36 28 69 6e 74 20 73 65 65 64 29 3b 0a 65 78 |16(int seed);.ex| 000001d0 74 65 72 6e 20 69 6e 74 20 63 6f 73 31 36 28 69 |tern int cos16(i| 000001e0 6e 74 20 61 29 3b 0a 65 78 74 65 72 6e 20 69 6e |nt a);.extern in| 000001f0 74 20 73 69 6e 31 36 28 69 6e 74 20 61 29 3b 0a |t sin16(int a);.| 00000200 65 78 74 65 72 6e 20 69 6e 74 20 65 78 70 31 36 |extern int exp16| 00000210 28 69 6e 74 20 61 29 3b 0a 65 78 74 65 72 6e 20 |(int a);.extern | 00000220 69 6e 74 20 6c 6e 31 36 28 69 6e 74 20 61 29 3b |int ln16(int a);| 00000230 0a 65 78 74 65 72 6e 20 69 6e 74 20 70 6f 77 31 |.extern int pow1| 00000240 36 28 69 6e 74 20 61 2c 20 69 6e 74 20 62 29 3b |6(int a, int b);| 00000250 0a 65 78 74 65 72 6e 20 69 6e 74 20 61 63 73 31 |.extern int acs1| 00000260 36 28 69 6e 74 20 61 29 3b 0a 65 78 74 65 72 6e |6(int a);.extern| 00000270 20 69 6e 74 20 61 73 6e 31 36 28 69 6e 74 20 61 | int asn16(int a| 00000280 29 3b 0a 0a 74 79 70 65 64 65 66 20 65 6e 75 6d |);..typedef enum| 00000290 20 7b 6d 75 6c 74 69 2c 20 6e 6f 6e 6d 75 6c 74 | {multi, nonmult| 000002a0 69 7d 20 6d 6f 6e 69 74 6f 72 3b 0a 74 79 70 65 |i} monitor;.type| 000002b0 64 65 66 20 65 6e 75 6d 20 7b 61 73 6e 5f 66 6e |def enum {asn_fn| 000002c0 2c 20 61 63 73 5f 66 6e 2c 20 70 6f 77 5f 66 6e |, acs_fn, pow_fn| 000002d0 2c 20 73 69 6e 5f 66 6e 2c 20 63 6f 73 5f 66 6e |, sin_fn, cos_fn| 000002e0 2c 20 65 78 70 5f 66 6e 2c 20 6c 6e 5f 66 6e 7d |, exp_fn, ln_fn}| 000002f0 20 66 6e 3b 0a 0a 6d 6f 6e 69 74 6f 72 20 6d 6f | fn;..monitor mo| 00000300 6e 69 74 6f 72 74 79 70 65 3b 0a 69 6e 74 20 6c |nitortype;.int l| 00000310 69 6e 65 73 65 70 3b 0a 64 6f 75 62 6c 65 20 78 |inesep;.double x| 00000320 73 2c 20 79 73 3b 0a 0a 63 68 61 72 20 2a 66 6e |s, ys;..char *fn| 00000330 6e 61 6d 65 5b 5d 20 3d 20 7b 22 32 2f 70 69 2e |name[] = {"2/pi.| 00000340 61 72 63 73 69 6e 20 78 22 2c 20 22 32 2f 70 69 |arcsin x", "2/pi| 00000350 2e 61 72 63 63 6f 73 20 78 22 2c 20 22 78 20 5e |.arccos x", "x ^| 00000360 20 30 2e 33 37 35 22 2c 20 22 73 69 6e 20 78 2e | 0.375", "sin x.| 00000370 70 69 2f 32 22 2c 20 22 63 6f 73 20 78 2e 70 69 |pi/2", "cos x.pi| 00000380 2f 32 22 2c 20 22 65 78 70 20 78 22 2c 20 22 6c |/2", "exp x", "l| 00000390 6e 20 78 22 7d 3b 0a 64 6f 75 62 6c 65 20 66 6e |n x"};.double fn| 000003a0 78 6c 5b 5d 20 3d 20 7b 2d 31 2c 20 2d 31 2c 20 |xl[] = {-1, -1, | 000003b0 30 2c 20 2d 34 2c 20 2d 34 2c 20 2d 31 2c 20 2d |0, -4, -4, -1, -| 000003c0 31 7d 3b 0a 64 6f 75 62 6c 65 20 66 6e 78 68 5b |1};.double fnxh[| 000003d0 5d 20 3d 20 7b 31 2c 20 31 2c 20 31 2c 20 34 2c |] = {1, 1, 1, 4,| 000003e0 20 34 2c 20 31 2e 35 2c 20 38 2e 34 7d 3b 0a 64 | 4, 1.5, 8.4};.d| 000003f0 6f 75 62 6c 65 20 66 6e 79 6c 5b 5d 20 3d 20 7b |ouble fnyl[] = {| 00000400 2d 31 2c 20 30 2c 20 30 2c 20 2d 31 2c 20 2d 31 |-1, 0, 0, -1, -1| 00000410 2c 20 2d 30 2e 38 2c 20 2d 31 2e 36 7d 3b 0a 64 |, -0.8, -1.6};.d| 00000420 6f 75 62 6c 65 20 66 6e 79 68 5b 5d 20 3d 20 7b |ouble fnyh[] = {| 00000430 31 2c 20 32 2c 20 31 2c 20 31 2c 20 31 2c 20 34 |1, 2, 1, 1, 1, 4| 00000440 2c 20 32 2e 33 36 38 7d 3b 0a 0a 6d 6f 6e 69 74 |, 2.368};..monit| 00000450 6f 72 20 72 65 61 64 5f 6d 6f 6e 69 74 6f 72 5f |or read_monitor_| 00000460 74 79 70 65 28 76 6f 69 64 29 0a 7b 0a 20 20 69 |type(void).{. i| 00000470 6e 74 20 72 32 3b 0a 20 20 6f 73 5f 73 77 69 33 |nt r2;. os_swi3| 00000480 72 28 36 2c 20 31 36 31 2c 31 33 33 2c 30 2c 20 |r(6, 161,133,0, | 00000490 30 2c 30 2c 26 72 32 29 3b 0a 20 20 69 66 20 28 |0,0,&r2);. if (| 000004a0 28 72 32 2f 34 20 26 20 33 29 20 3d 3d 20 31 29 |(r2/4 & 3) == 1)| 000004b0 20 72 65 74 75 72 6e 20 6d 75 6c 74 69 3b 0a 20 | return multi;. | 000004c0 20 65 6c 73 65 20 72 65 74 75 72 6e 20 6e 6f 6e | else return non| 000004d0 6d 75 6c 74 69 3b 0a 7d 0a 0a 76 6f 69 64 20 73 |multi;.}..void s| 000004e0 65 74 5f 73 63 61 6c 65 73 28 69 6e 74 20 61 2c |et_scales(int a,| 000004f0 20 69 6e 74 20 62 2c 20 69 6e 74 20 77 2c 20 69 | int b, int w, i| 00000500 6e 74 20 68 2c 20 64 6f 75 62 6c 65 20 78 6c 2c |nt h, double xl,| 00000510 20 64 6f 75 62 6c 65 20 79 6c 2c 20 64 6f 75 62 | double yl, doub| 00000520 6c 65 20 78 68 2c 20 64 6f 75 62 6c 65 20 79 68 |le xh, double yh| 00000530 2c 20 42 4f 4f 4c 20 61 78 65 73 2c 20 42 4f 4f |, BOOL axes, BOO| 00000540 4c 20 67 75 69 64 65 73 29 0a 7b 0a 20 20 69 6e |L guides).{. in| 00000550 74 20 75 2c 76 3b 0a 20 20 78 73 20 3d 20 77 2f |t u,v;. xs = w/| 00000560 28 78 68 2d 78 6c 29 3b 0a 20 20 79 73 20 3d 20 |(xh-xl);. ys = | 00000570 68 2f 28 79 68 2d 79 6c 29 3b 0a 20 20 75 20 3d |h/(yh-yl);. u =| 00000580 20 61 2d 28 69 6e 74 29 28 78 6c 2a 78 73 29 3b | a-(int)(xl*xs);| 00000590 0a 20 20 76 20 3d 20 62 2d 28 69 6e 74 29 28 79 |. v = b-(int)(y| 000005a0 6c 2a 79 73 29 3b 0a 20 20 62 62 63 5f 6f 72 69 |l*ys);. bbc_ori| 000005b0 67 69 6e 28 30 2c 20 30 29 3b 0a 20 20 62 62 63 |gin(0, 0);. bbc| 000005c0 5f 67 77 69 6e 64 6f 77 28 61 2c 20 62 2c 20 61 |_gwindow(a, b, a| 000005d0 2b 77 2c 20 62 2b 68 29 3b 0a 20 20 62 62 63 5f |+w, b+h);. bbc_| 000005e0 67 63 6f 6c 28 30 2c 20 32 29 3b 0a 20 20 69 66 |gcol(0, 2);. if| 000005f0 20 28 61 78 65 73 29 20 7b 0a 20 20 20 20 62 62 | (axes) {. bb| 00000600 63 5f 6d 6f 76 65 28 61 2c 20 76 29 3b 0a 20 20 |c_move(a, v);. | 00000610 20 20 62 62 63 5f 64 72 61 77 62 79 28 77 2c 20 | bbc_drawby(w, | 00000620 30 29 3b 0a 20 20 20 20 62 62 63 5f 6d 6f 76 65 |0);. bbc_move| 00000630 28 75 2c 20 62 29 3b 0a 20 20 20 20 62 62 63 5f |(u, b);. bbc_| 00000640 64 72 61 77 62 79 28 30 2c 20 68 29 3b 0a 20 20 |drawby(0, h);. | 00000650 7d 0a 20 20 69 66 20 28 67 75 69 64 65 73 29 20 |}. if (guides) | 00000660 7b 0a 20 20 20 20 62 62 63 5f 6d 6f 76 65 28 61 |{. bbc_move(a| 00000670 2c 20 76 2b 28 69 6e 74 29 28 79 73 2f 36 35 35 |, v+(int)(ys/655| 00000680 33 36 2e 30 29 29 3b 0a 20 20 20 20 62 62 63 5f |36.0));. bbc_| 00000690 64 72 61 77 62 79 28 77 2c 20 30 29 3b 0a 20 20 |drawby(w, 0);. | 000006a0 20 20 62 62 63 5f 6d 6f 76 65 28 61 2c 20 76 2d | bbc_move(a, v-| 000006b0 28 69 6e 74 29 28 79 73 2f 36 35 35 33 36 2e 30 |(int)(ys/65536.0| 000006c0 29 29 3b 0a 20 20 20 20 62 62 63 5f 64 72 61 77 |));. bbc_draw| 000006d0 62 79 28 77 2c 20 30 29 3b 0a 20 20 20 20 62 62 |by(w, 0);. bb| 000006e0 63 5f 67 63 6f 6c 28 30 2c 20 33 29 3b 0a 20 20 |c_gcol(0, 3);. | 000006f0 20 20 62 62 63 5f 6d 6f 76 65 28 61 2c 20 76 2b | bbc_move(a, v+| 00000700 28 69 6e 74 29 28 79 73 2f 31 33 31 30 37 32 2e |(int)(ys/131072.| 00000710 30 29 29 3b 0a 20 20 20 20 62 62 63 5f 64 72 61 |0));. bbc_dra| 00000720 77 62 79 28 77 2c 20 30 29 3b 0a 20 20 20 20 62 |wby(w, 0);. b| 00000730 62 63 5f 6d 6f 76 65 28 61 2c 20 76 2d 28 69 6e |bc_move(a, v-(in| 00000740 74 29 28 79 73 2f 31 33 31 30 37 32 2e 30 29 29 |t)(ys/131072.0))| 00000750 3b 0a 20 20 20 20 62 62 63 5f 64 72 61 77 62 79 |;. bbc_drawby| 00000760 28 77 2c 20 30 29 3b 0a 20 20 7d 0a 20 20 62 62 |(w, 0);. }. bb| 00000770 63 5f 6f 72 69 67 69 6e 28 75 2c 20 76 29 3b 0a |c_origin(u, v);.| 00000780 20 20 62 62 63 5f 67 63 6f 6c 28 30 2c 20 37 29 | bbc_gcol(0, 7)| 00000790 3b 0a 7d 0a 0a 69 6e 74 20 66 6e 76 61 6c 75 65 |;.}..int fnvalue| 000007a0 28 69 6e 74 20 66 2c 20 69 6e 74 20 78 29 0a 7b |(int f, int x).{| 000007b0 0a 20 20 73 77 69 74 63 68 20 28 66 29 0a 20 20 |. switch (f). | 000007c0 7b 0a 20 20 20 20 63 61 73 65 20 61 73 6e 5f 66 |{. case asn_f| 000007d0 6e 3a 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 |n:. return | 000007e0 61 73 6e 31 36 28 78 29 3b 0a 20 20 20 20 20 20 |asn16(x);. | 000007f0 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 |break;. case | 00000800 61 63 73 5f 66 6e 3a 0a 20 20 20 20 20 20 72 65 |acs_fn:. re| 00000810 74 75 72 6e 20 61 63 73 31 36 28 78 29 3b 0a 20 |turn acs16(x);. | 00000820 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 | break;. | 00000830 63 61 73 65 20 70 6f 77 5f 66 6e 3a 0a 20 20 20 |case pow_fn:. | 00000840 20 20 20 72 65 74 75 72 6e 20 70 6f 77 31 36 28 | return pow16(| 00000850 78 2c 20 32 34 35 37 36 29 3b 0a 20 20 20 20 20 |x, 24576);. | 00000860 20 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 | break;. case| 00000870 20 73 69 6e 5f 66 6e 3a 0a 20 20 20 20 20 20 72 | sin_fn:. r| 00000880 65 74 75 72 6e 20 73 69 6e 31 36 28 78 29 3b 0a |eturn sin16(x);.| 00000890 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 | break;. | 000008a0 20 63 61 73 65 20 63 6f 73 5f 66 6e 3a 0a 20 20 | case cos_fn:. | 000008b0 20 20 20 20 72 65 74 75 72 6e 20 63 6f 73 31 36 | return cos16| 000008c0 28 78 29 3b 0a 20 20 20 20 20 20 62 72 65 61 6b |(x);. break| 000008d0 3b 0a 20 20 20 20 63 61 73 65 20 65 78 70 5f 66 |;. case exp_f| 000008e0 6e 3a 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 |n:. return | 000008f0 65 78 70 31 36 28 78 29 3b 0a 20 20 20 20 20 20 |exp16(x);. | 00000900 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 |break;. case | 00000910 6c 6e 5f 66 6e 3a 0a 20 20 20 20 20 20 72 65 74 |ln_fn:. ret| 00000920 75 72 6e 20 6c 6e 31 36 28 78 29 3b 0a 20 20 20 |urn ln16(x);. | 00000930 20 20 20 62 72 65 61 6b 3b 0a 20 20 7d 0a 20 20 | break;. }. | 00000940 72 65 74 75 72 6e 20 30 3b 0a 7d 0a 0a 64 6f 75 |return 0;.}..dou| 00000950 62 6c 65 20 66 6e 65 72 72 6f 72 28 69 6e 74 20 |ble fnerror(int | 00000960 66 2c 20 69 6e 74 20 78 29 0a 7b 0a 20 20 73 77 |f, int x).{. sw| 00000970 69 74 63 68 20 28 66 29 0a 20 20 7b 0a 20 20 20 |itch (f). {. | 00000980 20 63 61 73 65 20 61 73 6e 5f 66 6e 3a 0a 20 20 | case asn_fn:. | 00000990 20 20 20 20 72 65 74 75 72 6e 20 61 73 6e 31 36 | return asn16| 000009a0 28 78 29 2f 36 35 35 33 36 2e 30 2d 61 73 69 6e |(x)/65536.0-asin| 000009b0 28 78 2f 36 35 35 33 36 2e 30 29 2f 31 2e 35 37 |(x/65536.0)/1.57| 000009c0 30 37 39 36 33 32 37 3b 0a 20 20 20 20 20 20 62 |0796327;. b| 000009d0 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 61 |reak;. case a| 000009e0 63 73 5f 66 6e 3a 0a 20 20 20 20 20 20 72 65 74 |cs_fn:. ret| 000009f0 75 72 6e 20 61 63 73 31 36 28 78 29 2f 36 35 35 |urn acs16(x)/655| 00000a00 33 36 2e 30 2d 61 63 6f 73 28 78 2f 36 35 35 33 |36.0-acos(x/6553| 00000a10 36 2e 30 29 2f 31 2e 35 37 30 37 39 36 33 32 37 |6.0)/1.570796327| 00000a20 3b 0a 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 |;. break;. | 00000a30 20 20 20 63 61 73 65 20 70 6f 77 5f 66 6e 3a 0a | case pow_fn:.| 00000a40 20 20 20 20 20 20 72 65 74 75 72 6e 20 70 6f 77 | return pow| 00000a50 31 36 28 78 2c 20 32 34 35 37 36 29 2f 36 35 35 |16(x, 24576)/655| 00000a60 33 36 2e 30 2d 70 6f 77 28 78 2f 36 35 35 33 36 |36.0-pow(x/65536| 00000a70 2e 30 2c 20 30 2e 33 37 35 29 3b 0a 20 20 20 20 |.0, 0.375);. | 00000a80 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 | break;. cas| 00000a90 65 20 73 69 6e 5f 66 6e 3a 0a 20 20 20 20 20 20 |e sin_fn:. | 00000aa0 72 65 74 75 72 6e 20 73 69 6e 31 36 28 78 29 2f |return sin16(x)/| 00000ab0 36 35 35 33 36 2e 30 2d 73 69 6e 28 31 2e 35 37 |65536.0-sin(1.57| 00000ac0 30 37 39 36 33 32 37 2a 78 2f 36 35 35 33 36 2e |0796327*x/65536.| 00000ad0 30 29 3b 0a 20 20 20 20 20 20 62 72 65 61 6b 3b |0);. break;| 00000ae0 0a 20 20 20 20 63 61 73 65 20 63 6f 73 5f 66 6e |. case cos_fn| 00000af0 3a 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 63 |:. return c| 00000b00 6f 73 31 36 28 78 29 2f 36 35 35 33 36 2e 30 2d |os16(x)/65536.0-| 00000b10 63 6f 73 28 31 2e 35 37 30 37 39 36 33 32 37 2a |cos(1.570796327*| 00000b20 78 2f 36 35 35 33 36 2e 30 29 3b 0a 20 20 20 20 |x/65536.0);. | 00000b30 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 | break;. cas| 00000b40 65 20 65 78 70 5f 66 6e 3a 0a 20 20 20 20 20 20 |e exp_fn:. | 00000b50 72 65 74 75 72 6e 20 65 78 70 31 36 28 78 29 2f |return exp16(x)/| 00000b60 36 35 35 33 36 2e 30 2d 65 78 70 28 78 2f 36 35 |65536.0-exp(x/65| 00000b70 35 33 36 2e 30 29 3b 0a 20 20 20 20 20 20 62 72 |536.0);. br| 00000b80 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 6c 6e |eak;. case ln| 00000b90 5f 66 6e 3a 0a 20 20 20 20 20 20 72 65 74 75 72 |_fn:. retur| 00000ba0 6e 20 78 3c 3d 30 20 3f 20 30 2e 30 31 20 3a 20 |n x<=0 ? 0.01 : | 00000bb0 6c 6e 31 36 28 78 29 2f 36 35 35 33 36 2e 30 2d |ln16(x)/65536.0-| 00000bc0 6c 6f 67 28 78 2f 36 35 35 33 36 2e 30 29 3b 0a |log(x/65536.0);.| 00000bd0 20 20 20 20 20 2f 2a 6e 62 20 30 2e 30 31 20 69 | /*nb 0.01 i| 00000be0 73 20 61 20 62 6f 64 67 65 20 74 6f 20 70 72 6f |s a bodge to pro| 00000bf0 64 75 63 65 20 6e 6f 20 76 69 73 69 62 6c 65 20 |duce no visible | 00000c00 70 6f 69 6e 74 73 20 6f 6e 20 67 72 61 70 68 20 |points on graph | 00000c10 66 6f 72 20 78 3c 3d 30 20 73 69 6e 63 65 20 66 |for x<=0 since f| 00000c20 6e 73 20 6e 6f 74 20 64 65 66 69 6e 65 64 20 69 |ns not defined i| 00000c30 6e 20 74 68 61 74 20 72 61 6e 67 65 2a 2f 0a 20 |n that range*/. | 00000c40 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 7d 0a | break;. }.| 00000c50 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a 0a 69 | return 0;.}..i| 00000c60 6e 74 20 6d 61 69 6e 28 76 6f 69 64 29 0a 7b 0a |nt main(void).{.| 00000c70 20 20 69 6e 74 20 78 2c 20 78 6d 61 78 2c 20 78 | int x, xmax, x| 00000c80 69 6e 63 3b 0a 20 20 66 6e 20 66 75 6e 63 74 69 |inc;. fn functi| 00000c90 6f 6e 3b 0a 20 20 63 68 61 72 20 64 75 6d 6d 79 |on;. char dummy| 00000ca0 3b 0a 0a 20 20 6d 6f 6e 69 74 6f 72 74 79 70 65 |;.. monitortype| 00000cb0 20 3d 20 72 65 61 64 5f 6d 6f 6e 69 74 6f 72 5f | = read_monitor_| 00000cc0 74 79 70 65 28 29 3b 0a 20 20 62 62 63 5f 6d 6f |type();. bbc_mo| 00000cd0 64 65 28 6d 6f 6e 69 74 6f 72 74 79 70 65 3d 3d |de(monitortype==| 00000ce0 6d 75 6c 74 69 20 3f 20 32 30 20 3a 20 31 32 29 |multi ? 20 : 12)| 00000cf0 3b 0a 20 20 6c 69 6e 65 73 65 70 20 3d 20 6d 6f |;. linesep = mo| 00000d00 6e 69 74 6f 72 74 79 70 65 3d 3d 6d 75 6c 74 69 |nitortype==multi| 00000d10 20 3f 20 32 30 20 3a 20 34 30 3b 0a 0a 20 20 66 | ? 20 : 40;.. f| 00000d20 6f 72 20 28 66 75 6e 63 74 69 6f 6e 20 3d 20 61 |or (function = a| 00000d30 73 6e 5f 66 6e 3b 20 66 75 6e 63 74 69 6f 6e 3c |sn_fn; function<| 00000d40 3d 6c 6e 5f 66 6e 3b 20 66 75 6e 63 74 69 6f 6e |=ln_fn; function| 00000d50 2b 2b 29 20 7b 0a 20 20 20 20 62 62 63 5f 63 6c |++) {. bbc_cl| 00000d60 67 28 29 3b 0a 20 20 20 20 62 62 63 5f 67 63 6f |g();. bbc_gco| 00000d70 6c 28 30 2c 20 32 29 3b 0a 20 20 20 20 62 62 63 |l(0, 2);. bbc| 00000d80 5f 76 64 75 28 35 29 3b 0a 20 20 20 20 62 62 63 |_vdu(5);. bbc| 00000d90 5f 6d 6f 76 65 28 36 34 2c 20 39 39 32 29 3b 0a |_move(64, 992);.| 00000da0 20 20 20 20 70 72 69 6e 74 66 28 66 6e 6e 61 6d | printf(fnnam| 00000db0 65 5b 66 75 6e 63 74 69 6f 6e 5d 29 3b 0a 20 20 |e[function]);. | 00000dc0 20 20 62 62 63 5f 6d 6f 76 65 28 36 34 2c 20 34 | bbc_move(64, 4| 00000dd0 38 30 29 3b 0a 20 20 20 20 70 72 69 6e 74 66 28 |80);. printf(| 00000de0 22 65 72 72 6f 72 20 28 70 6f 69 6e 74 20 66 61 |"error (point fa| 00000df0 6c 6c 69 6e 67 20 74 77 65 65 6e 20 69 6e 6e 65 |lling tween inne| 00000e00 72 20 6c 69 6e 65 73 20 69 6d 70 6c 69 65 73 20 |r lines implies | 00000e10 6c 65 73 73 20 74 68 61 6e 20 30 2e 35 2a 31 2f |less than 0.5*1/| 00000e20 36 35 35 33 36 29 22 29 3b 0a 20 20 20 20 73 65 |65536)");. se| 00000e30 74 5f 73 63 61 6c 65 73 28 31 32 38 2b 36 34 2c |t_scales(128+64,| 00000e40 35 31 32 2b 36 34 2c 31 30 32 34 2d 31 32 38 2c |512+64,1024-128,| 00000e50 35 31 32 2d 31 32 38 2c 20 66 6e 78 6c 5b 66 75 |512-128, fnxl[fu| 00000e60 6e 63 74 69 6f 6e 5d 2c 20 66 6e 79 6c 5b 66 75 |nction], fnyl[fu| 00000e70 6e 63 74 69 6f 6e 5d 2c 20 66 6e 78 68 5b 66 75 |nction], fnxh[fu| 00000e80 6e 63 74 69 6f 6e 5d 2c 20 66 6e 79 68 5b 66 75 |nction], fnyh[fu| 00000e90 6e 63 74 69 6f 6e 5d 2c 20 54 52 55 45 2c 20 46 |nction], TRUE, F| 00000ea0 41 4c 53 45 29 3b 0a 20 20 20 20 78 6d 61 78 20 |ALSE);. xmax | 00000eb0 3d 20 28 69 6e 74 29 28 66 6e 78 68 5b 66 75 6e |= (int)(fnxh[fun| 00000ec0 63 74 69 6f 6e 5d 2a 6f 6e 65 29 3b 0a 20 20 20 |ction]*one);. | 00000ed0 20 78 69 6e 63 20 3d 20 28 69 6e 74 29 28 6f 6e | xinc = (int)(on| 00000ee0 65 2f 78 73 29 3b 0a 20 20 20 20 66 6f 72 20 28 |e/xs);. for (| 00000ef0 78 3d 28 69 6e 74 29 28 66 6e 78 6c 5b 66 75 6e |x=(int)(fnxl[fun| 00000f00 63 74 69 6f 6e 5d 2a 6f 6e 65 29 3b 20 78 3c 3d |ction]*one); x<=| 00000f10 78 6d 61 78 3b 20 78 2b 3d 78 69 6e 63 29 20 7b |xmax; x+=xinc) {| 00000f20 0a 20 20 20 20 20 20 62 62 63 5f 70 6c 6f 74 28 |. bbc_plot(| 00000f30 36 39 2c 20 28 69 6e 74 29 28 78 2a 78 73 2f 6f |69, (int)(x*xs/o| 00000f40 6e 65 29 2c 20 28 69 6e 74 29 28 66 6e 76 61 6c |ne), (int)(fnval| 00000f50 75 65 28 66 75 6e 63 74 69 6f 6e 2c 20 78 29 2a |ue(function, x)*| 00000f60 79 73 2f 6f 6e 65 29 29 3b 0a 20 20 20 20 7d 0a |ys/one));. }.| 00000f70 20 20 20 20 73 65 74 5f 73 63 61 6c 65 73 28 31 | set_scales(1| 00000f80 32 38 2b 36 34 2c 30 2b 36 34 2c 31 30 32 34 2d |28+64,0+64,1024-| 00000f90 31 32 38 2c 35 31 32 2d 31 32 38 2c 20 66 6e 78 |128,512-128, fnx| 00000fa0 6c 5b 66 75 6e 63 74 69 6f 6e 5d 2c 20 2d 31 2f |l[function], -1/| 00000fb0 33 32 37 36 38 2e 30 2c 20 66 6e 78 68 5b 66 75 |32768.0, fnxh[fu| 00000fc0 6e 63 74 69 6f 6e 5d 2c 20 31 2f 33 32 37 36 38 |nction], 1/32768| 00000fd0 2e 30 2c 20 46 41 4c 53 45 2c 20 54 52 55 45 29 |.0, FALSE, TRUE)| 00000fe0 3b 0a 20 20 20 20 78 69 6e 63 20 3d 20 78 69 6e |;. xinc = xin| 00000ff0 63 2f 34 3b 0a 20 20 20 20 66 6f 72 20 28 78 3d |c/4;. for (x=| 00001000 28 69 6e 74 29 28 66 6e 78 6c 5b 66 75 6e 63 74 |(int)(fnxl[funct| 00001010 69 6f 6e 5d 2a 6f 6e 65 29 3b 20 78 3c 3d 78 6d |ion]*one); x<=xm| 00001020 61 78 3b 20 78 2b 3d 78 69 6e 63 29 20 7b 0a 20 |ax; x+=xinc) {. | 00001030 20 20 20 20 20 62 62 63 5f 70 6c 6f 74 28 36 39 | bbc_plot(69| 00001040 2c 20 28 69 6e 74 29 28 78 2a 78 73 2f 6f 6e 65 |, (int)(x*xs/one| 00001050 29 2c 20 28 69 6e 74 29 28 66 6e 65 72 72 6f 72 |), (int)(fnerror| 00001060 28 66 75 6e 63 74 69 6f 6e 2c 20 78 29 2a 79 73 |(function, x)*ys| 00001070 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 62 62 |));. }. bb| 00001080 63 5f 6f 72 69 67 69 6e 28 30 2c 30 29 3b 0a 20 |c_origin(0,0);. | 00001090 20 20 20 62 62 63 5f 67 77 69 6e 64 6f 77 28 30 | bbc_gwindow(0| 000010a0 2c 30 2c 31 32 37 39 2c 31 30 32 33 29 3b 0a 20 |,0,1279,1023);. | 000010b0 20 20 20 62 62 63 5f 6d 6f 76 65 28 31 31 35 32 | bbc_move(1152| 000010c0 2c 20 31 33 31 29 3b 0a 20 20 20 20 70 72 69 6e |, 131);. prin| 000010d0 74 66 28 22 50 72 65 73 73 20 61 22 29 3b 0a 20 |tf("Press a");. | 000010e0 20 20 20 62 62 63 5f 6d 6f 76 65 28 31 31 35 32 | bbc_move(1152| 000010f0 2c 20 31 33 31 2d 6c 69 6e 65 73 65 70 29 3b 0a |, 131-linesep);.| 00001100 20 20 20 20 70 72 69 6e 74 66 28 22 6b 65 79 20 | printf("key | 00001110 2e 2e 2e 22 29 3b 0a 20 20 20 20 62 62 63 5f 76 |...");. bbc_v| 00001120 64 75 28 34 29 3b 0a 2f 2a 0a 20 20 20 20 7b 0a |du(4);./*. {.| 00001130 20 20 20 20 20 20 69 6e 74 20 74 69 6d 65 2c 20 | int time, | 00001140 73 75 6d 3b 0a 20 20 20 20 20 20 64 6f 75 62 6c |sum;. doubl| 00001150 65 20 78 64 2c 20 78 6d 61 78 64 2c 20 78 69 6e |e xd, xmaxd, xin| 00001160 63 64 2c 20 73 75 6d 64 3b 0a 20 20 20 20 20 20 |cd, sumd;. | 00001170 78 20 20 20 20 3d 20 28 69 6e 74 29 28 66 6e 78 |x = (int)(fnx| 00001180 6c 5b 61 63 73 5f 66 6e 5d 2a 6f 6e 65 29 3b 0a |l[acs_fn]*one);.| 00001190 20 20 20 20 20 20 78 6d 61 78 20 3d 20 28 69 6e | xmax = (in| 000011a0 74 29 28 66 6e 78 68 5b 61 63 73 5f 66 6e 5d 2a |t)(fnxh[acs_fn]*| 000011b0 6f 6e 65 29 3b 0a 20 20 20 20 20 20 78 69 6e 63 |one);. xinc| 000011c0 20 3d 20 34 3b 0a 20 20 20 20 20 20 73 75 6d 3d | = 4;. sum=| 000011d0 30 3b 0a 20 20 20 20 20 20 74 69 6d 65 3d 63 6c |0;. time=cl| 000011e0 6f 63 6b 28 29 3b 0a 20 20 20 20 20 20 66 6f 72 |ock();. for| 000011f0 20 28 3b 20 78 3c 3d 78 6d 61 78 3b 20 78 2b 3d | (; x<=xmax; x+=| 00001200 78 69 6e 63 29 20 7b 0a 20 20 20 20 20 20 20 20 |xinc) {. | 00001210 73 75 6d 2b 3d 61 63 73 31 36 28 78 29 3b 0a 20 |sum+=acs16(x);. | 00001220 20 20 20 20 20 7d 0a 20 20 20 20 20 20 74 69 6d | }. tim| 00001230 65 3d 63 6c 6f 63 6b 28 29 2d 74 69 6d 65 3b 0a |e=clock()-time;.| 00001240 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 74 69 | printf("ti| 00001250 6d 65 20 25 69 2c 20 73 75 6d 20 25 69 5c 6e 22 |me %i, sum %i\n"| 00001260 2c 74 69 6d 65 2c 73 75 6d 29 3b 0a 20 20 20 20 |,time,sum);. | 00001270 20 20 78 64 20 20 20 3d 20 66 6e 78 6c 5b 61 63 | xd = fnxl[ac| 00001280 73 5f 66 6e 5d 3b 0a 20 20 20 20 20 20 78 6d 61 |s_fn];. xma| 00001290 78 64 3d 20 78 6d 61 78 2f 36 35 35 33 36 2e 30 |xd= xmax/65536.0| 000012a0 3b 0a 20 20 20 20 20 20 78 69 6e 63 64 3d 20 78 |;. xincd= x| 000012b0 69 6e 63 2f 36 35 35 33 36 2e 30 3b 0a 20 20 20 |inc/65536.0;. | 000012c0 20 20 20 73 75 6d 64 3d 30 3b 0a 20 20 20 20 20 | sumd=0;. | 000012d0 20 74 69 6d 65 3d 63 6c 6f 63 6b 28 29 3b 0a 20 | time=clock();. | 000012e0 20 20 20 20 20 66 6f 72 20 28 3b 20 78 64 3c 3d | for (; xd<=| 000012f0 78 6d 61 78 64 3b 20 78 64 2b 3d 78 69 6e 63 64 |xmaxd; xd+=xincd| 00001300 29 20 7b 0a 20 20 20 20 20 20 20 20 73 75 6d 64 |) {. sumd| 00001310 2b 3d 61 63 6f 73 28 78 64 29 3b 0a 20 20 20 20 |+=acos(xd);. | 00001320 20 20 7d 0a 20 20 20 20 20 20 74 69 6d 65 3d 63 | }. time=c| 00001330 6c 6f 63 6b 28 29 2d 74 69 6d 65 3b 0a 20 20 20 |lock()-time;. | 00001340 20 20 20 70 72 69 6e 74 66 28 22 74 69 6d 65 20 | printf("time | 00001350 25 69 2c 20 73 75 6d 20 25 65 5c 6e 22 2c 74 69 |%i, sum %e\n",ti| 00001360 6d 65 2c 73 75 6d 64 2f 31 2e 35 37 30 37 39 36 |me,sumd/1.570796| 00001370 33 32 37 29 3b 0a 20 20 20 20 7d 0a 2a 2f 0a 20 |327);. }.*/. | 00001380 20 20 20 6f 73 5f 63 6c 69 28 22 66 78 20 31 35 | os_cli("fx 15| 00001390 20 31 22 29 3b 0a 20 20 20 20 62 62 63 5f 63 75 | 1");. bbc_cu| 000013a0 72 73 6f 72 28 30 29 3b 0a 20 20 20 20 64 75 6d |rsor(0);. dum| 000013b0 6d 79 20 3d 20 62 62 63 5f 67 65 74 28 29 3b 0a |my = bbc_get();.| 000013c0 20 20 7d 0a 0a 20 20 72 65 74 75 72 6e 20 30 3b | }.. return 0;| 000013d0 0a 7d 0a |.}.| 000013d3