ottimizzazione floor
Von: ?manu* (paolini@no.math.unifi.spam.it) [Profil]
Datum: 19.05.2008 10:16
Message-ID: <%HaYj.49360$o06.36959@tornado.fastwebnet.it>
Newsgroup: it.comp.lang.c
Datum: 19.05.2008 10:16
Message-ID: <%HaYj.49360$o06.36959@tornado.fastwebnet.it>
Newsgroup: it.comp.lang.c
Dato int x; const SIZE2; vorrei trovare int i; il più grande intero che soddisfa i*SIZE <= x Questa dovrebbe essere una operazione banale per una CPU, ma è lunga da scrivere in C. Qual è il modo più efficiente di farlo? Ad esempio: i = (x>=0) ? x / SIZE : x/SIZE -1 ; è l'operazione corretta. Ma credo che i = (u32)(x + 0x40000000)/SIZE - 0x40000000/SIZE; sia molto più veloce... (si assume che x non sia molto grosso in valore assoluto e che sizeof(int)>2). Che mi dite? E.[ Auf dieses Posting antworten ]
