Skip to content

Commit

Permalink
cii: Add arith interface
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Nov 29, 2023
1 parent 2ddcf80 commit 02aafb8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cii/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(CMAKE_C_STANDARD 11)
option(BUILD_TESTING "" ON)

set(SOURCE_FILES
src/arith.c
src/assert.c
src/atom.c
src/except.c
Expand All @@ -16,6 +17,7 @@ set(SOURCE_FILES
src/table.c
)
set(HEADER_FILES
include/cii/arith.h
include/cii/assert.h
include/cii/atom.h
include/cii/except.h
Expand Down
51 changes: 51 additions & 0 deletions cii/include/cii/arith.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2023 Xu Shaohua <[email protected]>. All rights reserved.
// Use of this source is governed by GNU General Public License
// that can be found in the LICENSE file.

#ifndef CII_ARITH_H_
#define CII_ARITH_H_

/**
* Returns the maximum of two integers.
* @param x
* @param y
* @return
*/
extern int arith_max(int x, int y);

/**
* Returns the minimum of two integers.
* @param x
* @param y
* @return
*/
extern int arith_min(int x, int y);

/**
* Returns quotient of dividing |x| by |y|.
*
* When |x| and |y| are both positive or both negative, this function is equals
* to x / y.
* @param x
* @param y
* @return
*/
extern int arith_div(int x, int y);

/**
* Returns remainder of dividing x by y.
*
* When |x| and |y| are both positive or both negative, this function is equals
* x % y.
*
* @param x
* @param y
* @return
*/
extern int arith_mod(int x, int y);

extern int arith_ceiling(int x, int y);

extern int arith_floor(int x, int y);

#endif // CII_ARITH_H_
5 changes: 5 additions & 0 deletions cii/src/arith.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2023 Xu Shaohua <[email protected]>. All rights reserved.
// Use of this source is governed by GNU General Public License
// that can be found in the LICENSE file.

#include "cii/arith.h"
7 changes: 6 additions & 1 deletion cii/src/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
// Use of this source is governed by GNU General Public License
// that can be found in the LICENSE file.

#include "cii/set.h"
#include "cii/set.h"

#include <limits.h>

#include "cii/assert.h"
#include "cii/mem.h"

0 comments on commit 02aafb8

Please sign in to comment.