Yini okufanele iyiphi? · bei.pm
Kule ndawo kukhona izindatshana ngezifomathi zamafayela kanye ne-Reverse Engineering.
Manje kubalulekile ukuqonda:
Kukhona izilimi eziningi zokuhlela kanye nabantu abaningi abazi izinto ezithile ngegama elihlukile - noma bangenalo nolwazi lokuba khona kwezinto ezisemqoka, ngoba ulimi lwabo lokuhlela luthathwa lwaphela.
tl;dr:
Ukuqopha kwami kuhlobene kakhulu ne-C99 <stdint.h>
. Osebenzisa le ndlela yokubhala angakwazi ukuqonda kahle ukuhlela kwami.
Inani
Integer zingama izinombolo eziphelele, okusho izinombolo ezingekho nezingxenye zokuphuma.
Izinhlelo ze-Integer ngokuvamile zichazwa kumafomethi wedatha ngaphakathi kwesikhala sezibalo esithile, okuyi "resolution". Lokhu ngikubeka ngendlela ye-Bit - ngenxa yokuthi "Byte" nezinhlobo ezisekelwe kuyo (Word, Qword, ...) ngokuvamile zihluke ngokusekelwe phezulu.
Futhi, uma kukhulunywa ngezinhlobo ze-Integer, kukhona ukuhlukaniswa phakathi izinombolo eziyinqaba (ℕ, okusho, ngaphandle kwezimpawu - Unsigned) kanye izinombolo eziphelele (ℤ, okusho, ezinempawu - Signed).
Lolu lwazi lungabonakala ngempawu kumqondisi (u
noma s
).
Kukhona nokwenzeka ukuthi izinombolo ezinezinhlamvu zingabekwa njenge Einerkomplement noma njenge Zweierkomplement.
Ngaphandle kokuthi kukhonjiswe okunye, Zweierkomplement iyasetshenziswa, ngoba iyindlela ethokozisayo ekwakhiweni kwedatha kwesimanje.
Izibalo ezingenazo izimpawu zikhonjiswa kimi emibhalweni yami njenge uint
, ngokuhambisana nokukhonjiswa kwe-accuracy nge Bits.
Izibalo ezinempawu zikhonjiswa kimi emibhalweni yami njenge sint
, futhi nazo zikhonjiswa nge-accuracy nge Bits.
Ngiyaqedwa ukusebenzisa uhlobo lwedatha "char" lwezimpawu, ngoba imigqa yezimpawu ngokuvamile imela kuphela uchungechunge lwezinombolo eziphelele nge-interpretation ethile.
Lokhu kuboniswa njenge uint(8)[].
Izibonelo:
Ukubhalwa | C99 stdint.h -Ukulingana |
Incazelo | Isikhala Semibuzo |
---|---|---|---|
uint(16) | uint16_t | Inombolo Engashiwongo, ubude beBiti obungu-16 | 0 - 65.535 |
sint(8) | int8_t | Inombolo Eshiwongo, ubude beBiti obungu-8, I-Two's Complement | -126 - 127 |
uint(24) | uint32_t:24 | Inombolo Engashiwongo, ubude beBiti obungu-24 | 0 - 16.777.216 |
Imigomo ye-Festkomma
Izinombolo ze-Festkomma ziwumkhiqizo wezibalo ezivela kumkhakha we Izinombolo ezihlukanisekayo (Q), okwenza zibe ne komma kanye ne izindawo zokudlula.
Kwizinombolo ze-Festkomma, - ngakho-ke negama - indawo ye-komma ibekwe ngohlobo lwezidataphu.
Lokhu kuholela ekubeni kube khona ibanga lezibalo eliqinile lezibalo zalo hlobo; ngokwezibalo, ibanga lezibalo linqabile.
Ekwenzeni kweqiniso, lohlobo lwezidataphu lusetshenziswa kakhulu ezinkundleni ezingenalo uhlelo lwezokuthuthukiswa lwe-fließkomma olusheshayo, ngoba ukubala izinombolo ze-Festkomma kungase kwenziwe ngama-Integer.
Lolu hlobo lwezidataphu lusetshenziswa, ngokwesibonelo, yizinhlelo zokuphatha idatha, uma izidingo eziqinile kufanele zifezwe.
Cabangela izinhlelo zokugcina imali; izimali eziningi ziqinisa ezindaweni ezi-2 ngemuva kwe-komma.
(Kodwa akukuhle ukuthatha izinombolo ze-Festkomma; kukuhle kakhulu ukugcina ngokuqondile ubuningi obuncane bemali njenge-Integer bese ulethela ezinye izinga lokubukisa)
Ngokufana nezichazamazwi ze-Integer, ngokusebenzisa izinombolo ze-Festkomma, ngicacisa ukuphakama kwesibalo phambi kanye ngemuva kwe-komma:
ufixed(9,7)
ibonisa uhlobo lwezidataphu olungaboni 9 Bit zendawo phambi kwe-komma, kanye no-7 Bit zendawo ngemuva kwe-komma; kulokhu, kumba 16 Bit ububanzi, futhi ingakho ingakwazi ukuhlinzeka ngendawo ye- (0,0) kuya ku- (511,127).
Le ndlela yokuchaza izokhuluma ngempela ema-dezimal, ibeka phansi izinombolo eziyi-28 ezingasebenzi, ngoba kungenzeka ukuthi abantu bazogxila kakhulu kwi- (511,99) emisebenzini.
Esikhundleni sokuchazwa ngokuqondile kwe-Festkomma njengovektha wezikhumbuzo ezi-2 ezihlukile - okwenza kube khona indawo engasetshenziswanga lapho kuguqulwa kube izinombolo ze-dezimal kanye nokudlulisa ngezandla - kungase kuphinde kuboniswe igunya lesikhumbuzo ngemuva kwe-komma njenge isigaba sokuphaka kwazo zonke izixazululo.
Ngesibonelo se-ufixed(9,7)
, lesi sigaba sitholakala ngaphezulu kwesigaba esingu-27 - ibanga lezibalo lithi 0,00 kuya ku-511 + 126⁄127
Ukuze kudluliselwe ku-izibalo ze-dezimal, indawo yokudlula kufanele ihlukaniswe ngo-128.
Nalolu hlobo kulula ukwenza izibalo, ngoba ukudlulisela kuvela ngokuzenzakalelayo, ngakho lolu hlobo lujwayelekile ukuthandwa.
Nokho, lolu hlobo lunephutha lokuthi izindawo zokudlula ezibhalwe kwi-dezimal azikhona ngokuqinisekileyo, indawo eyodwa ye-dezimal ayisabi 0.01
, kodwa 0.007874
, okuzoholela kumaphutha wokuhlela.
Uhlobo lokuchazwa olusetshenziswayo luzobhalwa lapho kusetshenziswa.
Izilinganiso ze-Fließkomma noma ze-Gleitkomma
Amavalue eFließkomma ayizisho eziyinkimbinkimbi kwezibalo, lapho inombolo ephelele enokuhlukaniswa okuqinile iboniswa ngombhalo wezibalo ngendlela yokuthi ingxenye yokuhlukaniswa ibunjwa ngokuhambisa - futhi iphinde ibheke ngqo ku-ukubhalwa kwesayensi.
Indlela evame kakhulu yokwenza lokhu yaziwa nge-IEEE 754 futhi isivunyelwe emhlabeni jikelele kusukela lapho.
Ngesikhathi esifanayo, inani leFließkomma ngokuvamile lenziwe ngezinto ezilandelayo:
Uphawu (0 noma 1 ) |
Exponent | Mantisse |
Ngesikhathi uphawu lungatholakala kalula njengemininingwane ye-binary Yebo/Cha, inombolo yangempela ibunjwa ngalesi silinganiso
Mantisse * 2Exponent
Pho, kukhona nezinye izigaba ezimisiwe ezihlanganisa izimo ezikhethekile zinombolo ezilinganiselwe - okuhlanganisa ±∞
kanye NaN
("inombolo engavumelekile").
Amavalue eFließkomma awusizo ikakhulukazi uma ukunemba kungabalulekile kakhulu, njengoba kulezi zinhlobo zamavalue kuyenzeka kube neziphazamiso zokuphindaphinda futhi ngaleyo ndlela kube nokulahlekelwa ukunemba. Njengoba kuvamile, amavalue eFließkomma asetshenziswa, isibonelo, ekuchazeni kwekoordinati, njengama-vertex vectors kumamodeli e-3D noma ama-Bézier-/Spline-curves ngenxa yezinjongo zokwakhiwa okubonakalayo.
Ezifomathini zedatha, amavalue eFließkomma achazwa njenge-float(Mantisse, Exponent)
.
Uma ifomethi engahambisani ne-IEEE 754 isetshenziswa, lokho kuzokhombisa accordingly.