[avr-gcc] problem z promocja ...

Witam, unsignet int n; double t_sin; double t_pwm;

n = t_sin/2*t_pwm;

mimo ze t_sin/2*t_pwm wynosi 2880.xxxxx to n zawsze wychodzi mi 0 (zero) ... jak to zrobic aby kod nie byl zbyt nie czytelny???

Reply to
Pawel Kurzawa
Loading thread data ...

Hm, dziwne. Powinno dobrze dzialac. Na pewno jest tak jak piszesz ? Moze arytmetyka "double" nie dziala ? A moze chodzilo o n = t_sin/(2*t_pwm);

mozna jeszcze sprobowac:

n = t_sin*t_pwm/2; n = t_sin*t_pwm/2.0; n = ( (int)(t_sin*t_pwm)) /2;

J.

Reply to
J.F.

az wstyd przyznac ... ale pomoglo :)

Reply to
Pawel Kurzawa

No to jeszcze mozna sprawdzic co z tym kompilator zrobil .. i wstawic

n = ((int)(t_sin/t_pwm)) >> 2;

ewentualnie sprawdzic jak sobie radzi GCC z optymalizacja dzielenia calkowitego przez stala 2.

J.

Reply to
J.F.

chyba: ... >> 1;

Reply to
Andy

radzi sobie doskonale, nawet bez -O.

w.

Reply to
Wojtek Kaniewski

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.