02-22-2021, 09:28 PM

(02-22-2021 12:26 AM)Eddie W. Shore Wrote: [ -> ]Does anyone know how to find the integer or fractional part in the C programming module?

Perhaps this is useful

I spent some time today to map the math BASIC functions to C for the G850(V)(S). To use this code, enter the macros and functions (or only the ones you need) with line numbers (use A to auto number) in a new file basic.h on the G850(V)(S). Then add #include "basic.h" in your C program:

/* C equivalents of BASIC math functions - Dr. Robert van Engelen */

/* Written in compact form to save space, using fp (double) and li (long) */

/* WARNING: <,<=,>,>= on floats have a bug on some G850's, instead of x<y use x-y<0 */

/* Functions do not perform any range validity checking on argument values */

/* INT() and FIX() arguments should be in range -2147483648 to 2147483647 */

/* Note that ABS(x) takes a double, whereas abs(n) takes an int */

/* Note that li (long) values must be displayed with printf("%ld",n); */

/* License: BSD-3 open source */

#define fp double

#define li long

#define ACS acos

#define AHC acosh

#define AHS asinh

#define AHT atanh

#define ASN asin

#define ATN atan

#define COS cos

#define EXP exp

#define LN log

#define LOG log10

#define PI 3.141592654

#define RCP 1./

#define SIN sin

#define SQR sqrt

#define TAN tan

fp ABS(fp x){return x<0?-x:x;}

fp CUB(fp x){return x*x*x;}

fp CUR(fp x){return pow(x,1./3);}

fp FACT(li n){fp x=1;while(n>1)x*=n--;return x;}

li FIX(fp x){return x;}

li INT(fp x){return x<0?x-.9999999999:x;}

li NCR(li n,li k){li i=1,j=0;if(k>n-k)k=n-k;while(++j<=k)i*=n-k+j,i/=j;return i;}

li NPR(li n,li k){li i=1;k=n-k;while(++k<=n)i*=k;return i;}

fp POL(fp x,fp y,fp*z){*z=x>0?atan(y/x):y?asin(y<0?-1:1)-atan(x/y):acos(-(x<0));return sqrt(x*x+y*y);}

fp REC(fp x,fp y,fp*z){*z=x*sin(y);return x*cos(y);}

li SGN(fp x){return x<0?-1:!!x;}

fp SQU(fp x){return x*x;}

fp TEN(x){return pow(10,x);}

/* 0<RND(0)<1 gives double float result */

/* 0<RND(n)<=ceil(n) for n>=1 gives integer result */

/* RND(-n)==n new PRNG seed n */

fp RND(fp x) {

static unsigned li s=5323;

if (x<0) return s=-x;

s=8253729*s+2396403;

return x<1 ? (s%32767+1)/32768. : (li)(s%32767*x)/32767+1;

}

Most of the math functions available in BASIC are already defined in C, but the ones that are missing are defined in this code.

Note that the code is very terse to keep it as small as possible. Every punctuation character is significant! Best is to load the code with bas2img and bin2wav over the CE-126P cassette interface (see my earlier post) or directly via RS232.

I also found that the PC-G850(V)(S) user guide has some omissions, such as beep(x,y,z) which is the same BEEP command as in BASIC which works if you have a piezo buzzer installed. Also the ternary operators (?:) and the comma operator (,) are not mentioned, and there are a couple of minor mistakes.

Disclaimer: I tested this code extensively and found no bugs. But I cannot offer any warranty.

I may post a set of C math functions that are missing on the G850(V)(S). Suggestions and contributions are welcome!

- Rob