Python cmath.isclose() နည်းလမ်း
ဥပမာ
ရှုပ်ထွေးသောတန်ဖိုးနှစ်ခု၏ နီးစပ်မှုကို နှိုင်းယှဉ်ပါ-
#Import cmath Library
import cmath
#compare the closeness of two
complex values using relative tolerance
print(cmath.isclose(10+5j,
10+5j))
print(cmath.isclose(10+5j, 10.01+5j))
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်း သည် cmath.isclose()
ရှုပ်ထွေးသောတန်ဖိုးနှစ်ခု နီးစပ်မှုရှိ၊ မရှိ စစ်ဆေးသည်။ ဤနည်းလမ်းသည် Boolean တန်ဖိုးကို ပြန်ပေးသည်- True
အကယ်၍ တန်ဖိုးများ နီးစပ်ပါက၊ သို့မဟုတ် ပါက False
.
ဤနည်းလမ်းသည် တန်ဖိုးများ နီးစပ်မှုရှိမရှိကို ကြည့်ရှုရန် ဆွေမျိုးသည်းခံမှု သို့မဟုတ် အကြွင်းမဲ့သော သည်းခံမှုကို အသုံးပြုသည်။
အကြံပြုချက်- တန်ဖိုးများကို နှိုင်းယှဉ်ရန် အောက်ပါဖော်မြူလာကို အသုံးပြုသည်-
abs(ab) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
အထားအသို
cmath.isclose(a, b, rel_tol = value, abs_tol = value)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
a | Required. The first value to check for closeness |
b | Required. The second value to check for closeness |
rel_tol = value | Optional. The relative tolerance. It is the maximum allowed difference between value a and b. Default value is 1e-09 |
abs_tol = value | Optional. The minimum absolute tolerance. It is used to compare values near 0. The value must be at least 0 |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | bool တန်ဖိုးတစ်ခု ။ True အကယ်၍ တန်ဖိုးများ နီးစပ်ပါက၊False |
---|---|
Python ဗားရှင်း- | ၃.၅ |
နောက်ထပ် ဥပမာများ
ဥပမာ
အကြွင်းမဲ့သည်းခံမှုကို သတ်မှတ်သည့် ရှုပ်ထွေးသောတန်ဖိုးနှစ်ခု၏ နီးကပ်မှုကို နှိုင်းယှဉ်ကြည့်ပါ-
#Import cmath Library
import cmath
#compare the closeness of two
complex values using absolute tolerance
print(cmath.isclose(10+5j, 10+5j,
abs_tol=0.005))
print(cmath.isclose(10+5j, 10.01+5j, abs_tol=0.005))