A math function library for various programming languages. The primary target is WebAssembly, everything else is secondary and may not be stable. Use at your own risk.
Note: This library is not yet in a stable state. Exponent function cannot calculate with decimals powers (which results in root function not working yet either)
- C
- C++
- WebAssembly
- JavaScript (with proper
.wasmimport) - TypeScript (with proper
.wasmimport)
- JavaScript (with proper
The following functions are provided:
-
add(a, b)- Calculates the sum of valuesa&b -
subtract(a, b)- Calculates the difference ofbsubtracted froma -
multiply(a, b)- Calculates the product of valuesa&b -
divide(a, b)- Calculates the quotient ofadivided byb -
one_over(a)- Calculates the quotient of 1 divided bya -
percent(a, percent)- Calculates the percent of valuea -
is_whole_num(a)- Returns whether or notais a whole number -
is_even(a)- Returns whether or notais an even number -
am(a, b)- Calculates the Arithmetic Mean of provided valuesa&b -
gm(a, b)- Calculates the Geometric Mean of provided valuesa&b -
agm(a, b)- Calculates the Arithmetic-Geometric Mean ofaandb -
sq_root(a)- Calculates the square root ofa -
ln(a)- Calculates the natural log ofausing the formula informulas/natural-log.odf. This file can be opened w/ LibreOffice Math- Note: The results returned from this function will start to lose precision around the hundred thousandths decimal place.
-
log(base, arguement)- Calculates the logarithm ofbase&arguement -
exponent(base, exponent)- Calculates the value ofbaseto theexponentpower- Note: This only works when the exponent is a whole number (currently)
-
root(index, radicand)- Calculates the value ofindexto the root ofradicand
Emscripten is required to compile this project to WebAssembly.
Run either of the following commands to compile calculator.c to calculator.wasm
# Make Command:
make
# Build Command:
emcc -Os mathfun.c -o mathfun.wasm --no-entryThis file is generated from a compiled version of calculator.wasm. It is provided so anyone can compile the .wasm file from it without the need for emscripten.