Skip to content

Commit

Permalink
[libc] Add abs() function
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Nov 11, 2024
1 parent 64e065a commit b66b84b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions libc/include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void dtostr(double val, int style, int preci, char *buf);

long atol(const char *str);
int atoi(const char *str);
int abs(int x);

/* Returned by `div'. */
typedef struct
Expand Down
1 change: 1 addition & 0 deletions libc/misc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LIB ?= out.a
include $(TOPDIR)/libc/$(COMPILER).inc

OBJS = \
abs.o \
aliases.o \
atexit.o \
atof.o \
Expand Down
6 changes: 6 additions & 0 deletions libc/misc/abs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdlib.h>

int abs(int x)
{
return x < 0? -x : x;
}

0 comments on commit b66b84b

Please sign in to comment.