math.h: intpow

This commit is contained in:
Matheus
2022-11-24 18:27:12 -03:00
parent 05439a4e3b
commit b64edd7765
4 changed files with 40 additions and 2 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
objects := $(patsubst %.c,%.o,$(wildcard *.c))
subdirs := stdio string hashtable ringbuffer
OBJPATH=$(OBJDIR)/include/ringbuffer/
subdirs := stdio string hashtable ringbuffer math
OBJPATH=$(OBJDIR)/include/
export
all: $(subdirs) $(objects)
+6
View File
@@ -0,0 +1,6 @@
#ifndef _MATH_H_INCLUDE
#define _MATH_H_INCLUDE
long intpow(long base, long exp);
#endif
+12
View File
@@ -0,0 +1,12 @@
objects := $(patsubst %.c,%.o,$(wildcard *.c))
subdirs :=
OBJPATH=$(OBJDIR)/include/math/
export
all: $(subdirs) $(objects)
for subdir in $(subdirs) ; do $(MAKE) -C $${subdir} ; done
%.o: %.c
$(CC) $(CFLAGS) -o $@ $<
mkdir -p $(OBJPATH)
cp $@ $(OBJPATH)/$@
+20
View File
@@ -0,0 +1,20 @@
#include <math.h>
long intpow(long base, long exp){
if(exp == 0)
return 1;
long mult = base;
// this is kinda inefficient but works for now I guess
// i = 1 because value only really changes when the exponent is 2
for(int i = 1; i < exp; ++i){
base *= mult;
}
return base;
}