mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
math.h: intpow
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef _MATH_H_INCLUDE
|
||||
#define _MATH_H_INCLUDE
|
||||
|
||||
long intpow(long base, long exp);
|
||||
|
||||
#endif
|
||||
@@ -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)/$@
|
||||
@@ -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;
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user