Skip to content

Commit 25b4c0e

Browse files
authored
Merge branch 'main' into support-string-repeat-with-non-constant-integer
2 parents ea7ce9c + 3ccdfdb commit 25b4c0e

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

doc/src/built-in functions.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Built-in Functions
2+
3+
LPython has a variety of functions and types built into it that are always available.
4+
5+
### abs(x)
6+
7+
- **Parameter**
8+
- x : integer (i8, i16, i32, i64), floating point number (f32, f64), complex number (c32, c64) or bool
9+
- **Returns** : integer (i8, i16, i32, i64), floating point number (f32, f64)
10+
11+
Returns the absolute value of a number. If the argument is a complex number, its magnitude is returned.
12+
13+
14+
### bin(n)
15+
16+
- **Parameters**
17+
- n : integer (i32)
18+
- **Returns** : str
19+
20+
Returns the binary representation of n as a '0b' prefixed string.
21+
22+
23+
### complex(x=0, y=0)
24+
25+
- **Parameters**
26+
- x : integer (i32, i64) or floating point number (f32, f64)
27+
- y : integer (i32, i64) or floating point number (f32, f64)
28+
- **Returns** : complex number (c32, c64)
29+
30+
Returns a complex number with the provided real and imaginary parts. Both x and y should be of the same type. However, using both the 32-bit and 64-bit versions of the same type together is allowed. In that case, the returned complex number is of 64-bit type.
31+
32+
Example:
33+
34+
```python
35+
real: i32 = 10
36+
imag: i64 = 22
37+
c: c64 = complex(real, imag)
38+
```
39+
40+
### divmod(x, y)
41+
42+
- **Parameters**
43+
- x : integer (i32)
44+
- y : integer (i32)
45+
- **Returns** : tuple[i32, i32]
46+
47+
Returns the tuple (x // y, x % y).
48+
49+
50+
### exp(x)
51+
52+
- ****Parameter****
53+
- x : floating point number (f32, f64)
54+
- **Returns** : floating point number (f32, f64) between [0.0, inf]
55+
56+
Returns the base-e exponential of x (e<sup>x</sup>), where e is the Euler's number (2.71828). For a very large output, the function returns **inf** indicating overflow.
57+
58+
59+
### hex(n)
60+
61+
- **Parameters**
62+
- n : integer (i32)
63+
- **Returns** : str
64+
65+
Returns the hexadecimal representation of n as a '0x' prefixed string.
66+
67+
68+
### len(s)
69+
70+
- **Parameters**
71+
- s : sequence (such as string, tuple, list or range) or collection (such as a dictionary or set)
72+
- **Returns** : integer (i32)
73+
74+
Returns the number of items present in an object.
75+
76+
77+
### max(x, y)
78+
79+
- **Parameters**
80+
- x : integer (i32) or floating point number (f64)
81+
- y : integer (i32) or floating point number (f64)
82+
- **Returns** : integer (i32) or floating point number (f64)
83+
84+
Returns the greater value between x and y. Both x and y should be of the same type.
85+
86+
87+
### min(x, y)
88+
89+
- **Parameters**
90+
- x : integer (i32) or floating point number (f64)
91+
- y : integer (i32) or floating point number (f64)
92+
- **Returns** : integer (i32) or floating point number (f64)
93+
94+
Returns the smaller value between x and y. Both x and y should be of the same type.
95+
96+
97+
### mod(x, y)
98+
99+
- **Parameters**
100+
- x : integer (i32, i64) or floating point number (f32, f64)
101+
- y : integer (i32, i64) or floating point number (f32, f64)
102+
- **Returns** : integer (i32, i64) or floating point number (f32, f64)
103+
104+
Returns the remainder of x / y, or x when x is smaller than y. Both x and y should be of the same type.
105+
106+
107+
### pow(x, y)
108+
109+
- **Parameters**
110+
- x : integer (i32, i64), floating point number (f32, f64), complex number (c32) or bool
111+
- y: integer (i32, i64), floating point number (f32, f64) or bool
112+
- **Returns** : integer (i32), floating point number (f32, f64) or a complex number
113+
114+
Returns x<sup>y</sup>. When x is of type bool, y must also be of the same type. If x is 32-bit complex number (c32), y can only be a 32-bit integer (i32).
115+
116+
**Note** : `x ** y` is the recommended method for doing the above calculation.
117+
118+
119+
### round(x)
120+
121+
- **Parameters**
122+
- x : integer (i8, i16, i32, i64), floating point number (f32, f64) or bool
123+
- **Returns** : integer (i8, i16, i32, i64)
124+
125+
Returns the integer nearest to x.
126+
127+
128+
### sum(arr)
129+
130+
- **Parameters**
131+
- arr : list of integers (list[i32], list[i64]) or floating point numbers (list[i32], list[f64])
132+
- **Returns** : integer (i32, i64) or floating point number (f32, f64)
133+
134+
Returns the sum of all elements present in the list.
135+
136+
137+
### oct(n)
138+
139+
- **Parameters**
140+
- n : integer (i32)
141+
- **Returns** : str
142+
143+
Returns the octal representation of n as a '0o' prefixed string.
144+
145+
146+
147+

expr

-15.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)