Ceiling

Средства разработки, технические вопросы, отвечает (по мере сил) Отдел Разработок
Закрыто
Posh
Аспирант (2 lvl)
Сообщения: 86
Зарегистрирован: Ср июн 04, 2003 15:03

Ceiling

Сообщение Posh » Пт янв 14, 2005 19:57

Приветствую!

Вопрос. Что есть такое метод преобразования координат ceiling. Это бухгалтерское округление 0 .5 == 1? Есть ли у кого исходный текст этого преобразования? (ессественно для профилактических целей).

/POSH

Аватара пользователя
KAjFASH
Кандидат (3 lvl)
Сообщения: 117
Зарегистрирован: Чт авг 19, 2004 16:40

Сообщение KAjFASH » Сб янв 15, 2005 21:14

Может я не до конца понял, но код округления числа типа: 0.3 -> 0 и 0.7 -> 1 будет выгледить так:

Код: Выделить всё

double val = 0.3; // val -- число которое нужно округлить
int rounded = (int)(val + 0.5);
РегардЗ...
iPAQ, FS LOOX, Versija, Palm, Symbol... SD: 64,128,512
www.salesworks.com.ua

Posh
Аспирант (2 lvl)
Сообщения: 86
Зарегистрирован: Ср июн 04, 2003 15:03

Сообщение Posh » Вс янв 16, 2005 00:36

Вот, что они о себе пишут:

When working with 1.5x displays, how scaling is performed has implications for how you write your applications. The Window Manager uses fixed-point arithmetic to convert standard coordinates to native coordinates. Standard coordinates are scaled using the "ceiling" function, which causes values to be scaled as follows when working with a 1.5x display:


Standard
Native

1 2
2 3
3 5
4 6
5 8
6 9

If an application uses standard coordinates, but also wants a group of lines, pixels, or bitmaps to be evenly spaced, then the coordinates should be separated by an even number of standard pixels. For example, the sequence of standard coordinates separated by 3 pixels {1, 4, 7, 10, ...} is scaled to the uneven sequence {2, 6, 11, 15, ...}, with successive members separated by either 4 or 5 native pixels. In contrast, the sequence of standard coordinates separated by 2 pixels {1, 3, 5, 7, ...} is scaled to the sequence {2, 5, 8, 11, ...}, whose members are consistently separated by 3 native pixels.

Rectangles are scaled using a different algorithm that ensures consistency for both the origin and the extent of each side, so that a rectangle that is scaled and then unscaled is equal to the original rectangle.

When using standard coordinates for frames, the Window Manager uses the "floor" function. This causes values to be scaled as follows when working with a 1.5x display:


Standard
Native

1 1
2 3
3 4
4 6
5 7
6 9


The floor function is also used to scale the frame's width.

/POSH

ВадимП
Нобелевский лауреат (7 lvl)
Сообщения: 6385
Зарегистрирован: Ср июн 04, 2003 15:03

Сообщение ВадимП » Вс янв 16, 2005 00:52

floor() и ceiling() - ни малейшего отношения к тому, что Вы назвали "бухгалтерским округлением" не имеют.
ceiling - это округление до ближайшего целого в бОльшую сторону, а floor, соответственно - в меньшую.
То есть ceiling(7.001) == 8. (точка в данном случае означает конец предложения :))
А floor(9.9999) == 9

Закрыто

Вернуться в «Программирование для КПК»