Pakeji Hesabu is a math package written in pure Nuru by VictorKariuki.
This package provides various mathematical functions and constants implemented in nuru programming language. It includes methods for trigonometric functions
, logarithmic functions
, array operations
, and utility functions
.
To use the pakeji hesabu
package follow the steps below:
-
Copy the
hesabu.nr
file and any required third-party package files into the same directory as your project. -
Ensure that the package file names end with the
.nr
extension and match the package names. For example, if the package name ishesabu
, the corresponding file name should behesabu.nr
. -
You can directly import the
hesabu.nr
package and any required third-party packages in your Nuru code using thetumia
keyword. For example:tumia "hesabu"
Example of calling the package methods:
andika(hesabu.e())
This package covers a wide range of mathematical operations, including basic arithmetic
, trigonometry
, exponential and logarithmic functions
, rounding and comparison operations
, as well as some utility and array operations
.
The methods provided in the hesabu
package can be classified into different categories based on their functionalities. Here is a classification of the methods:
-
Trigonometric Functions:
cos(x)
sin(x)
tan(x)
acos(x)
asin(x)
atan(x)
-
Hyperbolic Functions:
cosh(x)
sinh(x)
tanh(x)
acosh(x)
asinh(x)
atanh(x)
-
Exponential and Logarithmic Functions:
exp(x)
expm1(x)
log(x)
log10(x)
log1p(x)
-
Other Mathematical Functions:
abs(namba)
ceil(x)
floor(x)
sqrt(x)
cbrt(x)
root(x, n)
hypot(values)
factorial(n)
-
Rounding and Comparison Functions:
round(x, method)
max(numbers)
min(numbers)
-
Utility Functions:
sign(x)
isNegative(num)
isInteger(num)
getIntegerPart(num)
-
Array and List Operations:
list(first, last, interval)
reduce(iterator, callback, initialValue)
- PI: Represents the mathematical constant
π
. - e: Represents
Euler's Number
. - phi: Represents the
Golden Ratio
. - ln10: Represents the
natural logarithm of 10
. - ln2: Represents the
natural logarithm of 2
. - log10e: Represents the
base 10 logarithms
of Euler's number(e)
. - log2e: Represents the
base 2 logarithm
of Euler's number(e)
. - sqrt1_2: Represents the
square root
of1/2
. - sqrt2: Represents the
square root
of2
. - sqrt3: Represents the
square root
of3
. - sqrt5: Represents the
square root
of5
. - EPSILON: Represents a small value (2.220446049250313e-16).
-
abs(namba)
- Description: Calculates the absolute value of a number.
- Example:
hesabu.abs(-42)
returns42
.
-
acos(x)
- Description: Calculates the arccosine of a number.
- Example:
hesabu.acos(0.5)
returns1.0471975511965979
.
-
acosh(x)
- Description: Calculates the inverse hyperbolic cosine of a number.
- Example:
hesabu.acosh(2)
returns1.3169578969248166
.
-
asin(x)
- Description: Calculates the arcsine of a number using the Taylor series.
- Example:
hesabu.arcsin(0.5)
returns0.5235987755982989
.
-
asinh(x)
- Description: Calculates the inverse hyperbolic sine of a number.
- Example:
hesabu.arsinh(2)
returns1.4436354751788103
.
-
atan(x)
- Description: Calculates the arctangent of a number using the Taylor series.
- Example:
hesabu.atan(1)
returns0.7853981633974485
.
-
atan2(y, x)
- Description: Calculates the arctangent of the quotient of its arguments.
- Example:
hesabu.atan2(1, 1)
returns0.7853981633974483
.
-
atanh(x)
- Description: Calculates the inverse hyperbolic tangent of a number.
- Example:
hesabu.atanh(0.5)
returns0.5493061443340549
.
-
cbrt(x)
- Description: Calculates the cube root of a number.
- Example:
hesabu.cbrt(8)
returns2
.
-
root(x, n)
- Description: Calculates the nth root of a number using the Newton-Raphson method.
- Example:
hesabu.root(27, 3)
returns3
.
-
ceil(x)
- Description: Rounds up to the smallest integer greater than or equal to a given number.
- Example:
hesabu.ceil(4.3)
returns5
.
-
cos(x)
- Description: Calculates the cosine of an angle in radians using the Taylor series.
- Example:
hesabu.cos(5)
returns0.28366218546322464
.
-
cosh(x)
- Description: Calculates the hyperbolic cosine of a number.
- Example:
hesabu.cosh(5)
returns74.20994842490012
.
-
exp(x)
- Description: Calculates the value of Euler's number raised to the power of a given number.
- Example:
hesabu.exp(2)
returns7.389056098930649
.
-
expm1(x)
- Description: Calculates Euler's number raised to the power of a number minus 1.
- Example:
hesabu.expm1(1)
returns1.7182818284590455
.
-
floor(x)
- Description: Rounds down to the largest integer less than or equal to a given number.
- Example:
hesabu.floor(4.7)
returns4
.
-
hypot(values)
- Description: Calculates the square root of the sum of squares of the given values.
- Example:
hesabu.hypot([3, 4])
returns5
.
-
log(x)
- Description: Calculates the natural logarithm of a number.
- Example:
hesabu.log(2)
returns0.69314718056
.
-
log10(x)
- Description: Calculates the base 10 logarithm of a number.
- Example:
hesabu.log10(100)
returns1.9999999999573126
.
-
log1p(x)
- Description: Calculates the natural logarithm of 1 plus the given number.
- Example:
hesabu.log1p(1)
returns0.6931471805599451
.
-
log2(x)
- Description: Calculates the base 2 logarithm of a number.
- Example:
hesabu.log2(8)
returns3
.
-
max(numbers)
- Description: Finds the maximum value in a list of numbers.
- Example:
hesabu.max([4, 2, 9, 5])
returns9
.
-
min(numbers)
- Description: Finds the minimum value in a list of numbers.
- Example:
hesabu.min([4, 2, 9, 5])
returns2
.
-
round(x, method)
- Description: Rounds a number to the nearest integer using the specified method.
- supported methods:
- "rpi" (round to the nearest integer using the principle of rounding half to the nearest even)
- "rni" (round to the nearest integer using the principle of rounding half away from zero)
- "ri" (round to the nearest integer using the standard rounding method)
- An invalid method results in returning NaN (Not a Number)
- Example:
hesabu.round(4.6, "rpi")
returns5
.
-
sign(x)
- Description: Determines the sign of a number.
- Example:
hesabu.sign(-5)
returns-1
.
-
sin(x)
- Description: Calculates the sine of an angle in radians using the Taylor series.
- Example:
hesabu.sin(1)
returns0.8414709848078965
.
-
sinh(x)
- Description: Calculates the hyperbolic sine of a number.
- Example:
hesabu.sinh(0)
returns0
.
-
sqrt(x)
- Description: Calculates the square root of a number.
- Example:
hesabu.sqrt(4)
returns2
.
-
tan(x)
- Description: Calculates the tangent of an angle in radians.
- Example:
hesabu.tan(1)
returns1.557407724654902
.
-
tanh(x)
- Description: Calculates the hyperbolic tangent of a number.
- Example:
hesabu.tanh(0)
returns0
.
-
factorial(n)
- Description: Calculates the factorial of a number.
- Example:
hesabu.factorial(5)
returns120
.
-
isNegative(num)
- Description: Checks if a number is negative.
- Example:
hesabu.isNegative(-5)
returnskweli
.
-
isInteger(num)
- Description: Checks if a number is an integer.
- Example:
hesabu.isInteger(4.5)
returnssikweli
.
-
getIntegerPart(num)
- Description: Gets the integer part of a number.
- Example:
hesabu.getIntegerPart(4.5)
returns4
.
-
list(first, last, interval)
- Description: Creates a list of numbers with the specified interval between them.
- Example:
hesabu.list(1, 5, 1)
returns[1, 2, 3, 4]
.
-
reduce(iterator, callback, initialValue)
- Description: Reduces the elements of an array to a single value using a specified callback function.
- Example:
hesabu.reduce([1, 2, 3, 4], [callback function], 0)
fanya callback = unda(accumulator, currentValue){ rudisha accumulator + currentValue; } andika(hesabu.reduce([1, 2, 3, 4], callback, 0)) \\ returns 10.
Contributions to the pakeji hesabu
package are welcome. If you have any improvements or bug fixes, feel free to create a pull request.
This package is available under the MIT License. See the LICENSE file for more information.