diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-08-24 17:57:51 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-08-24 17:57:51 +0200 |
| commit | 77ac9ce0a5c55d4f79f8fb8f7daa59ddb53cb507 (patch) | |
| tree | 93d4e30a207265af03394d347bfff76ba677f3ce /src/benchmarks/cfrac/atop.c | |
| parent | 971adefadb94e8780b1a73f08ed11d76c2ead8a2 (diff) | |
| download | allocbench-77ac9ce0a5c55d4f79f8fb8f7daa59ddb53cb507.tar.gz allocbench-77ac9ce0a5c55d4f79f8fb8f7daa59ddb53cb507.zip | |
add cfrac benchmark
Diffstat (limited to 'src/benchmarks/cfrac/atop.c')
| -rw-r--r-- | src/benchmarks/cfrac/atop.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/benchmarks/cfrac/atop.c b/src/benchmarks/cfrac/atop.c new file mode 100644 index 0000000..98f132a --- /dev/null +++ b/src/benchmarks/cfrac/atop.c @@ -0,0 +1,61 @@ +#include <ctype.h> +#include "pdefs.h" +#include "pcvt.h" +#include "precision.h" + +/* + * ascii to precision (modeled after atoi) + * leading whitespace skipped + * an optional leading '-' or '+' followed by digits '0'..'9' + * leading 0's Ok + * stops at first unrecognized character + * + * Returns: pUndef if an invalid argument (pUndef or nondigit as 1st digit) + */ +precision atop(chp) + register char *chp; +{ + precision res = pUndef; + precision clump = pUndef; + int sign = 0; + register int ch; + register accumulator temp; + accumulator x; + register int i; + + if (chp != (char *) 0) { + while (isspace(*chp)) chp++; /* skip whitespace */ + if (*chp == '-') { + sign = 1; + ++chp; + } else if (*chp == '+') { + ++chp; + } + if (isdigit(ch = * (unsigned char *) chp)) { + pset(&res, pzero); + pset(&clump, utop(aDigit)); + do { + i = aDigitLog-1; + temp = ch - '0'; + do { + if (!isdigit(ch = * (unsigned char *) ++chp)) goto atoplast; + temp = temp * aBase + (ch - '0'); + } while (--i > 0); + pset(&res, padd(pmul(res, clump), utop(temp))); + } while (isdigit(ch = * (unsigned char *) ++chp)); + goto atopdone; +atoplast: + x = aBase; + while (i++ < aDigitLog-1) { + x *= aBase; + } + pset(&res, padd(pmul(res, utop(x)), utop(temp))); +atopdone: + if (sign) { + pset(&res, pneg(res)); + } + } + } + pdestroy(clump); + return presult(res); +} |
