Skip to content

Commit 189b496

Browse files
Remove out of scope docs, and clarify minor areas
1 parent 0bae691 commit 189b496

3 files changed

Lines changed: 4 additions & 79 deletions

File tree

docs/builtins/float.md

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -103,67 +103,6 @@ if x < y + 0.001: # O(1)
103103
pass
104104
```
105105

106-
## Precision and Limitations
107-
108-
### Fixed 64-bit Precision
109-
110-
```python
111-
# IEEE 754 double precision (64 bits)
112-
# - 1 sign bit
113-
# - 11 exponent bits (range ~10^-308 to 10^308)
114-
# - 52 mantissa bits (~15-17 decimal digits precision)
115-
116-
x = 0.1 + 0.2
117-
print(x == 0.3) # False! Precision loss
118-
119-
# Representation
120-
print(f"{x:.20f}") # 0.30000000000000004443
121-
```
122-
123-
### Avoiding Precision Issues
124-
125-
```python
126-
from decimal import Decimal
127-
128-
# Use Decimal for financial calculations
129-
price = Decimal('0.10')
130-
tax = Decimal('0.20')
131-
total = price + tax # Exact: 0.30
132-
133-
# Use math.isclose for float comparisons
134-
import math
135-
x = 0.1 + 0.2
136-
if math.isclose(x, 0.3): # Accounts for precision
137-
print("Equal within tolerance")
138-
```
139-
140-
## Special Float Values
141-
142-
| Value | Representation | Notes |
143-
|-------|-----------------|-------|
144-
| Positive infinity | `float('inf')` | Larger than any number |
145-
| Negative infinity | `float('-inf')` | Smaller than any number |
146-
| Not a Number | `float('nan')` | Unordered, `nan != nan` |
147-
| Zero | `0.0` or `-0.0` | Two representations |
148-
149-
```python
150-
import math
151-
152-
x = float('inf')
153-
y = float('nan')
154-
155-
# Infinity operations
156-
print(x + 100) # inf
157-
print(x - x) # nan (indeterminate)
158-
print(x / x) # nan
159-
160-
# NaN behavior - unordered
161-
print(math.isnan(y)) # True
162-
print(y == y) # False (NaN != NaN always)
163-
print(y < 5) # False (unordered)
164-
print(y > 5) # False (unordered)
165-
```
166-
167106
## Performance Characteristics
168107

169108
### Fixed-size Operations
@@ -212,20 +151,6 @@ for i in range(1000000):
212151
- **[Decimal](../stdlib/decimal.md)** - Arbitrary precision decimal
213152
- **[Fraction](../stdlib/fractions.md)** - Rational numbers
214153

215-
## Best Practices
216-
217-
**Do**:
218-
219-
- Use `float` for general numerical computation
220-
- Use `math.isclose()` for float comparisons
221-
- Use `round()` for display, not comparison
222-
223-
**Avoid**:
224-
225-
- Comparing floats with `==` directly
226-
- Assuming decimal representation is exact
227-
- Using floats for financial calculations (use `Decimal`)
228-
229154
## Further Reading
230155

231156
- [CPython Internals: float](https://zpoint.github.io/CPython-Internals/BasicObject/float/float.html) -

docs/builtins/int.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ a = 100
146146
b = 100
147147
print(a is b) # True - same object!
148148

149-
# Large integers use arbitrary precision
150-
x = 10**1000
151-
y = 10**1000
149+
# Large integers not cached
150+
x = 300
151+
y = 300
152152
print(x is y) # False - different objects
153153
```
154154

docs/builtins/str.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ for word in words:
172172
result = "".join(words)
173173

174174
# Also good: list comprehension with join
175-
result = "".join(w.upper() for w in words)
175+
result = "".join([w.upper() for w in words])
176176
```
177177

178178
### String Formatting

0 commit comments

Comments
 (0)