-
Notifications
You must be signed in to change notification settings - Fork 1
Explore the Project
Avighna edited this page Mar 6, 2023
·
6 revisions
This library has functions that deal with the four basic math operations: addition, subtraction, multiplication, and division.
All of these functions can be called from C like this:
#include <basic_math_operations.h>
function_name ( ... );See using in C++ for examples on how to use this library in C++ and using in Python for examples using Python.
This only applies to C users. Please note that all buffers passed to any of the library's functions have to be zeroed beforehand. Failing to do so may lead to unexpected behaviour.
| Function | Source code | Description | Cross-platform | Programming language |
|---|---|---|---|---|
| add_whole_same_length | Linux | Adds two non-negative integers of the same length. | No | x86-64 Assembly |
| add_whole | Linux, Windows | Adds two non-negative integers. | Yes | x86-64 Assembly |
| addp | addp.c | Adds two non-negative rational numbers. | Yes | C |
| add | add.c | Adds two rational numbers. | Yes | C |
| Function | Source code | Description | Cross-platform | Programming language |
|---|---|---|---|---|
| subtract_whole_same_length | Linux | Subtracts two non-negative integers of the same length. | No | x86-64 Assembly |
| subtract_whole | Linux, Windows | Subtracts two non-negative integers. | Yes | x86-64 Assembly |
| subtractp | subtractp.c | Subtracts two non-negative rational numbers. | Yes | C |
| subtract | subtract.c | Subtracts two rational numbers. | Yes | C |
| Function | Source code | Description | Cross-platform | Programming language |
|---|---|---|---|---|
| _multiply_whole | Linux, Windows | Multiplies two non-negative integers but needs empty buffers. | Yes | x86-64 Assembly |
| multiply_whole | Linux, multiply_whole.c | Multiplies two non-negative integers. | Yes | x86-64 Assembly and C |
| multiplyp | multiplyp.c | Multiplies two non-negative rational numbers. | Yes | C |
| multiply | multiply.c | Multiplies two rational numbers. | Yes | C |
| Function | Source code | Description | Cross-platform | Programming language |
|---|---|---|---|---|
| _divide_whole_with_remainder | Linux, Windows | Performs modular division on two non-negative integers but needs an empty buffer along with its size. | Yes | x86-64 Assembly |
| divide_whole_with_remainder | divide_whole_with_remainder.c | Performs modular division on two non-negative integers. | Yes | C |
| divide_whole | divide_whole.c | Divides two non-negative integers. | Yes | C |
| dividep | dividep.c | Divides two non-negative rational numbers. | Yes | C |
| divide | divide.c | Divides two rational numbers. | Yes | C |
Each function has an attached description in the basic_math_operations.h header file. Example:
/// @brief Divides the first argument by the second argument with 'accuracy'
/// decimal places. Stores the quotient in the third argument. This function is
/// undefined when the denominator is 0.
/// @param numerator The numerator as a decimal.
/// @param denominator The nonzero denominator as a decimal.
/// @param quotient The quotient of the division.
/// @param accuracy The minimum number of decimal places to calculate to.
/// @return This is a void function: it does not return anything.
bmo_function_start void divide(const char *numerator, const char *denominator,
char *quotient, size_t accuracy);These function descriptions can be accessed by hovering over the function when editing code.