HPC.ru lite - Все форумы
Форум: Программирование для КПК
Тема: Ceiling
[Ответить]
Posh [14.01.2005 19:57] Ceiling:
Приветствую!
Вопрос. Что есть такое метод преобразования координат ceiling. Это бухгалтерское округление 0 .5 == 1? Есть ли у кого исходный текст этого преобразования? (ессественно для профилактических целей).
/POSH
KAjFASH [15.01.2005 21:14] :
Может я не до конца понял, но код округления числа типа: 0.3 -> 0 и 0.7 -> 1 будет выгледить так:double val = 0.3; // val -- число которое нужно округлить
int rounded = (int)(val + 0.5);
Posh [16.01.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
ВадимП [16.01.2005 00:52] :
floor() и ceiling() - ни малейшего отношения к тому, что Вы назвали "бухгалтерским округлением" не имеют.
ceiling - это округление до ближайшего целого в бОльшую сторону, а floor, соответственно - в меньшую.
То есть ceiling(7.001) == 8. (точка в данном случае означает конец предложения
)
А floor(9.9999) == 9
[Ответить]