Skip to content

Commit d0ea599

Browse files
author
Victor kariuki
committed
renamed hisabati package
fixed bugs used hisabati module for constants added a test file for hesabu package update hesabu package documentation
1 parent 90c0c6f commit d0ea599

File tree

3 files changed

+222
-245
lines changed

3 files changed

+222
-245
lines changed

third_party/math/README.md

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# Pakeji Hisabati (Math Package)
1+
# Pakeji Hesabu (Math Package)
22

3-
Pakeji Hisabati is a math package written in pure Nuru by [VictorKariuki](https://github.com/VictorKariuki).
3+
Pakeji Hesabu is a math package written in pure Nuru by [VictorKariuki](https://github.com/VictorKariuki).
44

55
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`.
66

77

88
## Usage
9-
To use the `pakeji hisabati` package follow the steps below:
9+
To use the `pakeji hesabu` package follow the steps below:
1010

11-
1. Copy the `hisabati.nr` file and any required third-party package files into the same directory as your project.
11+
1. Copy the `hesabu.nr` file and any required third-party package files into the same directory as your project.
1212

13-
2. Ensure that the package file names end with the `.nr` extension and match the package names. For example, if the package name is `hisabati`, the corresponding file name should be `hisabati.nr`.
13+
2. Ensure that the package file names end with the `.nr` extension and match the package names. For example, if the package name is `hesabu`, the corresponding file name should be `hesabu.nr`.
1414

15-
3. You can directly import the `hisabati.nr` package and any required third-party packages in your Nuru code using the `tumia` keyword. For example:
15+
3. You can directly import the `hesabu.nr` package and any required third-party packages in your Nuru code using the `tumia` keyword. For example:
1616

1717
```nuru
18-
tumia "hisabati"
18+
tumia "hesabu"
1919
```
2020
Example of calling the package methods:
2121
```nuru
22-
andika(hisabati.e())
22+
andika(hesabu.e())
2323
## What is in
2424
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`.
2525
26-
The methods provided in the `hisabati` package can be classified into different categories based on their functionalities. Here is a classification of the methods:
26+
The methods provided in the `hesabu` package can be classified into different categories based on their functionalities. Here is a classification of the methods:
2727
2828
1. Trigonometric Functions:
2929
- `cos(x)`
@@ -92,152 +92,161 @@ The methods provided in the `hisabati` package can be classified into different
9292
9393
1. **abs(namba)**
9494
- Description: Calculates the absolute value of a number.
95-
- Example: `hisabati.abs(-42)` returns `42`.
95+
- Example: `hesabu.abs(-42)` returns `42`.
9696
9797
2. **acos(x)**
9898
- Description: Calculates the arccosine of a number.
99-
- Example: `hisabati.acos(0.5)` returns `1.0471975511965979`.
99+
- Example: `hesabu.acos(0.5)` returns `1.0471975511965979`.
100100
101101
3. **acosh(x)**
102102
- Description: Calculates the inverse hyperbolic cosine of a number.
103-
- Example: `hisabati.acosh(2)` returns `1.3169578969248166`.
103+
- Example: `hesabu.acosh(2)` returns `1.3169578969248166`.
104104
105-
4. **arcsin(x)**
105+
4. **asin(x)**
106106
- Description: Calculates the arcsine of a number using the Taylor series.
107-
- Example: `hisabati.arcsin(0.5)` returns `0.5235987755982988`.
107+
- Example: `hesabu.arcsin(0.5)` returns `0.5235987755982989`.
108108
109-
5. **arsinh(x)**
109+
5. **asinh(x)**
110110
- Description: Calculates the inverse hyperbolic sine of a number.
111-
- Example: `hisabati.arsinh(2)` returns `1.4436354751788103`.
111+
- Example: `hesabu.arsinh(2)` returns `1.4436354751788103`.
112112
113113
6. **atan(x)**
114114
- Description: Calculates the arctangent of a number using the Taylor series.
115-
- Example: `hisabati.atan(1)` returns `0.7853981633974483`.
115+
- Example: `hesabu.atan(1)` returns `0.7853981633974485`.
116116
117117
7. **atan2(y, x)**
118118
- Description: Calculates the arctangent of the quotient of its arguments.
119-
- Example: `hisabati.atan2(1, 1)` returns `0.7853981633974483`.
119+
- Example: `hesabu.atan2(1, 1)` returns `0.7853981633974483`.
120120
121121
8. **atanh(x)**
122122
- Description: Calculates the inverse hyperbolic tangent of a number.
123-
- Example: `hisabati.atanh(0.5)` returns `0.5493061443340549`.
123+
- Example: `hesabu.atanh(0.5)` returns `0.5493061443340549`.
124124
125125
9. **cbrt(x)**
126126
- Description: Calculates the cube root of a number.
127-
- Example: `hisabati.cbrt(8)` returns `2`.
127+
- Example: `hesabu.cbrt(8)` returns `2`.
128128
129129
10. **root(x, n)**
130130
- Description: Calculates the nth root of a number using the Newton-Raphson method.
131-
- Example: `hisabati.root(27, 3)` returns `3`.
131+
- Example: `hesabu.root(27, 3)` returns `3`.
132132
133133
11. **ceil(x)**
134134
- Description: Rounds up to the smallest integer greater than or equal to a given number.
135-
- Example: `hisabati.ceil(4.3)` returns `5`.
135+
- Example: `hesabu.ceil(4.3)` returns `5`.
136136
137137
12. **cos(x)**
138138
- Description: Calculates the cosine of an angle in radians using the Taylor series.
139-
- Example: `hisabati.cos(0)` returns `1`.
139+
- Example: `hesabu.cos(5)` returns `0.28366218546322464`.
140140
141141
13. **cosh(x)**
142142
- Description: Calculates the hyperbolic cosine of a number.
143-
- Example: `hisabati.cosh(0)` returns `1`.
143+
- Example: `hesabu.cosh(5)` returns `74.20994842490012`.
144144
145145
14. **exp(x)**
146146
- Description: Calculates the value of Euler's number raised to the power of a given number.
147-
- Example: `hisabati.exp(2)` returns `7.38905609893065`.
147+
- Example: `hesabu.exp(2)` returns `7.389056098930649`.
148148
149149
15. **expm1(x)**
150150
- Description: Calculates Euler's number raised to the power of a number minus 1.
151-
- Example: `hisabati.expm1(1)` returns `1.718281828459045`.
151+
- Example: `hesabu.expm1(1)` returns `1.7182818284590455`.
152152
153153
16. **floor(x)**
154154
- Description: Rounds down to the largest integer less than or equal to a given number.
155-
- Example: `hisabati.floor(4.7)` returns `4`.
155+
- Example: `hesabu.floor(4.7)` returns `4`.
156156
157157
17. **hypot(values)**
158158
- Description: Calculates the square root of the sum of squares of the given values.
159-
- Example: `hisabati.hypot([3, 4])` returns `5`.
159+
- Example: `hesabu.hypot([3, 4])` returns `5`.
160160
161161
18. **log(x)**
162162
- Description: Calculates the natural logarithm of a number.
163-
- Example: `hisabati.log(1)` returns `0`.
163+
- Example: `hesabu.log(2)` returns `0.69314718056`.
164164
165165
19. **log10(x)**
166166
- Description: Calculates the base 10 logarithm of a number.
167-
- Example: `hisabati.log10(100)` returns `2`.
167+
- Example: `hesabu.log10(100)` returns `1.9999999999573126`.
168168
169169
20. **log1p(x)**
170170
- Description: Calculates the natural logarithm of 1 plus the given number.
171-
- Example: `hisabati.log1p(1)` returns `0.6931471805599453`.
171+
- Example: `hesabu.log1p(1)` returns `0.6931471805599451`.
172172
173173
21. **log2(x)**
174174
- Description: Calculates the base 2 logarithm of a number.
175-
- Example: `hisabati.log2(8)` returns `3`.
175+
- Example: `hesabu.log2(8)` returns `3`.
176176
177177
22. **max(numbers)**
178178
- Description: Finds the maximum value in a list of numbers.
179-
- Example: `hisabati.max([4, 2, 9, 5])` returns `9`.
179+
- Example: `hesabu.max([4, 2, 9, 5])` returns `9`.
180180
181181
23. **min(numbers)**
182182
- Description: Finds the minimum value in a list of numbers.
183-
- Example: `hisabati.min([4, 2, 9, 5])` returns `2`.
183+
- Example: `hesabu.min([4, 2, 9, 5])` returns `2`.
184184
185185
24. **round(x, method)**
186186
- Description: Rounds a number to the nearest integer using the specified method.
187-
- Example: `hisabati.round(4.6, "rpi")` returns `5`.
187+
- supported methods:
188+
- "rpi" (round to the nearest integer using the principle of rounding half to the nearest even)
189+
- "rni" (round to the nearest integer using the principle of rounding half away from zero)
190+
- "ri" (round to the nearest integer using the standard rounding method)
191+
- An invalid method results in returning NaN (Not a Number)
192+
- Example: `hesabu.round(4.6, "rpi")` returns `5`.
188193
189194
25. **sign(x)**
190195
- Description: Determines the sign of a number.
191-
- Example: `hisabati.sign(-5)` returns `-1`.
196+
- Example: `hesabu.sign(-5)` returns `-1`.
192197
193198
26. **sin(x)**
194199
- Description: Calculates the sine of an angle in radians using the Taylor series.
195-
- Example: `hisabati.sin(0)` returns `0`.
200+
- Example: `hesabu.sin(1)` returns `0.8414709848078965`.
196201
197202
27. **sinh(x)**
198203
- Description: Calculates the hyperbolic sine of a number.
199-
- Example: `hisabati.sinh(0)` returns `0`.
204+
- Example: `hesabu.sinh(0)` returns `0`.
200205
201206
28. **sqrt(x)**
202207
- Description: Calculates the square root of a number.
203-
- Example: `hisabati.sqrt(4)` returns `2`.
208+
- Example: `hesabu.sqrt(4)` returns `2`.
204209
205210
29. **tan(x)**
206211
- Description: Calculates the tangent of an angle in radians.
207-
- Example: `hisabati.tan(0)` returns `0`.
212+
- Example: `hesabu.tan(1)` returns `1.557407724654902`.
208213
209214
30. **tanh(x)**
210215
- Description: Calculates the hyperbolic tangent of a number.
211-
- Example: `hisabati.tanh(0)` returns `0`.
216+
- Example: `hesabu.tanh(0)` returns `0`.
212217
213218
31. **factorial(n)**
214219
- Description: Calculates the factorial of a number.
215-
- Example: `hisabati.factorial(5)` returns `120`.
220+
- Example: `hesabu.factorial(5)` returns `120`.
216221
217222
32. **isNegative(num)**
218223
- Description: Checks if a number is negative.
219-
- Example: `hisabati.isNegative(-5)` returns `true`.
224+
- Example: `hesabu.isNegative(-5)` returns `kweli`.
220225
221226
33. **isInteger(num)**
222227
- Description: Checks if a number is an integer.
223-
- Example: `hisabati.isInteger(4.5)` returns `false`.
228+
- Example: `hesabu.isInteger(4.5)` returns `sikweli`.
224229
225230
34. **getIntegerPart(num)**
226231
- Description: Gets the integer part of a number.
227-
- Example: `hisabati.getIntegerPart(4.5)` returns `4`.
232+
- Example: `hesabu.getIntegerPart(4.5)` returns `4`.
228233
229234
35. **list(first, last, interval)**
230235
- Description: Creates a list of numbers with the specified interval between them.
231-
- Example: `hisabati.list(1, 5, 1)` returns `[1, 2, 3, 4]`.
236+
- Example: `hesabu.list(1, 5, 1)` returns `[1, 2, 3, 4]`.
232237
233238
36. **reduce(iterator, callback, initialValue)**
234239
- Description: Reduces the elements of an array to a single value using a specified callback function.
235-
- Example: `hisabati.reduce([1, 2, 3, 4], (accumulator, currentValue) => accumulator + currentValue, 0)` returns `10`.
236-
240+
- Example: `hesabu.reduce([1, 2, 3, 4], [callback function], 0)`
241+
```s
242+
fanya callback = unda(accumulator, currentValue){
243+
rudisha accumulator + currentValue;
244+
}
237245
246+
andika(hesabu.reduce([1, 2, 3, 4], callback, 0)) \\ returns 10.
238247
### Contributing
239248
240-
Contributions to the `pakeji hisabati` package are welcome. If you have any improvements or bug fixes, feel free to create a pull request.
249+
Contributions to the `pakeji hesabu` package are welcome. If you have any improvements or bug fixes, feel free to create a pull request.
241250
242251
### License
243252

0 commit comments

Comments
 (0)