Skip to content

Commit a903eb7

Browse files
Docs: Add missing int and float methods and attributes
int: Add bit_length, bit_count, to_bytes, from_bytes, as_integer_ratio, is_integer, conjugate methods and real, imag, numerator, denominator attrs. float: Add is_integer, as_integer_ratio, hex, fromhex, conjugate, from_number methods and real, imag attributes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 06dfd4b commit a903eb7

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

docs/builtins/float.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ The `float` type represents floating-point numbers with fixed precision (64-bit
4343
| `math.ceil(x)` | O(1) | O(1) | Ceiling |
4444
| `math.trunc(x)` | O(1) | O(1) | Truncate |
4545

46+
## Instance Methods
47+
48+
| Method | Time | Space | Notes |
49+
|--------|------|-------|-------|
50+
| `is_integer()` | O(1) | O(1) | Check if float is whole number |
51+
| `as_integer_ratio()` | O(1) | O(1) | Returns exact (numerator, denominator) tuple |
52+
| `hex()` | O(1) | O(1) | Convert to hexadecimal string |
53+
| `fromhex(s)` | O(n) | O(1) | Class method; create float from hex string |
54+
| `conjugate()` | O(1) | O(1) | Returns self; complex number compatibility |
55+
| `from_number(x)` | O(1) | O(1) | Class method; convert number to float (Python 3.14+) |
56+
57+
## Numeric Attributes
58+
59+
| Attribute | Time | Notes |
60+
|-----------|------|-------|
61+
| `real` | O(1) | Returns self; real part |
62+
| `imag` | O(1) | Always 0.0; imaginary part |
63+
4664
## Common Operations
4765

4866
### Basic Arithmetic

docs/builtins/int.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@ The `int` type represents arbitrary precision integers. Python 3 has a single in
5454
| `repr(x)` | O(n) | O(n) | String representation |
5555
| `int(x)` | O(1) | O(1) | No-op if already int |
5656

57+
## Instance Methods
58+
59+
| Method | Time | Space | Notes |
60+
|--------|------|-------|-------|
61+
| `bit_length()` | O(1) | O(1) | Number of bits needed to represent value |
62+
| `bit_count()` | O(n) | O(1) | Count of 1 bits (popcount); Python 3.10+ |
63+
| `to_bytes(length, byteorder)` | O(n) | O(n) | Convert to bytes; n = length |
64+
| `from_bytes(bytes, byteorder)` | O(n) | O(n) | Class method; create int from bytes |
65+
| `as_integer_ratio()` | O(1) | O(1) | Returns (self, 1) tuple |
66+
| `is_integer()` | O(1) | O(1) | Always returns True for int |
67+
| `conjugate()` | O(1) | O(1) | Returns self; complex number compatibility |
68+
69+
## Numeric Attributes
70+
71+
| Attribute | Time | Notes |
72+
|-----------|------|-------|
73+
| `real` | O(1) | Returns self; real part |
74+
| `imag` | O(1) | Always 0; imaginary part |
75+
| `numerator` | O(1) | Returns self; for Rational interface |
76+
| `denominator` | O(1) | Always 1; for Rational interface |
77+
5778
## Common Operations
5879

5980
### Basic Arithmetic

0 commit comments

Comments
 (0)