|
1 |
| -# Pakeji Hisabati (Math Package) |
| 1 | +# Pakeji Hesabu (Math Package) |
2 | 2 |
|
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). |
4 | 4 |
|
5 | 5 | 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`.
|
6 | 6 |
|
7 | 7 |
|
8 | 8 | ## Usage
|
9 |
| -To use the `pakeji hisabati` package follow the steps below: |
| 9 | +To use the `pakeji hesabu` package follow the steps below: |
10 | 10 |
|
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. |
12 | 12 |
|
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`. |
14 | 14 |
|
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: |
16 | 16 |
|
17 | 17 | ```nuru
|
18 |
| - tumia "hisabati" |
| 18 | + tumia "hesabu" |
19 | 19 | ```
|
20 | 20 | Example of calling the package methods:
|
21 | 21 | ```nuru
|
22 |
| - andika(hisabati.e()) |
| 22 | + andika(hesabu.e()) |
23 | 23 | ## What is in
|
24 | 24 | 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`.
|
25 | 25 |
|
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: |
27 | 27 |
|
28 | 28 | 1. Trigonometric Functions:
|
29 | 29 | - `cos(x)`
|
@@ -92,152 +92,161 @@ The methods provided in the `hisabati` package can be classified into different
|
92 | 92 |
|
93 | 93 | 1. **abs(namba)**
|
94 | 94 | - Description: Calculates the absolute value of a number.
|
95 |
| - - Example: `hisabati.abs(-42)` returns `42`. |
| 95 | + - Example: `hesabu.abs(-42)` returns `42`. |
96 | 96 |
|
97 | 97 | 2. **acos(x)**
|
98 | 98 | - 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`. |
100 | 100 |
|
101 | 101 | 3. **acosh(x)**
|
102 | 102 | - 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`. |
104 | 104 |
|
105 |
| -4. **arcsin(x)** |
| 105 | +4. **asin(x)** |
106 | 106 | - 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`. |
108 | 108 |
|
109 |
| -5. **arsinh(x)** |
| 109 | +5. **asinh(x)** |
110 | 110 | - 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`. |
112 | 112 |
|
113 | 113 | 6. **atan(x)**
|
114 | 114 | - 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`. |
116 | 116 |
|
117 | 117 | 7. **atan2(y, x)**
|
118 | 118 | - 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`. |
120 | 120 |
|
121 | 121 | 8. **atanh(x)**
|
122 | 122 | - 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`. |
124 | 124 |
|
125 | 125 | 9. **cbrt(x)**
|
126 | 126 | - Description: Calculates the cube root of a number.
|
127 |
| - - Example: `hisabati.cbrt(8)` returns `2`. |
| 127 | + - Example: `hesabu.cbrt(8)` returns `2`. |
128 | 128 |
|
129 | 129 | 10. **root(x, n)**
|
130 | 130 | - 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`. |
132 | 132 |
|
133 | 133 | 11. **ceil(x)**
|
134 | 134 | - 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`. |
136 | 136 |
|
137 | 137 | 12. **cos(x)**
|
138 | 138 | - 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`. |
140 | 140 |
|
141 | 141 | 13. **cosh(x)**
|
142 | 142 | - Description: Calculates the hyperbolic cosine of a number.
|
143 |
| - - Example: `hisabati.cosh(0)` returns `1`. |
| 143 | + - Example: `hesabu.cosh(5)` returns `74.20994842490012`. |
144 | 144 |
|
145 | 145 | 14. **exp(x)**
|
146 | 146 | - 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`. |
148 | 148 |
|
149 | 149 | 15. **expm1(x)**
|
150 | 150 | - 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`. |
152 | 152 |
|
153 | 153 | 16. **floor(x)**
|
154 | 154 | - 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`. |
156 | 156 |
|
157 | 157 | 17. **hypot(values)**
|
158 | 158 | - 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`. |
160 | 160 |
|
161 | 161 | 18. **log(x)**
|
162 | 162 | - Description: Calculates the natural logarithm of a number.
|
163 |
| - - Example: `hisabati.log(1)` returns `0`. |
| 163 | + - Example: `hesabu.log(2)` returns `0.69314718056`. |
164 | 164 |
|
165 | 165 | 19. **log10(x)**
|
166 | 166 | - Description: Calculates the base 10 logarithm of a number.
|
167 |
| - - Example: `hisabati.log10(100)` returns `2`. |
| 167 | + - Example: `hesabu.log10(100)` returns `1.9999999999573126`. |
168 | 168 |
|
169 | 169 | 20. **log1p(x)**
|
170 | 170 | - 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`. |
172 | 172 |
|
173 | 173 | 21. **log2(x)**
|
174 | 174 | - Description: Calculates the base 2 logarithm of a number.
|
175 |
| - - Example: `hisabati.log2(8)` returns `3`. |
| 175 | + - Example: `hesabu.log2(8)` returns `3`. |
176 | 176 |
|
177 | 177 | 22. **max(numbers)**
|
178 | 178 | - 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`. |
180 | 180 |
|
181 | 181 | 23. **min(numbers)**
|
182 | 182 | - 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`. |
184 | 184 |
|
185 | 185 | 24. **round(x, method)**
|
186 | 186 | - 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`. |
188 | 193 |
|
189 | 194 | 25. **sign(x)**
|
190 | 195 | - Description: Determines the sign of a number.
|
191 |
| - - Example: `hisabati.sign(-5)` returns `-1`. |
| 196 | + - Example: `hesabu.sign(-5)` returns `-1`. |
192 | 197 |
|
193 | 198 | 26. **sin(x)**
|
194 | 199 | - 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`. |
196 | 201 |
|
197 | 202 | 27. **sinh(x)**
|
198 | 203 | - Description: Calculates the hyperbolic sine of a number.
|
199 |
| - - Example: `hisabati.sinh(0)` returns `0`. |
| 204 | + - Example: `hesabu.sinh(0)` returns `0`. |
200 | 205 |
|
201 | 206 | 28. **sqrt(x)**
|
202 | 207 | - Description: Calculates the square root of a number.
|
203 |
| - - Example: `hisabati.sqrt(4)` returns `2`. |
| 208 | + - Example: `hesabu.sqrt(4)` returns `2`. |
204 | 209 |
|
205 | 210 | 29. **tan(x)**
|
206 | 211 | - Description: Calculates the tangent of an angle in radians.
|
207 |
| - - Example: `hisabati.tan(0)` returns `0`. |
| 212 | + - Example: `hesabu.tan(1)` returns `1.557407724654902`. |
208 | 213 |
|
209 | 214 | 30. **tanh(x)**
|
210 | 215 | - Description: Calculates the hyperbolic tangent of a number.
|
211 |
| - - Example: `hisabati.tanh(0)` returns `0`. |
| 216 | + - Example: `hesabu.tanh(0)` returns `0`. |
212 | 217 |
|
213 | 218 | 31. **factorial(n)**
|
214 | 219 | - Description: Calculates the factorial of a number.
|
215 |
| - - Example: `hisabati.factorial(5)` returns `120`. |
| 220 | + - Example: `hesabu.factorial(5)` returns `120`. |
216 | 221 |
|
217 | 222 | 32. **isNegative(num)**
|
218 | 223 | - Description: Checks if a number is negative.
|
219 |
| - - Example: `hisabati.isNegative(-5)` returns `true`. |
| 224 | + - Example: `hesabu.isNegative(-5)` returns `kweli`. |
220 | 225 |
|
221 | 226 | 33. **isInteger(num)**
|
222 | 227 | - Description: Checks if a number is an integer.
|
223 |
| - - Example: `hisabati.isInteger(4.5)` returns `false`. |
| 228 | + - Example: `hesabu.isInteger(4.5)` returns `sikweli`. |
224 | 229 |
|
225 | 230 | 34. **getIntegerPart(num)**
|
226 | 231 | - Description: Gets the integer part of a number.
|
227 |
| - - Example: `hisabati.getIntegerPart(4.5)` returns `4`. |
| 232 | + - Example: `hesabu.getIntegerPart(4.5)` returns `4`. |
228 | 233 |
|
229 | 234 | 35. **list(first, last, interval)**
|
230 | 235 | - 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]`. |
232 | 237 |
|
233 | 238 | 36. **reduce(iterator, callback, initialValue)**
|
234 | 239 | - 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 | + } |
237 | 245 |
|
| 246 | + andika(hesabu.reduce([1, 2, 3, 4], callback, 0)) \\ returns 10. |
238 | 247 | ### Contributing
|
239 | 248 |
|
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. |
241 | 250 |
|
242 | 251 | ### License
|
243 | 252 |
|
|
0 commit comments