He aha te mea, he aha te mea? · bei.pm
I roto i tēnei waahanga, he tuhinga e pā ana ki ngā whakaritenga kōnae me te whakahou i te hanga.
I tēnei wā, ko te mea pea:
He maha ngā reo hōtaka kei reira i te ao, ā, he maha ngā tāngata e mōhio ana ki ēnei mea i raro i ngā ingoa rerekē - kāore pea rātou e mōhio ana mō te wātea o ngā mea taketake, nāna i tango i tēnei mai i a rātou.
tl;dr:
Ko taku tuhinga he pūtake ki C99 <stdint.h>
. Mēnā ka taea e koe te whakamahi i tēnei tuhinga, ka pai koe ki taku tuhinga.
Rauemi
Integer he nama katoa, arā, he nama kāore e whai wāhi ana i te pōkai.
I roto i ngā kōnae raraunga, ko ngā Integer e pā ana ki tētahi whānuitanga nama, ā, he whakaritenga, e tautuhia ana. Ka whakaatu au i tēnei i roto i ngā Bit - nā te mea, he mea pā ki te papa te "Byte" me ngā momo e hāngai ana (Word, Qword, ...).
I tua atu, ka rerekē te momo Integer i waenga i te ngā nama taiao (ℕ, arā, kāore he tohu - Unsigned) me te ngā nama katoa (ℤ, arā, he tohu - Signed).
Ka taea te kite i tēnei kōrero i roto i te tohu (u
rānei s
).
Ka taea te whakaatu i ngā tohu e pā ana ki ngā nama katoa hei One's complement rānei hei Two's complement.
I te wā kāore e mea atu ana, ka whakamahia te Two's complement, nāna i te rorohiko hou hei whakaatu e pai ake.
Ka whakaatuhia e au ngā nama kāore he tohu hei uint
i roto i āku tuhinga, me te whakaatu i te tika i roto i ngā Bits.
Ka whakaatuhia e au ngā nama he tohu hei sint
i roto i āku tuhinga, ā, me te whakaatu i te tika i roto i ngā Bits.
Ka waiho au i te whakamahi i te momo raraunga "char" mō ngā tohu, nāna i te mea, ko ngā kōwae tohu he maha ngā uara Integer me te whakamaori motuhake.
Ka whakaatuhia ēnei hei uint(8)[].
Ngā tauira:
Whakaahua | Te whakakapinga C99 stdint.h |
whakamārama | Te wāhi tau |
---|---|---|---|
uint(16) | uint16_t | Whakahaere kore, 16 Bit te roa | 0 - 65.535 |
sint(8) | int8_t | Whakahaere ki te taha, 8 Bit te roa, te rōpū rua | -126 - 127 |
uint(24) | uint32_t:24 | Whakahaere kore, 24 Bit te roa | 0 - 16.777.216 |
Uara Festkomma
Ngā uara whakatau he tau i te rōrahi o ngā Tau Rōnaki (Q), nō reira he komaka me nākoha kei a rātou.
I ngā uara whakatau, kāore e taea te neke i te komaka i runga i te momo raraunga; koia te take i whakaingoatia ai.
Nō reira, he rahi tau pono mō ēnei momo raraunga; i runga i te pāngarau, he mutunga te rōrahi tau.
I te ao tūturu, ka whakamahia tēnei momo raraunga i ngā papa pērā i ngā rorohiko kāore e rahi te tere o te hātewa, nāna i taea te pānui i ngā uara whakatau nā runga i ngā waahanga teitei.
Ka whakamahia hoki tēnei momo raraunga e ngā pūnaha whakahaere pākihi, ina he whakaritenga pūmau e tika ana.
Tērā pea, me whakaaro ki ngā pūnaha e tiakina ana ngā raraunga pūtea; ko te nuinga o ngā moni e rahi ana te 2 ngā wāhi i muri i te komaka.
(Kāore he whakaaro pai ki te tango i ngā uara whakatau mō tēnei; he pai ake te pupuri i te rōrahi moni iti hei tau me te waiho i te toenga ki te whakaatu)
I runga i ngā tau, ka tuku ahau i te whakaritenga o te tau i mua me i muri i te komaka:
ufixed(9,7)
e tohu ana i te momo raraunga, e kore e taka te 9 Bit mō te uara i mua i te komaka, me te 7 Bit mō te uara i muri i te komaka; i runga i te rahi he 16 Bit te whānui, ā, hei tauira, e taea ana te kīanga o ngā tau e rua e kore e whakawhirinaki ki a rātou mai i (0,0) ki (511,127).
Heoi, ko tēnei whakāro ka whakawhiti i ngā tau 28 kāore e whakamahia, nāna i taea pea te rahi ki (511,99) i roto i te ao.
Hei whakawehe i te whakāro māori o te uara whakatau hei vektora e rua ngā tau wehe - e pā ana ki te mea ka waiho he rōrahi kāore e whakamahia i te whakawhiti ki ngā tau rōnaki me te whakawhiti ā-ringa - ka taea hoki te meka i te wāhi nākoha hei tūāhua o ā rātou whakaritenga katoa.
I runga i te tauira o te ufixed(9,7)
, ka puta he tūāhua i runga i te rōrahi o 27 - ka whakawhiti te rōrahi i te 0,00 ki te 511 + 126⁄127
Hei whakawhiti ki te whakaaturanga rōnaki, me te wāhi nākoha ka wehe ki te 128.
Mā tēnei huarahi ka māmā kē te whakahaere i ngā mahi pānui, nāna i taea ai te whakawhiti ki te āhua, ā, ko tēnei huarahi ka whakaritea te nuinga.
Heoi, he pānga tēnei ki te wāhi nākoha i te whakaaturanga rōnaki kāore e pā hei whakaritenga, kāore he wāhi rōnaki e pērā me te 0.01
, engari he 0.007874
, e kawea ana ki ngā hapa teitei.
Ko tēhea tikanga e whakamahia ana, ka tuhinga ki te wāhi e whakamahi ana.
Uara Ngaro, uara Pātea
Ngā uara rārangi he whakatakotoranga pāngarau e kākahu ana i ngā āhuatanga matatini, kāore e taea te whakakotahi i tētahi tau pūmau me te kōwhiringa pūmau, nāna i whakatakoto i te tikanga pāngarau ki te whakaatu i te wāhanga kāwana mā te neke - ā, ki te pātata ki te mahi pūtaiao.
Ko te tikanga e whakamahia nuitia ana hei whakatutuki i tēnei, nāna i painga te IEEE 754, ā, kua whakaaetia e te ao.
I raro i tēnei, ko te uara rārangi he mea nō ngā āhuatanga e whai ake nei:
Te tohu (0 kāore 1 ) |
Te āpitihanga | Te mantissa |
I te wā e taea ana te tohu hei mōhiohio pātea, ka hangaia te tau pono i raro i te whārite
Te mantissa * 2Te āpitihanga
Āpiti atu, he rārangi taurangi e kākahu ana i ngā take motuhake ngā tau rārangi - kei reira ±∞
me NaN
("kāore he tau tika").
He tino whai hua ngā uara rārangi ina kaore e tino hira te tika, i te mea ka pā te hapa ki ngā uara pērā, ā, ka mate te tika. I te nuinga o te wā, ka whakamahia ngā uara rārangi hei whakamārama i ngā kōtuinga, pērā i ngā rārangi vertex i roto i ngā tauira 3D, i ngā kuraka Bézier/spline mō ngā whāinga whakaata.
I roto i ngā whakatakotoranga kōnae, ka whakatakoto ngā uara rārangi hei float(Te mantissa, Te āpitihanga)
.
Mēnā ka whakamahia he whakatakotoranga e rerekē ana i te IEEE 754, ka whai tikanga ki te whakaatu.