Compare commits

..

No commits in common. "master" and "420b78bdc2a16ca7c7dfd623aa9d99087dc05d0f" have entirely different histories.

9 changed files with 1 additions and 43 deletions

View File

@ -1,5 +1,4 @@
#TODO: find way of installing shell library with make
files = c/add c/div c/mean c/mod c/mul c/sub c/sum
files = add div mean mul sub sum
all: $(files)

View File

25
c/mod.c
View File

@ -1,25 +0,0 @@
#include <stdio.h>
#ifndef eprintf
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
int main(int argc, char **argv) {
int v1;
int v2;
int out;
int e1;
int e2;
e1 = sscanf(argv[1], "%i", &v1);
e2 = sscanf(argv[2], "%i", &v2);
if(e1==EOF) {
eprintf("%s: argument 1 cannot be parsed as int", *argv);
return 1;
} else if(e2==EOF) {
eprintf("%s: argument 2 cannot be parsed as int", *argv);
return 1;
}
out=v1%v2;
printf("%d\n",out);
return 0;
}

View File

View File

View File

View File

@ -1,16 +0,0 @@
# Shellmath v2
# Works in most bourne-type shells.
# Partially reimplemented in shell script due to less overhead.
function add { echo $(($1+$2)); }
function sub { echo $(($1-$2)); }
function mul { echo $(($1*$2)); }
function div { echo $(($1/$2)); }
function mdl { echo $(($1%$2)); }
function randr { echo $(($1+$RANDOM%$2)); }
function sum {
for i in $@; do
acc=$((acc+i))
done
echo $acc
}

View File

View File