Post Reply 
AriCalculator is a home made pocket calculator.
10-31-2018, 08:06 AM (This post was last modified: 10-31-2018 09:45 AM by grsbanks.)
Post: #62
RE: AriCalculator is a home made pocket calculator.
The library will be fully open source once I'm satisfied that it's working properly. I'm writing it in C that's as portable as I can make it so it should work on pretty much any 32- or 64-bit system.

As far as usage is concerned, this small test program in C is linked to the library:

Code:
#include <stdlib.h>
#include <stdio.h>

#include "decfp.h"

void prt(_NUM*);

int main(int argc, char** argv) {
    
    _NUM x, sn, cs, tn;

    RealToNum(&CONST_PI_2,&x);
    prt(&x);
    NumSinCos(&x,&sn,&cs);
    NumScaleTrigVector(&sn,&cs);
    prt(&sn);
    prt(&cs);
    
    Setting_ErrorOnOverflow = TRUE;
    /* NumTan does this anyway */
    DECFP_ERR res = NumDivide(&sn,&cs,&tn);
    if (res)
        printf("ERROR: %s\n",ErrorMessage(res));
    else
        prt(&tn);
    
    Setting_ErrorOnOverflow = FALSE;
    res = NumDivide(&sn,&cs,&tn);
    if (res)
        printf("ERROR: %s\n",ErrorMessage(res));
    else
        prt(&tn);

    NumNegate(&x,&x);
    
    NumSinCos(&x,&sn,&cs);
    NumScaleTrigVector(&sn,&cs);
    prt(&sn);
    prt(&cs);
    
    Setting_ErrorOnOverflow = TRUE;
    res = NumDivide(&sn,&cs,&tn);
    if (res)
        printf("ERROR: %s\n",ErrorMessage(res));
    else
        prt(&tn);
    
    Setting_ErrorOnOverflow = FALSE;
    res = NumDivide(&sn,&cs,&tn);
    if (res)
        printf("ERROR: %s\n",ErrorMessage(res));
    else
        prt(&tn);
    
    return 0;
}

void prt(_NUM* x) {
    char* bfr = NumOutFullPrecision(x);
    printf("%s\n",bfr);
    free(bfr);
}

Gives this output:

Code:
$ bin/decfp
+1.57079632679489661923132e+0000
+1.00000000000000000000000e+0000
+0.00000000000000000000000e+0000
ERROR: Divide by zero
+9.99999999999999999999999e+9999
-1.00000000000000000000000e+0000
+0.00000000000000000000000e+0000
ERROR: Divide by zero
-9.99999999999999999999999e+9999
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: AriCalculator is a home made pocket calculator. - grsbanks - 10-31-2018 08:06 AM



User(s) browsing this thread: 3 Guest(s)