Skip to content

Commit b3e91ac

Browse files
committed
document update & patch
- update document - optimize `master.mul` function - fix issue & bug in LuaJIT, Lua5.1 - fix issue on `media.sqrt` function - fix issue on `media.pow` function - fix issue on `media.decimallen` function - add & update type check - change `MEDIA_DEFAULT_SQRTROOT_TOLERANCE` option `MEDIA_DEFAULT_SQRTROOT_FRACT_LIMIT` - add parameter `self_changed` function `ads` and `unm` to choose function have to clone object or just change value - rewrite `media.exp` and this function has more accuracy
1 parent c95ab83 commit b3e91ac

13 files changed

Lines changed: 405 additions & 180 deletions

.doc/.assets/design.png

-104 KB
Binary file not shown.

.doc/.assets/image1.png

-100 KB
Loading

.doc/int.abs.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22

33
![https://github.com/SupTan85/int.lua](.assets/cover.svg)
44

5-
## function
5+
## Syntax & Usage
66

77
> [!NOTE]
8-
This function always set the sign of a number to positive.
8+
This function ensures the sign of a number is always positive by returning its magnitude.
99

10-
**Input type:**
11-
12-
- **x** -- [**int object**](type.intobj.md) only.
10+
```lua
11+
function int.abs(x, self_changed) -- Returns the absolute value of `x`.
12+
```
1313

14-
**Output type:**
14+
| Parameter | Type | Description |
15+
| :----------: | :------------------------------------ | :----------------------------------------------------------------------------------------------------------- |
16+
| x | [**int object**](type.intobj.md) only | Required. The value to calculate the absolute value of. |
17+
| self_changed | boolean (default: false) | Optional. Enable if you want to change the value in this object only.<br>(disable copy object for optimization) |
1518

16-
- [**int object**](type.intobj.md)
19+
**Return Value:**
1720

18-
```lua
19-
function int.abs(x) -- Returns the absolute value of `x`.
20-
```
21+
1. [**int object**](type.intobj.md)
2122

2223
**Example:**
2324

@@ -31,7 +32,7 @@ print(int.abs(y)) -- output: 12.3456
3132

3233
---
3334

34-
## methods
35+
## Methods
3536

3637
This feature lets you to call functions on an object.
3738

.doc/int.ceil.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# int.ceil
2+
3+
![https://github.com/SupTan85/int.lua](.assets/cover.svg)
4+
5+
## Syntax & Usage
6+
7+
> [!NOTE]
8+
This function returns the smallest integer value of the given number.\
9+
**When inputting negative numbers, the function will behave oppositely (ceil -> floor).**
10+
11+
```lua
12+
function int.ceil(x) -- Returns the smallest integer greater than or equal to `x`.
13+
```
14+
15+
| Parameter | Type | Description |
16+
| :-------: | :------------------------------------ | :------------------------------------------ |
17+
| x | [**int object**](type.intobj.md) only | Required. The value to be processed. |
18+
19+
**Return Value:**
20+
21+
1. [**int object**](type.intobj.md)
22+
23+
**Example:**
24+
25+
```lua
26+
local int = require("int") -- import module
27+
28+
local x, y = int.new("-12.2", "12.3456")
29+
print(int.ceil(x)) -- output: -12
30+
print(int.ceil(y)) -- output: 13
31+
```
32+
33+
---
34+
35+
## methods
36+
37+
This feature lets you to call functions on an object.
38+
39+
```lua
40+
local int = require("int") -- import module
41+
42+
local x, y = int.new("-12.2", "12.3456")
43+
print(x:ceil()) -- output: -12
44+
print(y:ceil()) -- output: 13
45+
```
46+
47+
> [!TIP]
48+
In this example, a function inside the object is called and returns the object itself as the input.
49+
50+
also you can do like this:
51+
52+
```lua
53+
local int = require("int") -- import module
54+
55+
local x, y = int.new("-12.2", "12.3456")
56+
57+
-- this works like "print(int.ceil(x))"
58+
print(y.ceil(x)) -- output: -12
59+
60+
-- this works like "print(int.ceil(y))"
61+
print(x.ceil(y, 2)) -- output: 13
62+
```
63+
64+
> [!TIP]
65+
In this example, a function inside the object is called but a different object is used as the input.
66+
67+
---
68+
69+
[**function & methods**](../README.md#function--methods)
70+
71+
![end](.assets/bar.svg)

.doc/int.cnew.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22

33
![https://github.com/SupTan85/int.lua](.assets/cover.svg)
44

5-
## function
5+
## Syntax & Usage
66

77
> [!NOTE]
88
**Information:** This function creates an [**int object**](type.intobj.md) with a custom size per chunk.\
99
*It is recommended to use string type as "number" input, also you can input number type.*
1010

11-
**Input type:**
12-
13-
- **number** -- either a string or a number.
14-
- **size** -- number only. *"should be integer"*
15-
16-
**Output type:**
17-
18-
- [**int object**](type.intobj.md)
19-
2011
```lua
2112
function int.cnew(number, size) -- (number:string|number, size:string|number) For setting a size per chunk. **CHUNK SIZE SHOULD BE SAME WHEN CALCULATE**
2213
```
2314

15+
| Parameter | Type | Description |
16+
| :-------: | :-------------------------- | :----------------------------------------------------------------------- |
17+
| number | either a string or a number | Required. The value to be converted to [**int object**](type.intobj.md). |
18+
| size | number only (integer) | Optional. A number for registy chunky size. |
19+
2420
> [!IMPORTANT]
25-
**What does "size per chunk" mean?**\
21+
**What does "chunk size" mean?**\
2622
It refers to how a module calculates or stores numbers. Specifically, it saves numbers inside an [**int object**](type.intobj.md), divided into chunks or indexes, to avoid reaching numerical limits. If the "size per chunk" is larger, calculations can be faster and more efficient, allowing the system to handle more data. However, using a smaller "size per chunk" may lead to instability in some functions that check the length of number inside object, and **maximum of size per chunk is 9 (in default setting) & Should be integer.**
2723

24+
**Return Value:**
25+
26+
1. [**int object**](type.intobj.md)
27+
2828
**Example:**
2929

3030
```lua

.doc/int.floor.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
![https://github.com/SupTan85/int.lua](.assets/cover.svg)
44

5-
## function
5+
## Syntax & Usage
66

77
> [!NOTE]
8-
This function returns the largest integral value of the given number. However, you can custom it.\
9-
*When inputting negative numbers, the function will behave oppositely (floor -> ceil).*
8+
This function returns the integral value without decimal of the given number, while you can custom decimal places in same time.\
9+
**When inputting negative numbers, the function will behave oppositely (floor -> ceil).**
1010

11-
**Input type:**
12-
13-
- **x** -- [**int object**](type.intobj.md) only.
14-
- **length** -- number only.
11+
```lua
12+
function int.floor(x, length) -- Returns the largest integer less than or equal to `x`, optionally truncated to `length` decimal places.
13+
```
1514

16-
**Output type:**
15+
| Parameter | Type | Description |
16+
| :-------: | :------------------------------------ | :------------------------------------------ |
17+
| x | [**int object**](type.intobj.md) only | Required. The value to be processed. |
18+
| length | number only (integer) | Required. Number of decimal places to keep. |
1719

18-
- [**int object**](type.intobj.md)
20+
**Return Value:**
1921

20-
```lua
21-
function int.floor(x, length) -- Returns the largest integral value smaller than or equal to `x`, or Custom a `x` fraction.
22-
```
22+
1. [**int object**](type.intobj.md)
2323

2424
**Example:**
2525

.doc/int.new.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
![https://github.com/SupTan85/int.lua](.assets/cover.svg)
44

5-
## function
5+
## Syntax & Usage
66

77
> [!NOTE]
88
The [**int object**](../README.md#int-object) is represented as a table in Lua, designed for calculation purposes within the int module. This table includes numerical data and calculation-related information, and it supports a metatable to facilitate ease of use.
99

10-
**Input type:**
10+
```lua
11+
function int.new(...) -- (string|number) For only create. alway use default size! **CHUNK SIZE SHOULD BE SAME WHEN CALCULATE**
12+
```
13+
14+
**Parameter:**
1115

1216
- [**arg(...)**](type.vararg.md) -- either a string or a number.
1317

14-
**Output type:**
18+
**Return Value:**
1519

1620
- [**int object**](type.intobj.md)
1721

18-
```lua
19-
function int.new(...) -- (string|number) For only create. alway use default size! **CHUNK SIZE SHOULD BE SAME WHEN CALCULATE**
20-
```
21-
2222
**Example:**
2323

2424
```lua

.doc/int.tonumber.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![https://github.com/SupTan85/int.lua](.assets/cover.svg)
44

5-
## function
5+
## Syntax & Usage
66

77
> [!NOTE]
88
This function converts an [**int object**](type.intobj.md) to number.
@@ -11,18 +11,18 @@ This function converts an [**int object**](type.intobj.md) to number.
1111
We do **not recommend** using this function with large numbers, because they may be represented in scientific notation or lose precision.<br>
1212
please use [**tostring**](int.tostring.md) instead of tonumber!
1313

14-
**Input type:**
15-
16-
- **x** -- [**int object**](type.intobj.md) only.
17-
18-
**Output type:**
19-
20-
- **number**
21-
2214
```lua
2315
function int.tonumber(x) -- Deconvert table to number. *not recommend*
2416
```
2517

18+
| Parameter | Type | Description |
19+
| :-------: | :------------------------------------ | :-------------------------------------------------- |
20+
| x | [**int object**](type.intobj.md) only | Required. The object to be converted to **number**. |
21+
22+
**Return Value:**
23+
24+
1. **number**
25+
2626
**Example:**
2727

2828
```lua

.doc/int.tostring.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
![https://github.com/SupTan85/int.lua](.assets/cover.svg)
44

5-
## function
5+
## Syntax & Usage
66

77
> [!NOTE]
88
This function converts an [**int object**](type.intobj.md) to number but on string type, to handle a large number.
99

10-
**Input type:**
11-
12-
- **x** -- [**int object**](type.intobj.md) only.
13-
14-
**Output type:**
15-
16-
- **string**
17-
1810
```lua
1911
function int.tostring(x) -- Deconvert table to string.
2012
```
2113

14+
| Parameter | Type | Description |
15+
| :-------: | :------------------------------------ | :-------------------------------------------------- |
16+
| x | [**int object**](type.intobj.md) only | Required. The object to be converted to **string**. |
17+
18+
**Return Value:**
19+
20+
1. **string**
21+
2222
**Example:**
2323

2424
```lua

.doc/int.unm.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22

33
![https://github.com/SupTan85/int.lua](.assets/cover.svg)
44

5-
## function
5+
## Syntax & Usage
66

77
> [!NOTE]
8-
This function is made for a **unary operator**, so it reverses the sign of a number.
8+
This function handles the **unary minus operator**, it negates the value of the given number.
99

10-
**Input type:**
11-
12-
- **x** -- [**int object**](type.intobj.md) only.
10+
```lua
11+
function int.unm(x, self_changed) -- reverses the sign.
12+
```
1313

14-
**Output type:**
14+
| Parameter | Type | Description |
15+
| :----------: | :------------------------------------ | :----------------------------------------------------------------------------------------------------------- |
16+
| x | [**int object**](type.intobj.md) only | Required. The value whose sign will be reversed. |
17+
| self_changed | boolean (default: false) | Optional. Enable if you want to change the value in this object only.<br>(disable copy object for optimization) |
1518

16-
- [**int object**](type.intobj.md)
19+
**Return Value:**
1720

18-
```lua
19-
function int.unm(x) -- reverses the sign.
20-
```
21+
1. [**int object**](type.intobj.md)
2122

2223
**Example:**
2324

0 commit comments

Comments
 (0)