mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
math.h: intpow
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
objects := $(patsubst %.c,%.o,$(wildcard *.c))
|
objects := $(patsubst %.c,%.o,$(wildcard *.c))
|
||||||
subdirs := stdio string hashtable ringbuffer
|
subdirs := stdio string hashtable ringbuffer math
|
||||||
OBJPATH=$(OBJDIR)/include/ringbuffer/
|
OBJPATH=$(OBJDIR)/include/
|
||||||
export
|
export
|
||||||
|
|
||||||
all: $(subdirs) $(objects)
|
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