C - zaokrouhlovani

Milan B. milan na bastl.sk
Neděle Únor 20 14:35:42 CET 2011


Ano, je standardizovany:

The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has 
an unsigned type
or if E1 has a signed type and a nonnegative value, the value of the 
result is the integral
part of the quotient of E1 / 2E2. If E1 has a signed type and a negative 
value, the
resulting value is implementation-defined.

Takze ste sa asi trafili do toho "implementation-defined".

-m-

On 20. 2. 2011 14:03, Michal Gregor wrote:
> A jeste jeden dotaz. Priklad, ktery zkousim pouziva posun misto deleni 
> a nasobeni. Jsou tam signed promenne. Ale to by nemelo vadit ne. 
> Bitovy posun pro signed je snad v C taky standartizovany.
>
> static u32 Tlak_Pa;
> s32 X1;
> s32 X2;
> X1 = (X1 * 3038) >> 16; // Toto pocita dobre
> X2 =  (-7357 * (s32)Tlak_Pa) >>16; // Toto pocita spatne
> Musel jsem to upravit na:
> X2 =  (-7357 * (s32)Tlak_Pa) / 65536;
>
> Michal Gregor
>
>
> ----- Original Message ----- From: "Michal Gregor" <a2x1nptda8 na email.cz>
> To: "HW-News" <hw-list na list.hw.cz>
> Sent: Sunday, February 20, 2011 1:43 PM
> Subject: C - zaokrouhlovani
>
>
> Zdravim pocitam v C s celymi cisly. Promenne 32bitu signed.
>
> -17840128 / 7611 = -2343,9926422283536985941400604388
>
> V prikladu z netu jim to vychazi 2344, tedy zaokrouhleno nahoru.
> Ale Hitech C18 zaokrouhluje dolu tedy na 2343.
> Je v norme pro C dano jak se maji cisla zaokrouhlovat v pripade 
> vypoctu pro
> cele cisla?
>
> Michal Gregor
>
>
>
>
>
>
> _______________________________________________
> HW-list mailing list  -  sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list
> _______________________________________________
> HW-list mailing list  -  sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list



Další informace o konferenci Hw-list