Daftar Referensi Python
math.frexp() memecah float menjadi mantissa m dan eksponen e sehingga x = m * 2**e.
Sintaks
math.frexp(x)
Parameter
| Parameter | Wajib? | Keterangan |
|---|---|---|
x |
Ya | Nilai numerik |
Nilai balik: tuple (mantissa, exponent).
Contoh
import math
print(math.frexp(10))
Output:
(0.625, 4)
Contoh Lainnya
Nilai nol
import math
print(math.frexp(0))
Output:
(0.0, 0)
Nilai negatif
import math
print(math.frexp(-8))
Output:
(-0.5, 4)
Menyusun kembali
import math
m, e = math.frexp(10)
print(math.ldexp(m, e))
Output:
10.0
Kesalahan Umum
- Hasil mantissa untuk nilai nonnol memiliki magnitude antara 0.5 dan 1.
- Hasil eksponen berupa integer.
- Gunakan
math.ldexp()untuk operasi kebalikannya.
Pelajari Lebih Lanjut
- Referensi: math.ldexp() · math.isfinite() · float()
- Buku Belajar Python untuk Pemula: Bab 16
